From ceeb7406d44760925ed474029fe743c20306d011 Mon Sep 17 00:00:00 2001 From: Ryan Date: Thu, 1 Aug 2024 15:53:49 +0900 Subject: [PATCH] 0.1.4 --- Cargo.toml | 2 +- RELEASE_NOTE.md | 10 +++++++++- src/log.rs | 46 ++++++---------------------------------------- 3 files changed, 16 insertions(+), 42 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 50be5d0..56eecb5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "device-common" -version = "0.1.2" +version = "0.1.4" edition = "2021" authors = ["Ryan Bae "] diff --git a/RELEASE_NOTE.md b/RELEASE_NOTE.md index 1e7d00e..a7504b4 100644 --- a/RELEASE_NOTE.md +++ b/RELEASE_NOTE.md @@ -9,4 +9,12 @@ first deploy 0.1.2 ====== -- create log directory \ No newline at end of file +- create log directory + +0.1.3 +====== +- remove s3 dependency(rusoto_core, rusoto_s3) + +0.1.4 +====== +- fix bug for using toml library \ No newline at end of file diff --git a/src/log.rs b/src/log.rs index 7f0e5f8..255dfe9 100644 --- a/src/log.rs +++ b/src/log.rs @@ -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 { - 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 { let mut ret: Option = 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