Skip to content

Commit 442a810

Browse files
suofacebook-github-bot
authored andcommitted
cut log spam (#524)
Summary: Pull Request resolved: #524 The amount of spew when just trying to use monarch as a user was crazy lol. Should fix #411. This creates two layers: - A file log layer - A stderr log layer They are configured separately depending on environment. The file one is controlled by RUST_LOG, and the stderr one is controlled by MONARCH_LOG. For now, both are always used, even if redundant. You can look at the proposed defaults on an environment basis, but for local/mast we have the same config: errors to stderr, info+ to file. ghstack-source-id: 295862670 exported-using-ghexport Reviewed By: dcci Differential Revision: D78220912 fbshipit-source-id: 2077360f6408fea5413393d895745e1ce90ee218
1 parent 3eec37f commit 442a810

File tree

1 file changed

+41
-36
lines changed
  • hyperactor_telemetry/src

1 file changed

+41
-36
lines changed

hyperactor_telemetry/src/lib.rs

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
#![feature(formatting_options)]
1515

1616
// TODO:ehedeman Remove or replace with better config once telemetry perf issues are solved
17-
/// Environment variable to disable the glog logging layer.
18-
/// Set to "1" to disable glog logging output.
19-
pub const DISABLE_GLOG_TRACING: &str = "DISABLE_GLOG_TRACING";
20-
2117
/// Environment variable to disable the OpenTelemetry logging layer.
2218
/// Set to "1" to disable OpenTelemetry tracing.
2319
pub const DISABLE_OTEL_TRACING: &str = "DISABLE_OTEL_TRACING";
@@ -83,23 +79,18 @@ impl TelemetryClock for DefaultTelemetryClock {
8379

8480
// Need to keep this around so that the tracing subscriber doesn't drop the writer.
8581
lazy_static! {
86-
static ref WRITER_GUARD: Arc<(NonBlocking, WorkerGuard)> = {
87-
let writer: Box<dyn Write + Send> = match env::Env::current() {
88-
env::Env::Local | env::Env::Test | env::Env::MastEmulator => {
82+
static ref FILE_WRITER_GUARD: Arc<(NonBlocking, WorkerGuard)> = {
83+
let writer: Box<dyn Write + Send> = match RollingFileAppender::builder()
84+
.rotation(Rotation::DAILY)
85+
.filename_prefix("dedicated_log_monarch")
86+
.filename_suffix("log")
87+
.build("/logs/")
88+
{
89+
Ok(file) => Box::new(file),
90+
Err(e) => {
91+
tracing::warn!("unable to create custom log file: {}", e);
8992
Box::new(std::io::stderr())
9093
}
91-
env::Env::Mast => match RollingFileAppender::builder()
92-
.rotation(Rotation::DAILY)
93-
.filename_prefix("dedicated_log_monarch")
94-
.filename_suffix("log")
95-
.build("/logs/")
96-
{
97-
Ok(file) => Box::new(file),
98-
Err(e) => {
99-
tracing::warn!("unable to create custom log file: {}", e);
100-
Box::new(std::io::stderr())
101-
}
102-
},
10394
};
10495
return Arc::new(
10596
tracing_appender::non_blocking::NonBlockingBuilder::default()
@@ -425,24 +416,46 @@ macro_rules! declare_static_histogram {
425416
/// to get this behavior.
426417
pub fn initialize_logging(clock: impl TelemetryClock + Send + 'static) {
427418
swap_telemetry_clock(clock);
428-
let glog_level = match env::Env::current() {
419+
let file_log_level = match env::Env::current() {
429420
env::Env::Local => "info",
430421
env::Env::MastEmulator => "info",
431422
env::Env::Mast => "info",
432423
env::Env::Test => "debug",
433424
};
425+
let file_writer: &NonBlocking = &FILE_WRITER_GUARD.0;
426+
let file_layer = fmt::Layer::default()
427+
.with_writer(file_writer.clone())
428+
.event_format(Glog::default().with_timer(LocalTime::default()))
429+
.fmt_fields(GlogFields::default().compact())
430+
.with_ansi(false)
431+
.with_filter(
432+
Targets::new()
433+
.with_default(LevelFilter::from_level(
434+
tracing::Level::from_str(
435+
&std::env::var("MONARCH_FILE_LOG").unwrap_or(file_log_level.to_string()),
436+
)
437+
.expect("Invalid log level"),
438+
))
439+
.with_target("opentelemetry", LevelFilter::OFF), // otel has some log span under debug that we don't care about
440+
);
434441

435-
let writer: &NonBlocking = &WRITER_GUARD.0;
436-
let glog = fmt::Layer::default()
437-
.with_writer(writer.clone())
442+
let stderr_log_level = match env::Env::current() {
443+
env::Env::Local => "error",
444+
env::Env::MastEmulator => "info",
445+
env::Env::Mast => "error",
446+
env::Env::Test => "debug",
447+
};
448+
let stderr_layer = fmt::Layer::default()
449+
.with_writer(std::io::stderr)
438450
.event_format(Glog::default().with_timer(LocalTime::default()))
439451
.fmt_fields(GlogFields::default().compact())
440452
.with_ansi(std::io::stderr().is_terminal())
441453
.with_filter(
442454
Targets::new()
443455
.with_default(LevelFilter::from_level(
444456
tracing::Level::from_str(
445-
&std::env::var("RUST_LOG").unwrap_or(glog_level.to_string()),
457+
&std::env::var("MONARCH_STDERR_LOG")
458+
.unwrap_or(stderr_log_level.to_string()),
446459
)
447460
.expect("Invalid log level"),
448461
))
@@ -465,16 +478,13 @@ pub fn initialize_logging(clock: impl TelemetryClock + Send + 'static) {
465478
} else {
466479
None
467480
})
468-
.with(if is_layer_enabled(DISABLE_GLOG_TRACING) {
469-
Some(glog)
470-
} else {
471-
None
472-
})
473481
.with(if is_layer_enabled(DISABLE_RECORDER_TRACING) {
474482
Some(recorder().layer())
475483
} else {
476484
None
477485
})
486+
.with(file_layer)
487+
.with(stderr_layer)
478488
.try_init()
479489
{
480490
tracing::debug!("logging already initialized for this process: {}", err);
@@ -502,13 +512,8 @@ pub fn initialize_logging(clock: impl TelemetryClock + Send + 'static) {
502512
#[cfg(not(fbcode_build))]
503513
{
504514
if let Err(err) = Registry::default()
505-
.with(
506-
if std::env::var(DISABLE_GLOG_TRACING).unwrap_or_default() != "1" {
507-
Some(glog)
508-
} else {
509-
None
510-
},
511-
)
515+
.with(file_layer)
516+
.with(stderr_layer)
512517
.with(
513518
if std::env::var(DISABLE_RECORDER_TRACING).unwrap_or_default() != "1" {
514519
Some(recorder().layer())

0 commit comments

Comments
 (0)