fn create_logger()

This commit is contained in:
Dmitry Belyaev 2022-09-26 10:57:47 +03:00
parent b7791c0882
commit f3226046fd
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3

View File

@ -4,7 +4,9 @@ mod config;
mod server; mod server;
mod service; mod service;
use flexi_logger::{AdaptiveFormat, Age, Cleanup, Criterion, Duplicate, FileSpec, Logger, Naming}; use flexi_logger::{
AdaptiveFormat, Age, Cleanup, Criterion, Duplicate, FileSpec, Logger, LoggerHandle, Naming,
};
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
@ -33,13 +35,16 @@ struct Cli {
command: Command, command: Command,
} }
fn main() { fn create_logger() -> LoggerHandle {
let args = Cli::parse(); Logger::try_with_str("info")
.expect("default logging level invalid")
let logger = Logger::try_with_str("info")
.unwrap()
.log_to_file( .log_to_file(
FileSpec::default().directory(std::env::current_exe().unwrap().parent().unwrap()), FileSpec::default().directory(
std::env::current_exe()
.expect("can't get current exe path")
.parent()
.expect("can't get parent folder"),
),
) )
.rotate( .rotate(
Criterion::Age(Age::Day), Criterion::Age(Age::Day),
@ -56,7 +61,12 @@ fn main() {
.unwrap() .unwrap()
.with_file_name("logspec.toml"), .with_file_name("logspec.toml"),
) )
.unwrap(); .expect("can't start logger")
}
fn main() {
let args = Cli::parse();
let logger = create_logger();
let res = match args.command { let res = match args.command {
Command::Install => service::install(), Command::Install => service::install(),