diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/js/06_util.js | 19 | ||||
-rw-r--r-- | runtime/js/99_main.js | 12 | ||||
-rw-r--r-- | runtime/lib.rs | 1 | ||||
-rw-r--r-- | runtime/worker_bootstrap.rs | 35 |
4 files changed, 53 insertions, 14 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, }; diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 91d34272f..8fd9a6bd9 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -299,7 +299,7 @@ function runtimeStart( v8Version, tsVersion, target, - debugFlag, + logLevel, noColor, isTty, source, @@ -315,7 +315,7 @@ function runtimeStart( tsVersion, ); core.setBuildInfo(target); - util.setLogDebug(debugFlag, source); + util.setLogLevel(logLevel, source); setNoColor(noColor || !isTty); // deno-lint-ignore prefer-primordials Error.prepareStackTrace = core.prepareStackTrace; @@ -428,7 +428,7 @@ function bootstrapMainRuntime(runtimeOptions) { const { 0: args, 1: cpuCount, - 2: debugFlag, + 2: logLevel, 3: denoVersion, 4: locale, 5: location_, @@ -495,7 +495,7 @@ function bootstrapMainRuntime(runtimeOptions) { v8Version, tsVersion, target, - debugFlag, + logLevel, noColor, isTty, ); @@ -542,7 +542,7 @@ function bootstrapWorkerRuntime( const { 0: args, 1: cpuCount, - 2: debugFlag, + 2: logLevel, 3: denoVersion, 4: locale, 5: location_, @@ -610,7 +610,7 @@ function bootstrapWorkerRuntime( v8Version, tsVersion, target, - debugFlag, + logLevel, noColor, isTty, internalName ?? name, diff --git a/runtime/lib.rs b/runtime/lib.rs index 50822d373..1e307f492 100644 --- a/runtime/lib.rs +++ b/runtime/lib.rs @@ -35,3 +35,4 @@ pub mod worker; mod worker_bootstrap; pub use worker_bootstrap::BootstrapOptions; +pub use worker_bootstrap::WorkerLogLevel; diff --git a/runtime/worker_bootstrap.rs b/runtime/worker_bootstrap.rs index ba894f52b..9627281a6 100644 --- a/runtime/worker_bootstrap.rs +++ b/runtime/worker_bootstrap.rs @@ -6,13 +6,42 @@ use std::thread; use crate::colors; +/// The log level to use when printing diagnostic log messages, warnings, +/// or errors in the worker. +/// +/// Note: This is disconnected with the log crate's log level and the Rust code +/// in this crate will respect that value instead. To specify that, use +/// `log::set_max_level`. +#[derive(Debug, Default, Clone, Copy)] +pub enum WorkerLogLevel { + // WARNING: Ensure this is kept in sync with + // the JS values (search for LogLevel). + Error = 1, + Warn = 2, + #[default] + Info = 3, + Debug = 4, +} + +impl From<log::Level> for WorkerLogLevel { + fn from(value: log::Level) -> Self { + match value { + log::Level::Error => WorkerLogLevel::Error, + log::Level::Warn => WorkerLogLevel::Warn, + log::Level::Info => WorkerLogLevel::Info, + log::Level::Debug => WorkerLogLevel::Debug, + log::Level::Trace => WorkerLogLevel::Debug, + } + } +} + /// Common bootstrap options for MainWorker & WebWorker #[derive(Clone)] pub struct BootstrapOptions { /// Sets `Deno.args` in JS runtime. pub args: Vec<String>, pub cpu_count: usize, - pub debug_flag: bool, + pub log_level: WorkerLogLevel, pub enable_testing_features: bool, pub locale: String, pub location: Option<ModuleSpecifier>, @@ -44,7 +73,7 @@ impl Default for BootstrapOptions { no_color: !colors::use_color(), is_tty: colors::is_tty(), enable_testing_features: Default::default(), - debug_flag: Default::default(), + log_level: Default::default(), ts_version: Default::default(), locale: "en".to_string(), location: Default::default(), @@ -77,7 +106,7 @@ impl BootstrapOptions { } { - let val = v8::Boolean::new(scope, self.debug_flag); + let val = v8::Integer::new(scope, self.log_level as i32); array.set_index(scope, 2, val.into()); } |