From ff5c73b7c3046a0bdafc317c94416151ac667745 Mon Sep 17 00:00:00 2001 From: anoshenko Date: Wed, 9 Nov 2022 13:40:08 +0300 Subject: [PATCH] Updated log functions --- appLog.go | 11 ++--------- appServer.go | 8 ++++++++ appWasm.go | 9 +++++---- app_wasm.js | 4 ---- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/appLog.go b/appLog.go index 3d23c27..cbb9e65 100644 --- a/appLog.go +++ b/appLog.go @@ -2,7 +2,6 @@ package rui import ( "fmt" - "log" "runtime" ) @@ -10,14 +9,8 @@ import ( // clients and the server is displayed in the debug log var ProtocolInDebugLog = false -var debugLogFunc func(string) = func(text string) { - log.Println("\033[34m" + text) -} - -var errorLogFunc = func(text string) { - log.Println("\033[31m" + text) - //println(text) -} +var debugLogFunc func(string) = debugLog +var errorLogFunc func(string) = errorLog // SetDebugLog sets a function for outputting debug info. // The default value is nil (debug info is ignored) diff --git a/appServer.go b/appServer.go index afd4452..275567a 100644 --- a/appServer.go +++ b/appServer.go @@ -20,6 +20,14 @@ import ( //go:embed app_socket.js var socketScripts string +func debugLog(text string) { + log.Println("\033[34m" + text) +} + +func errorLog(text string) { + log.Println("\033[31m" + text) +} + type application struct { server *http.Server params AppParams diff --git a/appWasm.go b/appWasm.go index 36e1adc..b52fa3f 100644 --- a/appWasm.go +++ b/appWasm.go @@ -25,10 +25,14 @@ func (app *wasmApp) Finish() { app.session.close() } -func wasmLog(text string) { +func debugLog(text string) { js.Global().Get("console").Call("log", text) } +func errorLog(text string) { + js.Global().Get("console").Call("log", "%c"+text, "color: #F00;") +} + func (app *wasmApp) handleMessage(this js.Value, args []js.Value) any { if len(args) > 0 { text := args[0].String() @@ -160,9 +164,6 @@ func (app *wasmApp) init(params AppParams) { // StartApp - create the new wasmApp and start it func StartApp(addr string, createContentFunc func(Session) SessionContent, params AppParams) { - SetDebugLog(wasmLog) - SetErrorLog(wasmLog) - if createContentFunc == nil { return } diff --git a/app_wasm.js b/app_wasm.js index a33e94f..d4d2010 100644 --- a/app_wasm.js +++ b/app_wasm.js @@ -1,8 +1,4 @@ -function log(s) { - console.log(s); -} - window.onfocus = function(event) { windowFocus = true sendMessage( "session-resume{session=" + sessionID +"}" );