diff --git a/main.go b/main.go index 4d0b412d02f3ffe4eb36c22116bdd20fdbf892f3..46a170cfabca32b8c84f0df5865efb65cb0679ed 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ package main import ( "fmt" + jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/bindings" "gitlab.com/elixxir/xxdk-wasm/utils" "gitlab.com/elixxir/xxdk-wasm/wasm" @@ -18,6 +19,15 @@ import ( "syscall/js" ) +func init() { + // Overwrites setting the log level to INFO done in bindings so that the + // Javascript console can be used + ll := &wasm.LogListener{ + Threshold: jww.LevelInfo, Value: js.Global().Get("console")} + jww.SetLogListeners(ll.Listen) + jww.SetStdoutThreshold(jww.LevelFatal + 1) +} + func main() { fmt.Println("Starting xxDK WebAssembly bindings.") fmt.Printf("Client version %s\n", bindings.GetVersion()) diff --git a/wasm/logging.go b/wasm/logging.go index 177a57e3fcacc7cfe9b437f911ff08894b500009..a39cf7facb418f3f516c6511e258fb7132f69709 100644 --- a/wasm/logging.go +++ b/wasm/logging.go @@ -46,14 +46,13 @@ var logListeners []jww.LogListener // Returns: // - Throws TypeError if the log level is invalid. func LogLevel(_ js.Value, args []js.Value) interface{} { - level := args[0].Int() - if level < 0 || level > 6 { - err := errors.Errorf("log level is not valid: log level: %d", level) + threshold := jww.Threshold(args[0].Int()) + if threshold < jww.LevelTrace || threshold > jww.LevelFatal { + err := errors.Errorf("log level is not valid: log level: %d", threshold) utils.Throw(utils.TypeError, err) return nil } - threshold := jww.Threshold(level) jww.SetLogThreshold(threshold) jww.SetFlags(log.LstdFlags | log.Lmicroseconds) @@ -94,13 +93,12 @@ func LogLevel(_ js.Value, args []js.Value) interface{} { // - A Javascript representation of the LogFile object, which allows accessing // the contents of the log file and other metadata. func LogToFile(_ js.Value, args []js.Value) interface{} { - level := args[0].Int() - if level < 0 || level > 6 { - err := errors.Errorf("log level is not valid: log level: %d", level) + threshold := jww.Threshold(args[0].Int()) + if threshold < jww.LevelTrace || threshold > jww.LevelFatal { + err := errors.Errorf("log level is not valid: log level: %d", threshold) utils.Throw(utils.TypeError, err) return nil } - threshold := jww.Threshold(level) // Create new buffer of the specified size b, err := circbuf.NewBuffer(int64(args[2].Int()))