Skip to content

Commit 7701a69

Browse files
Kh4Llinuxdevel
authored andcommitted
fix(sandbox): rotate openshell.log daily, keep 3 files (NVIDIA#431)
1 parent 0c42a50 commit 7701a69

File tree

1 file changed

+11
-8
lines changed
  • crates/openshell-sandbox/src

1 file changed

+11
-8
lines changed

crates/openshell-sandbox/src/main.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,18 @@ struct Args {
9595
async fn main() -> Result<()> {
9696
let args = Args::parse();
9797

98-
// Try to open the log file; fall back to stdout-only logging if it fails
98+
// Try to open a rolling log file; fall back to stdout-only logging if it fails
9999
// (e.g., /var/log is not writable in custom workload images).
100-
let file_logging = std::fs::OpenOptions::new()
101-
.create(true)
102-
.append(true)
103-
.open("/var/log/openshell.log")
100+
// Rotates daily, keeps the 3 most recent files to bound disk usage.
101+
let file_logging = tracing_appender::rolling::RollingFileAppender::builder()
102+
.rotation(tracing_appender::rolling::Rotation::DAILY)
103+
.filename_prefix("openshell")
104+
.filename_suffix("log")
105+
.max_log_files(3)
106+
.build("/var/log")
104107
.ok()
105-
.map(|file| {
106-
let (writer, guard) = tracing_appender::non_blocking(file);
108+
.map(|roller| {
109+
let (writer, guard) = tracing_appender::non_blocking(roller);
107110
(writer, guard)
108111
});
109112

@@ -156,7 +159,7 @@ async fn main() -> Result<()> {
156159
.with(push_layer)
157160
.init();
158161
// Log the warning after the subscriber is initialized
159-
warn!("Could not open /var/log/openshell.log; using stdout-only logging");
162+
warn!("Could not open /var/log for log rotation; using stdout-only logging");
160163
None
161164
};
162165

0 commit comments

Comments
 (0)