mirror of
https://github.com/denoland/deno.git
synced 2025-08-30 23:38:03 +00:00
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.
This commit is contained in:
parent
acc6cdc0b1
commit
3b69d238cd
7 changed files with 60 additions and 23 deletions
|
@ -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,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue