forked from mbk-lab/rui_orig
2
0
Fork 0

Updated log functions

This commit is contained in:
anoshenko 2022-11-09 13:40:08 +03:00
parent ecbcda7a53
commit ff5c73b7c3
4 changed files with 15 additions and 17 deletions

View File

@ -2,7 +2,6 @@ package rui
import ( import (
"fmt" "fmt"
"log"
"runtime" "runtime"
) )
@ -10,14 +9,8 @@ import (
// clients and the server is displayed in the debug log // clients and the server is displayed in the debug log
var ProtocolInDebugLog = false var ProtocolInDebugLog = false
var debugLogFunc func(string) = func(text string) { var debugLogFunc func(string) = debugLog
log.Println("\033[34m" + text) var errorLogFunc func(string) = errorLog
}
var errorLogFunc = func(text string) {
log.Println("\033[31m" + text)
//println(text)
}
// SetDebugLog sets a function for outputting debug info. // SetDebugLog sets a function for outputting debug info.
// The default value is nil (debug info is ignored) // The default value is nil (debug info is ignored)

View File

@ -20,6 +20,14 @@ import (
//go:embed app_socket.js //go:embed app_socket.js
var socketScripts string var socketScripts string
func debugLog(text string) {
log.Println("\033[34m" + text)
}
func errorLog(text string) {
log.Println("\033[31m" + text)
}
type application struct { type application struct {
server *http.Server server *http.Server
params AppParams params AppParams

View File

@ -25,10 +25,14 @@ func (app *wasmApp) Finish() {
app.session.close() app.session.close()
} }
func wasmLog(text string) { func debugLog(text string) {
js.Global().Get("console").Call("log", text) 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 { func (app *wasmApp) handleMessage(this js.Value, args []js.Value) any {
if len(args) > 0 { if len(args) > 0 {
text := args[0].String() text := args[0].String()
@ -160,9 +164,6 @@ func (app *wasmApp) init(params AppParams) {
// StartApp - create the new wasmApp and start it // StartApp - create the new wasmApp and start it
func StartApp(addr string, createContentFunc func(Session) SessionContent, params AppParams) { func StartApp(addr string, createContentFunc func(Session) SessionContent, params AppParams) {
SetDebugLog(wasmLog)
SetErrorLog(wasmLog)
if createContentFunc == nil { if createContentFunc == nil {
return return
} }

View File

@ -1,8 +1,4 @@
function log(s) {
console.log(s);
}
window.onfocus = function(event) { window.onfocus = function(event) {
windowFocus = true windowFocus = true
sendMessage( "session-resume{session=" + sessionID +"}" ); sendMessage( "session-resume{session=" + sessionID +"}" );