summaryrefslogtreecommitdiff
path: root/runtime/js/06_util.js
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-05-30 11:34:50 -0400
committerGitHub <noreply@github.com>2023-05-30 15:34:50 +0000
commit3b69d238cdedc7f47515ba74f2366724679c5c7d (patch)
tree016643f2551b53270f7af35a69e457ba74f91173 /runtime/js/06_util.js
parentacc6cdc0b1c0fae5e0fba3b0110f96119c2139f7 (diff)
feat(runtime): add `WorkerLogLevel` (#19316)
This is not really used yet, but provides some infrastructure for doing more fine grained logging in JS. I will add warn messages in a future PR.
Diffstat (limited to 'runtime/js/06_util.js')
-rw-r--r--runtime/js/06_util.js19
1 files changed, 14 insertions, 5 deletions
diff --git a/runtime/js/06_util.js b/runtime/js/06_util.js
index e04ae7bd7..971957b7e 100644
--- a/runtime/js/06_util.js
+++ b/runtime/js/06_util.js
@@ -5,18 +5,27 @@ const {
Promise,
SafeArrayIterator,
} = primordials;
-let logDebug = false;
+
+// WARNING: Keep this in sync with Rust (search for LogLevel)
+const LogLevel = {
+ Error: 1,
+ Warn: 2,
+ Info: 3,
+ Debug: 4,
+};
+
+let logLevel = 3;
let logSource = "JS";
-function setLogDebug(debug, source) {
- logDebug = debug;
+function setLogLevel(level, source) {
+ logLevel = level;
if (source) {
logSource = source;
}
}
function log(...args) {
- if (logDebug) {
+ if (logLevel >= LogLevel.Debug) {
// if we destructure `console` off `globalThis` too early, we don't bind to
// the right console, therefore we don't log anything out.
globalThis.console.error(
@@ -80,6 +89,6 @@ export {
log,
nonEnumerable,
readOnly,
- setLogDebug,
+ setLogLevel,
writable,
};