Log lines in the browser console

This commit is contained in:
Sergey Stepanov 2022-04-11 09:16:08 +03:00
parent 63d8a0354c
commit 3bbf075f92
No known key found for this signature in database
GPG key ID: A56B4929BAA8556B
2 changed files with 14 additions and 17 deletions

2
go.mod
View file

@ -28,7 +28,7 @@ require (
github.com/prometheus/client_golang v1.11.0
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/rs/xid v1.4.0 // indirect
github.com/rs/xid v1.4.0
github.com/spf13/pflag v1.0.5
github.com/veandco/go-sdl2 v0.4.10
golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871

View file

@ -3,24 +3,21 @@ const log = (() => {
let level = -1;
const atLeast = lv => (lv || -1) >= level;
const noop = () => ({});
const
info = atLeast(levels.info) ? console.info.bind(window.console) : noop,
debug = atLeast(levels.debug) ? console.debug.bind(window.console) : noop,
error = atLeast(levels.error) ? console.error.bind(window.console) : noop,
warning = atLeast(levels.warning) ? console.warn.bind(window.console) : noop;
return {
level: levels,
info: function () {
atLeast(levels.info) && console.info.apply(null, arguments)
},
debug: function () {
atLeast(levels.debug) && console.debug.apply(null, arguments)
},
error: function () {
console.error.apply(null, arguments)
},
warning: function () {
atLeast(levels.warning) && console.warn.apply(null, arguments)
},
setLevel: (level_) => {
level = levels[level_] || -1;
},
info,
debug,
error,
warning,
setLevel: (level_) => level = levels[level_] || -1,
is: (level_) => level === level_
}
})(console);
})(console, window);