Skip to content

Commit

Permalink
fix(ext/event_worker): don't use tracing as the log backend if `cli…
Browse files Browse the repository at this point in the history
…/tracing` feature flag is not enabled (#469)

* fix(ext/event_worker): add a feature flag

* chore(cli): update `Cargo.toml`

* chore: update `Cargo.lock`
  • Loading branch information
nyannyacha authored Jan 3, 2025
1 parent 5558d8e commit 6246a6f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,4 +28,4 @@ tracing-subscriber = { workspace = true, optional = true }
env_logger = "0.10.0"

[features]
tracing = ["dep:tracing-subscriber"]
tracing = ["dep:tracing-subscriber", "dep:sb_event_worker"]
5 changes: 4 additions & 1 deletion ext/event_worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ anyhow.workspace = true
tokio.workspace = true
log.workspace = true
tracing.workspace = true
enum-as-inner.workspace = true
enum-as-inner.workspace = true

[features]
tracing = []
20 changes: 14 additions & 6 deletions ext/event_worker/js_interceptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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());
}
}

Expand Down

0 comments on commit 6246a6f

Please sign in to comment.