Skip to content

Commit

Permalink
feat: replace appender rolling with rolling file (#512)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored May 29, 2024
1 parent 8853191 commit 71a8892
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 28 deletions.
26 changes: 18 additions & 8 deletions Cargo.lock

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

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ members = [
]

[workspace.package]
version = "0.1.71"
version = "0.1.72"
authors = ["The Dragonfly Developers"]
homepage = "https://d7y.io/"
repository = "https://github.com/dragonflyoss/client.git"
Expand All @@ -22,13 +22,13 @@ readme = "README.md"
edition = "2021"

[workspace.dependencies]
dragonfly-client = { path = "dragonfly-client", version = "0.1.71" }
dragonfly-client-core = { path = "dragonfly-client-core", version = "0.1.71" }
dragonfly-client-config = { path = "dragonfly-client-config", version = "0.1.71" }
dragonfly-client-storage = { path = "dragonfly-client-storage", version = "0.1.71" }
dragonfly-client-backend = { path = "dragonfly-client-backend", version = "0.1.71" }
dragonfly-client-util = { path = "dragonfly-client-util", version = "0.1.71" }
dragonfly-client-init = { path = "dragonfly-client-init", version = "0.1.71" }
dragonfly-client = { path = "dragonfly-client", version = "0.1.72" }
dragonfly-client-core = { path = "dragonfly-client-core", version = "0.1.72" }
dragonfly-client-config = { path = "dragonfly-client-config", version = "0.1.72" }
dragonfly-client-storage = { path = "dragonfly-client-storage", version = "0.1.72" }
dragonfly-client-backend = { path = "dragonfly-client-backend", version = "0.1.72" }
dragonfly-client-util = { path = "dragonfly-client-util", version = "0.1.72" }
dragonfly-client-init = { path = "dragonfly-client-init", version = "0.1.72" }
thiserror = "1.0"
dragonfly-api = "2.0.114"
reqwest = { version = "0.11.27", features = ["stream", "native-tls", "default-tls", "rustls-tls"] }
Expand Down
1 change: 1 addition & 0 deletions dragonfly-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ anyhow.workspace = true
tracing-log = "0.2"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing-appender = "0.2.3"
rolling-file = "0.2.0"
tracing-opentelemetry = "0.18.0"
opentelemetry = { version = "0.18.0", default-features = false, features = ["trace", "rt-tokio"] }
opentelemetry-jaeger = { version = "0.17.0", features = ["rt-tokio"] }
Expand Down
2 changes: 1 addition & 1 deletion dragonfly-client/src/bin/dfdaemon/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct Args {

#[arg(
long,
default_value_t = 3,
default_value_t = 6,
help = "Specify the max number of log files"
)]
log_max_files: usize,
Expand Down
4 changes: 2 additions & 2 deletions dragonfly-client/src/bin/dfget/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ struct Args {

#[arg(
long,
default_value_t = 3,
default_value_t = 6,
help = "Specify the max number of log files"
)]
log_max_files: usize,
Expand Down Expand Up @@ -198,7 +198,7 @@ struct Args {

#[arg(
long,
default_value_t = 24,
default_value_t = 6,
help = "Specify the dfdaemon's max number of log files"
)]
dfdaemon_log_max_files: usize,
Expand Down
2 changes: 1 addition & 1 deletion dragonfly-client/src/bin/dfstore/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct Args {

#[arg(
long,
default_value_t = 3,
default_value_t = 6,
help = "Specify the max number of log files"
)]
log_max_files: usize,
Expand Down
17 changes: 9 additions & 8 deletions dragonfly-client/src/tracing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
*/

use opentelemetry::sdk::propagation::TraceContextPropagator;
use rolling_file::*;
use std::fs;
use std::fs::OpenOptions;
use std::os::unix::io::AsRawFd;
use std::path::{Path, PathBuf};
use tracing::{info, Level};
use tracing_appender::non_blocking::WorkerGuard;
use tracing_appender::rolling::{RollingFileAppender, Rotation};
use tracing_log::LogTracer;
use tracing_subscriber::{filter::LevelFilter, fmt::Layer, prelude::*, EnvFilter, Registry};

Expand Down Expand Up @@ -56,13 +57,13 @@ pub fn init_tracing(
guards.push(stdout_guard);

// Setup file layer.
let rolling_appender = RollingFileAppender::builder()
.rotation(Rotation::DAILY)
.filename_prefix(name)
.filename_suffix("log")
.max_log_files(log_max_files)
.build(log_dir)
.expect("failed to create rolling file appender");
fs::create_dir_all(log_dir).expect("failed to create log directory");
let rolling_appender = BasicRollingFileAppender::new(
log_dir.join(name).with_extension("log"),
RollingConditionBasic::new().hourly(),
log_max_files,
)
.expect("failed to create rolling file appender");

let (rolling_writer, rolling_writer_guard) = tracing_appender::non_blocking(rolling_appender);
let file_logging_layer = Layer::new()
Expand Down

0 comments on commit 71a8892

Please sign in to comment.