From 3bbf075f92c2a0a0abb7137af4327d9059dbcb4a Mon Sep 17 00:00:00 2001 From: Sergey Stepanov Date: Mon, 11 Apr 2022 09:16:08 +0300 Subject: [PATCH] Log lines in the browser console --- go.mod | 2 +- web/js/log.js | 29 +++++++++++++---------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/go.mod b/go.mod index 59863ede..ad5b377f 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/web/js/log.js b/web/js/log.js index d3b73fbd..3b80a48c 100644 --- a/web/js/log.js +++ b/web/js/log.js @@ -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);