mirror of
https://github.com/denoland/deno.git
synced 2024-11-28 16:20:57 -05:00
36 lines
857 B
JavaScript
36 lines
857 B
JavaScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
|
|
import { primordials } from "ext:core/mod.js";
|
|
import { op_bootstrap_log_level } from "ext:core/ops";
|
|
const { SafeArrayIterator } = primordials;
|
|
|
|
// WARNING: Keep this in sync with Rust (search for LogLevel)
|
|
const LogLevel = {
|
|
Error: 1,
|
|
Warn: 2,
|
|
Info: 3,
|
|
Debug: 4,
|
|
};
|
|
|
|
const logSource = "JS";
|
|
|
|
let logLevel_ = null;
|
|
function logLevel() {
|
|
if (logLevel_ === null) {
|
|
logLevel_ = op_bootstrap_log_level() || 3;
|
|
}
|
|
return logLevel_;
|
|
}
|
|
|
|
function log(...args) {
|
|
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(
|
|
`DEBUG ${logSource} -`,
|
|
...new SafeArrayIterator(args),
|
|
);
|
|
}
|
|
}
|
|
|
|
export { log };
|