Skip to content

Commit

Permalink
better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoskal committed Jan 23, 2024
1 parent 5e3493a commit 24bd47e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion aicirt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn daemon_format(

pub fn init_log(mode: LogMode) -> Result<()> {
let logger = match mode {
LogMode::Normal => Logger::try_with_env_or_str("warn")?.log_to_stdout(),
LogMode::Normal => Logger::try_with_env_or_str("info")?.log_to_stdout(),
LogMode::Test => {
Logger::try_with_env_or_str("debug")?.write_mode(WriteMode::SupportCapture)
}
Expand Down
9 changes: 9 additions & 0 deletions rllm/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ pub struct RllmCliArgs {
#[arg(long, short, name = "NAME=VALUE")]
pub setting: Vec<String>,

/// Set log level (ex: "info,rllm=trace,aicirt=debug", "warn", "error")
#[arg(long)]
pub log: Option<String>,

/// HuggingFace model name, URL or path starting with "./"
#[arg(short, long, help_heading = "Model")]
pub model: String,
Expand Down Expand Up @@ -468,6 +472,11 @@ fn guess_aicirt() -> Result<String> {

// #[actix_web::main]
pub async fn server_main(mut args: RllmCliArgs) -> () {
// we setenv, so that aicirt process also gets it
match &args.log {
Some(v) => std::env::set_var("RUST_LOG", v),
None => {}
}
aicirt::init_log(if args.daemon {
aicirt::LogMode::Deamon
} else {
Expand Down
19 changes: 17 additions & 2 deletions rllm/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,27 @@ pub fn apply_settings(settings: &Vec<String>) -> Result<()> {
Ok(())
}

fn logging_info() -> &'static str {
r#"
There are 5 logging levels: error, warn, info, debug, and trace.
You can assign different log levels to crates:
info,rllm=trace,aicirt=debug - rllm at trace, aicirt at debug, otherwise info
You can set logging levels with --log or with RUST_LOG environment variable.
"#
}

pub fn parse_with_settings<T>() -> T
where
T: Parser + Args,
{
let cli =
Command::new("CLI").after_help(format!("\n{}\n{}", all_settings(), list_tokenizers()));
let cli = Command::new("CLI").after_help(format!(
"\n{}\n{}\n{}",
all_settings(),
list_tokenizers(),
logging_info()
));
let cli = T::augment_args(cli);
let matches = cli.get_matches();
T::from_arg_matches(&matches)
Expand Down

0 comments on commit 24bd47e

Please sign in to comment.