|
|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
use std::env::current_exe; |
|
|
|
|
use std::fs; |
|
|
|
|
use std::{env, fs}; |
|
|
|
|
use std::path::Path; |
|
|
|
|
use tracing::{error, Level, subscriber}; |
|
|
|
|
use tracing_appender::non_blocking::{WorkerGuard}; |
|
|
|
|
@ -10,7 +10,13 @@ use crate::parameter_store::get_parameter;
|
|
|
|
|
fn get_log_level_parameter_key() -> Option<String> { |
|
|
|
|
let mut ret: Option<String> = None; |
|
|
|
|
|
|
|
|
|
match env!("CARGO_PKG_NAME") { |
|
|
|
|
let exe_path = current_exe().expect("Failed to get current executable"); |
|
|
|
|
let program_name = exe_path.file_name() |
|
|
|
|
.unwrap_or_else(|| std::ffi::OsStr::new("unknown")) |
|
|
|
|
.to_string_lossy() |
|
|
|
|
.to_string(); |
|
|
|
|
|
|
|
|
|
match program_name.as_str() { |
|
|
|
|
"device-gateway" => { ret = Option::from(GATEWAY_LOG_LEVEL_KEY.to_string()) } |
|
|
|
|
"device-node" => { ret = Option::from(NODE_LOG_LEVEL_KEY.to_string()) } |
|
|
|
|
"device-ticket" => { ret = Option::from(TICKET_LOG_LEVEL_KEY.to_string()) } |
|
|
|
|
@ -78,4 +84,26 @@ fn get_log_dir() -> String {
|
|
|
|
|
current_dir.pop(); |
|
|
|
|
current_dir.push("log"); |
|
|
|
|
current_dir.display().to_string() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[cfg(test)] |
|
|
|
|
mod tests { |
|
|
|
|
use super::*; |
|
|
|
|
use serial_test::serial; |
|
|
|
|
|
|
|
|
|
fn setup() { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn teardown() { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
#[serial] |
|
|
|
|
fn test_get_log_level_parameter_key() { |
|
|
|
|
setup(); |
|
|
|
|
assert!(get_log_level_parameter_key().is_none()); |
|
|
|
|
teardown(); |
|
|
|
|
} |
|
|
|
|
} |