Skip to content

Commit

Permalink
feat: support enabling pretty log via env var
Browse files Browse the repository at this point in the history
  • Loading branch information
xxchan committed May 31, 2024
1 parent c560d2d commit 8d59940
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/utils/runtime/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::path::PathBuf;
use either::Either;
use risingwave_common::metrics::MetricsLayer;
use risingwave_common::util::deployment::Deployment;
use risingwave_common::util::env_var::env_var_is_true;
use risingwave_common::util::query_log::*;
use risingwave_common::util::tracing::layer::set_toggle_otel_layer_fn;
use thiserror_ext::AsReport;
Expand Down Expand Up @@ -170,6 +171,17 @@ fn disabled_filter() -> filter::Targets {
///
/// `RW_QUERY_LOG_TRUNCATE_LEN` configures the max length of the SQLs logged in the query log,
/// to avoid the log file growing too large. The default value is 1024 in production.
///
/// ### `RW_ENABLE_PRETTY_LOG`
///
/// If it is set to `true`, enable pretty log output, which contains line numbers and prints spans in multiple lines.
/// This can be helpful for development and debugging.
///
/// Hint: Also turn off other uninteresting logs to make the most of the pretty log.
/// e.g.,
/// ```bash
/// RUST_LOG="risingwave_storage::hummock::event_handler=off,batch_execute=off,risingwave_batch::task=off" RW_ENABLE_PRETTY_LOG=true risedev d
/// ```
pub fn init_risingwave_logger(settings: LoggerSettings) {
let deployment = Deployment::current();

Expand Down Expand Up @@ -276,7 +288,13 @@ pub fn init_risingwave_logger(settings: LoggerSettings) {
.json()
.map_event_format(|e| e.with_current_span(false)) // avoid duplication as there's a span list field
.boxed(),
Deployment::Other => fmt_layer.boxed(),
Deployment::Other => {
if env_var_is_true("RW_ENABLE_PRETTY_LOG") {
fmt_layer.pretty().boxed()
} else {
fmt_layer.boxed()
}
}
};

layers.push(
Expand Down

0 comments on commit 8d59940

Please sign in to comment.