2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2024-01-26 17:46:46 -05:00
|
|
|
import { primordials } from "ext:core/mod.js";
|
|
|
|
import { op_bootstrap_log_level } from "ext:core/ops";
|
2024-02-06 16:28:32 -05:00
|
|
|
const { SafeArrayIterator } = primordials;
|
2023-05-30 11:34:50 -04:00
|
|
|
|
|
|
|
// WARNING: Keep this in sync with Rust (search for LogLevel)
|
|
|
|
const LogLevel = {
|
|
|
|
Error: 1,
|
|
|
|
Warn: 2,
|
|
|
|
Info: 3,
|
|
|
|
Debug: 4,
|
|
|
|
};
|
|
|
|
|
2023-11-12 23:52:59 -05:00
|
|
|
const logSource = "JS";
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-11-12 23:52:59 -05:00
|
|
|
let logLevel_ = null;
|
|
|
|
function logLevel() {
|
|
|
|
if (logLevel_ === null) {
|
2024-01-10 17:37:25 -05:00
|
|
|
logLevel_ = op_bootstrap_log_level() || 3;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
2023-11-12 23:52:59 -05:00
|
|
|
return logLevel_;
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
function log(...args) {
|
2023-11-12 23:52:59 -05:00
|
|
|
if (logLevel() >= LogLevel.Debug) {
|
2023-02-07 14:22:46 -05:00
|
|
|
// if we destructure `console` off `globalThis` too early, we don't bind to
|
|
|
|
// the right console, therefore we don't log anything out.
|
2023-05-22 14:17:31 -04:00
|
|
|
globalThis.console.error(
|
2023-02-07 14:22:46 -05:00
|
|
|
`DEBUG ${logSource} -`,
|
|
|
|
...new SafeArrayIterator(args),
|
|
|
|
);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2024-02-06 16:28:32 -05:00
|
|
|
export { log };
|