Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(main): enable debug log option. #150

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions zstor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use actix::Actor;
use actix::Addr;
use actix_rt::signal::unix::SignalKind;
use futures::future::join_all;
use log::LevelFilter;
use log::{debug, error, info, trace};
use log4rs::append::rolling_file::policy::compound::{
roll::fixed_window::FixedWindowRoller, trigger::size::SizeTrigger, CompoundPolicy,
Expand Down Expand Up @@ -47,6 +46,11 @@ struct Opts {
parse(from_os_str)
)]
config: PathBuf,

/// Enable debug logging.
#[structopt(name = "debug", long, short)]
debug: bool,

/// Path to the log file to use. The logfile will automatically roll over if the size
/// increases beyond 10MiB.
#[structopt(
Expand Down Expand Up @@ -236,6 +240,13 @@ async fn write_pid_file(path: &Path) -> ZstorResult<bool> {

async fn real_main() -> ZstorResult<()> {
let opts = Opts::from_args();

let log_level = if opts.debug {
log::LevelFilter::Debug
} else {
log::LevelFilter::Info
};

// TODO: add check for file name
let mut rolled_log_file = opts.log_file.clone();
let name = if let Some(ext) = rolled_log_file.extension() {
Expand Down Expand Up @@ -275,12 +286,8 @@ async fn real_main() -> ZstorResult<()> {
}))
.build("logfile", Box::new(log_file)),
)
.logger(Logger::builder().build("filelogger", LevelFilter::Debug))
.build(
Root::builder()
.appender("logfile")
.build(log::LevelFilter::Debug),
)
.logger(Logger::builder().build("filelogger", log_level))
.build(Root::builder().appender("logfile").build(log_level))
.unwrap();
log4rs::init_config(log_config).unwrap();

Expand Down
Loading