From e996c661f0534f68832a39363fed4dc7627f1af6 Mon Sep 17 00:00:00 2001 From: zdevito Date: Thu, 6 Nov 2025 13:55:07 -0800 Subject: [PATCH] [logging] monarch logs do not go to stderr Updating our logging behavior to reflect our 'logging axioms'. This removes the forwarding of monarch logs to stderr. "Monarch Logs" are logs lines which relate to the internal operation of monarch and are used for debugging bugs in the monarch system. "User logs" are the logs and any output to stderr/out that actors running within monarch make. Monarch itself should never produce "User logs" except in the following limited circumstances: * warning about deprecated APIs and other functionality limitations the output of the default 'unhandled_fault_hook' reporting the serialization of an ActorFailure message. * a single log line on startup of the client or a host worker (but not a proc!) that describes where the "monarch logs" are being written. Differential Revision: [D86456839](https://our.internmc.facebook.com/intern/diff/D86456839/) **NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D86456839/)! [ghstack-poisoned] --- .../src/v1/host_mesh/mesh_agent.rs | 11 ++++++++ hyperactor_telemetry/src/lib.rs | 27 ------------------- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/hyperactor_mesh/src/v1/host_mesh/mesh_agent.rs b/hyperactor_mesh/src/v1/host_mesh/mesh_agent.rs index 95371f533..0d370ec22 100644 --- a/hyperactor_mesh/src/v1/host_mesh/mesh_agent.rs +++ b/hyperactor_mesh/src/v1/host_mesh/mesh_agent.rs @@ -125,6 +125,17 @@ impl Actor for HostMeshAgent { type Params = HostAgentMode; async fn new(host: HostAgentMode) -> anyhow::Result { + if let HostAgentMode::Process(_) = host { + let (directory, file) = hyperactor_telemetry::log_file_path( + hyperactor_telemetry::env::Env::current(), + None, + ) + .unwrap(); + eprintln!( + "Monarch internal logs are being written to {}/{}.log", + directory, file + ); + } Ok(Self { host: Some(host), created: HashMap::new(), diff --git a/hyperactor_telemetry/src/lib.rs b/hyperactor_telemetry/src/lib.rs index 3cb4f9bbf..077fcae64 100644 --- a/hyperactor_telemetry/src/lib.rs +++ b/hyperactor_telemetry/src/lib.rs @@ -33,8 +33,6 @@ pub const DISABLE_SQLITE_TRACING: &str = "DISABLE_SQLITE_TRACING"; /// Environment variable constants // Log level (debug, info, warn, error, critical) to capture for Monarch traces on dedicated log file (changes based on environment, see `log_file_path`). const MONARCH_FILE_LOG_ENV: &str = "MONARCH_FILE_LOG"; -// Log level (debug, info, warn, error, critical) to capture for Monarch traces on stderr. -const MONARCH_STDERR_LOG_ENV: &str = "MONARCH_STDERR_LOG"; pub const MAST_HPC_JOB_NAME_ENV: &str = "MAST_HPC_JOB_NAME"; @@ -600,29 +598,6 @@ pub fn initialize_logging_with_log_prefix( .with_target("opentelemetry", LevelFilter::OFF), // otel has some log span under debug that we don't care about ); - let stderr_log_level = match env::Env::current() { - env::Env::Local => LOG_LEVEL_ERROR, - env::Env::MastEmulator => LOG_LEVEL_INFO, - env::Env::Mast => LOG_LEVEL_ERROR, - env::Env::Test => LOG_LEVEL_DEBUG, - }; - let stderr_layer = fmt::Layer::default() - .with_writer(std::io::stderr) - .event_format(PrefixedFormatter::new(prefix_env_var)) - .fmt_fields(GlogFields::default().compact()) - .with_ansi(std::io::stderr().is_terminal()) - .with_filter( - Targets::new() - .with_default(LevelFilter::from_level( - tracing::Level::from_str( - &std::env::var(MONARCH_STDERR_LOG_ENV) - .unwrap_or(stderr_log_level.to_string()), - ) - .expect("Invalid log level"), - )) - .with_target("opentelemetry", LevelFilter::OFF), // otel has some log span under debug that we don't care about - ); - use tracing_subscriber::Registry; use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::util::SubscriberInitExt; @@ -645,7 +620,6 @@ pub fn initialize_logging_with_log_prefix( None }) .with(file_layer) - .with(stderr_layer) .with(if is_layer_enabled(DISABLE_RECORDER_TRACING) { Some(recorder().layer()) } else { @@ -680,7 +654,6 @@ pub fn initialize_logging_with_log_prefix( { if let Err(err) = Registry::default() .with(file_layer) - .with(stderr_layer) .with( if std::env::var(DISABLE_RECORDER_TRACING).unwrap_or_default() != "1" { Some(recorder().layer())