Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support enabling pretty log via env var #17041

Merged
merged 1 commit into from
May 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading