Skip to content

Commit

Permalink
Add logs rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
azarovh committed Dec 20, 2024
1 parent de026fb commit 752da7c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ enum-iterator = "2.0"
enumflags2 = "0.7"
expect-test = "1.3"
fallible-iterator = "0.3"
file-rotate = "0.7"
fix-hidden-lifetime-bug = "0.2"
fixed-hash = "0.8"
flate2 = "1.0"
Expand Down
1 change: 1 addition & 0 deletions node-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ utils-networking = { path = "../utils/networking" }

anyhow.workspace = true
clap = { workspace = true, features = ["derive"] }
file-rotate.workspace = true
jsonrpsee = { workspace = true, features = ["macros"] }
tokio = { workspace = true, default-features = false }
serde = { workspace = true, features = ["derive"] }
Expand Down
12 changes: 10 additions & 2 deletions node-lib/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use std::{
sync::Arc,
};

use file_rotate::{compression::Compression, suffix::AppendCount, ContentLimit, FileRotate};

use anyhow::{anyhow, Context, Result};
use blockprod::rpc::BlockProductionRpcServer;
use chainstate_launcher::{ChainConfig, StorageBackendConfig};
Expand Down Expand Up @@ -264,8 +266,14 @@ pub async fn setup(options: Options) -> Result<NodeSetupResult> {

// Init logging
if run_options.log_to_file.is_some_and(|log_to_file| log_to_file) {
let log_file = std::fs::File::create(data_dir.join(LOG_FILE_NAME))
.map_err(|e| anyhow!("Cannot create log file in {data_dir:?}: {e}"))?;
let log_file = FileRotate::new(
data_dir.join(format!("logs/{}", LOG_FILE_NAME)),
AppendCount::new(2), // total 3 file
ContentLimit::Bytes(100_000_000), // 100MB each
Compression::None,
#[cfg(unix)]
None,
);
logging::init_logging_to(log_file, false);
} else {
logging::init_logging();
Expand Down

0 comments on commit 752da7c

Please sign in to comment.