Skip to content

Commit 75fa355

Browse files
runtime: Route logger records according to file logging
Align stderr routing with log_to_file so normal records are file-only when enabled and only errors reach stderr when disabled. Update observability tests and contracts to document the stream behavior while preserving user-facing diagnostics and command payload routing. Co-authored-by: SCE <sce@crocoder.dev>
1 parent b7b3a9e commit 75fa355

12 files changed

Lines changed: 917 additions & 944 deletions

‎cli/src/services/app_support.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ mod tests {
334334

335335
let rendered = String::from_utf8(stderr).expect("stderr is valid utf8");
336336
let redacted_message =
337-
services::security::redact_sensitive_text(&UserError::NotAuthenticated.message());
337+
services::security::redact_sensitive_text(UserError::NotAuthenticated.message());
338338
assert!(rendered.contains(&redacted_message));
339339
}
340340

‎cli/src/services/error.rs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,6 @@ mod tests {
224224
UserError::NotGitRepository.key(),
225225
"setup.not_git_repository"
226226
);
227-
assert_eq!(
228-
UserError::NotGitRepository.message(),
229-
"This directory is not a Git repository. Run `git init`, then rerun `sce setup`."
230-
);
231227
assert_eq!(error.to_string(), UserError::NotGitRepository.message());
232228
}
233229

‎cli/src/services/observability.rs‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ fn cli_error_fields(error: &CliError) -> Vec<(&'static str, String)> {
306306
}
307307

308308
fn should_emit_to_stderr(level: LogLevel, log_to_file: bool) -> bool {
309-
level != LogLevel::Error || !log_to_file
309+
level == LogLevel::Error && !log_to_file
310310
}
311311

312312
fn validate_log_dir(value: &str) -> Result<()> {
@@ -752,10 +752,17 @@ mod tests {
752752
}
753753

754754
#[test]
755-
fn non_error_records_remain_on_stderr_when_file_logging_is_enabled() {
756-
assert!(should_emit_to_stderr(LogLevel::Warn, true));
757-
assert!(should_emit_to_stderr(LogLevel::Info, true));
758-
assert!(should_emit_to_stderr(LogLevel::Debug, true));
755+
fn non_error_records_do_not_route_to_stderr_when_file_logging_is_enabled() {
756+
assert!(!should_emit_to_stderr(LogLevel::Warn, true));
757+
assert!(!should_emit_to_stderr(LogLevel::Info, true));
758+
assert!(!should_emit_to_stderr(LogLevel::Debug, true));
759+
}
760+
761+
#[test]
762+
fn non_error_records_do_not_route_to_stderr_when_file_logging_is_disabled() {
763+
assert!(!should_emit_to_stderr(LogLevel::Warn, false));
764+
assert!(!should_emit_to_stderr(LogLevel::Info, false));
765+
assert!(!should_emit_to_stderr(LogLevel::Debug, false));
759766
}
760767

761768
#[test]

‎cli/src/services/setup/command.rs‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -173,22 +173,3 @@ fn setup_required_hooks_outcome_from_lifecycle(
173173
.collect(),
174174
}
175175
}
176-
177-
#[cfg(test)]
178-
mod tests {
179-
use super::*;
180-
use std::time::{SystemTime, UNIX_EPOCH};
181-
182-
fn unique_temp_dir(label: &str) -> std::path::PathBuf {
183-
let nonce = SystemTime::now()
184-
.duration_since(UNIX_EPOCH)
185-
.expect("system time should be after Unix epoch")
186-
.as_nanos();
187-
let directory = std::env::temp_dir().join(format!(
188-
"sce-setup-command-{label}-{}-{nonce}",
189-
std::process::id()
190-
));
191-
std::fs::create_dir_all(&directory).expect("create temporary directory");
192-
directory
193-
}
194-
}

0 commit comments

Comments
 (0)