|
|
|
|
@ -4,52 +4,18 @@ use std::path::Path;
|
|
|
|
|
use tracing::{error, Level, subscriber}; |
|
|
|
|
use tracing_appender::non_blocking::{WorkerGuard}; |
|
|
|
|
use tracing_appender::rolling::{RollingFileAppender, Rotation}; |
|
|
|
|
use tracing_unwrap::{OptionExt, ResultExt}; |
|
|
|
|
use crate::constants::{FAILOVER_LOG_LEVEL_KEY, GATEWAY_LOG_LEVEL_KEY, NODE_LOG_LEVEL_KEY, TICKET_LOG_LEVEL_KEY}; |
|
|
|
|
use crate::parameter_store::get_parameter; |
|
|
|
|
|
|
|
|
|
fn read_cargo_toml() -> toml::Value{ |
|
|
|
|
let cargo_toml_content = fs::read_to_string("Cargo.toml") |
|
|
|
|
.expect_or_log("Failed to read Cargo.toml file"); |
|
|
|
|
|
|
|
|
|
let cargo_toml: toml::Value = toml::from_str(&cargo_toml_content) |
|
|
|
|
.expect_or_log("Failed to parse Cargo.toml"); |
|
|
|
|
|
|
|
|
|
cargo_toml |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn get_app_name() -> Option<String> { |
|
|
|
|
let cargo_toml = read_cargo_toml(); |
|
|
|
|
|
|
|
|
|
let package = cargo_toml |
|
|
|
|
.get("package") |
|
|
|
|
.expect("`[package]` section is missing in Cargo.toml"); |
|
|
|
|
|
|
|
|
|
let name = package |
|
|
|
|
.get("name") |
|
|
|
|
.expect_or_log("`name` field is missing in Cargo.toml"); |
|
|
|
|
|
|
|
|
|
let name_str = name |
|
|
|
|
.as_str() |
|
|
|
|
.expect_or_log("Package name is not a string"); |
|
|
|
|
|
|
|
|
|
Option::from(name_str.to_string()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn get_log_level_parameter_key() -> Option<String> { |
|
|
|
|
let mut ret: Option<String> = None; |
|
|
|
|
|
|
|
|
|
match get_app_name() { |
|
|
|
|
None => { ret = None } |
|
|
|
|
Some(app_name) => { |
|
|
|
|
match app_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()) } |
|
|
|
|
"device-failover" => { ret = Option::from(FAILOVER_LOG_LEVEL_KEY.to_string()) } |
|
|
|
|
_ => { return ret } |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
match env!("CARGO_PKG_NAME") { |
|
|
|
|
"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()) } |
|
|
|
|
"device-failover" => { ret = Option::from(FAILOVER_LOG_LEVEL_KEY.to_string()) } |
|
|
|
|
_ => { return ret } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ret |
|
|
|
|
|