diff --git a/Cargo.lock b/Cargo.lock index 1a57bf3a0..2ae1becd1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1371,6 +1371,7 @@ dependencies = [ "graph", "log", "once_cell", + "sb_event_worker", "tokio", "tracing-subscriber", ] diff --git a/cli/Cargo.toml b/cli/Cargo.toml index ff1693ba5..a0dca805b 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -15,6 +15,8 @@ base.workspace = true deno_manifest.workspace = true graph.workspace = true +sb_event_worker = { workspace = true, optional = true, features = ["tracing"] } + anyhow.workspace = true log.workspace = true tokio.workspace = true @@ -26,4 +28,4 @@ tracing-subscriber = { workspace = true, optional = true } env_logger = "0.10.0" [features] -tracing = ["dep:tracing-subscriber"] \ No newline at end of file +tracing = ["dep:tracing-subscriber", "dep:sb_event_worker"] \ No newline at end of file diff --git a/ext/event_worker/Cargo.toml b/ext/event_worker/Cargo.toml index 5db092a29..f78a6c139 100644 --- a/ext/event_worker/Cargo.toml +++ b/ext/event_worker/Cargo.toml @@ -19,4 +19,7 @@ anyhow.workspace = true tokio.workspace = true log.workspace = true tracing.workspace = true -enum-as-inner.workspace = true \ No newline at end of file +enum-as-inner.workspace = true + +[features] +tracing = [] \ No newline at end of file diff --git a/ext/event_worker/js_interceptors.rs b/ext/event_worker/js_interceptors.rs index 18e4543e1..4e77a967f 100644 --- a/ext/event_worker/js_interceptors.rs +++ b/ext/event_worker/js_interceptors.rs @@ -4,7 +4,7 @@ use deno_core::error::AnyError; use deno_core::op2; use deno_core::OpState; use tokio::sync::mpsc; -use tracing::{event, trace}; +use tracing::trace; #[op2(fast)] fn op_user_worker_log( @@ -35,11 +35,19 @@ fn op_user_worker_log( trace!(?metadata); tx.send(metadata)?; } else { - match level { - LogLevel::Debug => event!(tracing::Level::DEBUG, "{msg}"), - LogLevel::Info => event!(tracing::Level::INFO, "{msg}"), - LogLevel::Warning => event!(tracing::Level::WARN, "{msg}"), - LogLevel::Error => event!(tracing::Level::ERROR, "{msg}"), + #[cfg(feature = "tracing")] + { + match level { + LogLevel::Debug => tracing::event!(tracing::Level::DEBUG, "{msg}"), + LogLevel::Info => tracing::event!(tracing::Level::INFO, "{msg}"), + LogLevel::Warning => tracing::event!(tracing::Level::WARN, "{msg}"), + LogLevel::Error => tracing::event!(tracing::Level::ERROR, "{msg}"), + } + } + + #[cfg(not(feature = "tracing"))] + { + log::error!("[{:?}] {}", level, msg.to_string()); } }