Skip to content

Commit

Permalink
refactor(logging): use tracing instead of log4rs (#486)
Browse files Browse the repository at this point in the history
* refactor(logging): use tracing instead of log4rs

* feat(logging): use internal max files settings and reload logger whithout restart app

* chore: cleanup and rm log4rs

* chore: update scripts
  • Loading branch information
greenhat616 authored Feb 25, 2024
1 parent 5a51834 commit 791baa5
Show file tree
Hide file tree
Showing 18 changed files with 380 additions and 224 deletions.
151 changes: 73 additions & 78 deletions backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ authors = ["zzzgydi", "keiko233"]

[workspace.dependencies]
thiserror = "1"
tracing = "0.1"

[profile.release]
panic = "abort"
Expand Down
15 changes: 13 additions & 2 deletions backend/tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ open = "5.0.1"
log = "0.4.20"
ctrlc = "3.4.2"
dunce = "1.0.4"
log4rs = "1.2.0"
nanoid = "0.4.0"
chrono = "0.4.31"
sysinfo = "0.30"
Expand All @@ -35,7 +34,7 @@ auto-launch = "0.5"
once_cell = "1.19.0"
port_scanner = "0.1.5"
delay_timer = "0.11.5"
parking_lot = "0.12.1"
parking_lot = { version = "0.12.1" }
tokio = { version = "1", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
reqwest = { version = "0.11", features = ["json", "rustls-tls"] }
Expand Down Expand Up @@ -70,6 +69,17 @@ rust-i18n = "3"
adler = "1.0.2"
rfd = "0.10" # should bump to v0.14 when clarify why the rfd v0.10 from tauri breaks build
indexmap = { version = "2.2.3", features = ["serde"] }
tracing = { workspace = true }
tracing-attributes = "0.1"
tracing-futures = "0.2"
tracing-subscriber = { version = "0.3", features = [
"env-filter",
"json",
"parking_lot",
] }
tracing-error = "0.2"
tracing-log = { version = "0.2" }
tracing-appender = { version = "0.2", features = ["parking_lot"] }

[target.'cfg(windows)'.dependencies]
deelevate = "0.2.0"
Expand Down Expand Up @@ -112,3 +122,4 @@ custom-protocol = ["tauri/custom-protocol"]
verge-dev = []
default-meta = []
nightly = []
deadlock-detection = ["parking_lot/deadlock_detection"]
4 changes: 2 additions & 2 deletions backend/tauri/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
mod clash;
mod core;
mod draft;
mod nyanpasu;
mod prfitem;
mod profiles;
mod runtime;
mod verge;

pub use self::{clash::*, core::*, draft::*, prfitem::*, profiles::*, runtime::*, verge::*};
pub use self::{clash::*, core::*, draft::*, nyanpasu::*, prfitem::*, profiles::*, runtime::*};
49 changes: 49 additions & 0 deletions backend/tauri/src/config/nyanpasu/logging.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use super::IVerge;
use serde::{Deserialize, Serialize};
use tracing_subscriber::filter;
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum LoggingLevel {
#[serde(rename = "silent", alias = "off")]
Silent,
#[serde(rename = "trace", alias = "tracing")]
Trace,
#[serde(rename = "debug")]
Debug,
#[serde(rename = "info")]
Info,
#[serde(rename = "warn", alias = "warning")]
Warn,
#[serde(rename = "error")]
Error,
}

impl Default for LoggingLevel {
#[cfg(debug_assertions)]
fn default() -> Self {
Self::Trace
}

#[cfg(not(debug_assertions))]
fn default() -> Self {
Self::Info
}
}

impl From<LoggingLevel> for filter::LevelFilter {
fn from(level: LoggingLevel) -> Self {
match level {
LoggingLevel::Silent => filter::LevelFilter::OFF,
LoggingLevel::Trace => filter::LevelFilter::TRACE,
LoggingLevel::Debug => filter::LevelFilter::DEBUG,
LoggingLevel::Info => filter::LevelFilter::INFO,
LoggingLevel::Warn => filter::LevelFilter::WARN,
LoggingLevel::Error => filter::LevelFilter::ERROR,
}
}
}

impl IVerge {
pub fn get_log_level(&self) -> LoggingLevel {
self.app_log_level.clone().unwrap_or_default()
}
}
Loading

0 comments on commit 791baa5

Please sign in to comment.