diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-05-30 11:34:50 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-30 15:34:50 +0000 |
commit | 3b69d238cdedc7f47515ba74f2366724679c5c7d (patch) | |
tree | 016643f2551b53270f7af35a69e457ba74f91173 /runtime/worker_bootstrap.rs | |
parent | acc6cdc0b1c0fae5e0fba3b0110f96119c2139f7 (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/worker_bootstrap.rs')
-rw-r--r-- | runtime/worker_bootstrap.rs | 35 |
1 files changed, 32 insertions, 3 deletions
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()); } |