feat: improve log rule

This commit is contained in:
GyDi
2022-07-17 17:39:44 +08:00
parent 66abf27edd
commit 5be6f550be
8 changed files with 33 additions and 33 deletions

View File

@@ -418,7 +418,7 @@ impl Core {
let result = event.payload();
if result.is_none() {
log::warn!("event payload result is none");
log::warn!(target: "app", "event payload result is none");
return;
}
@@ -438,10 +438,10 @@ impl Core {
let service = service.lock();
log_if_err!(service.set_config(info, config, notice));
log::info!("profile enhanced status {}", result.status);
log::info!(target: "app", "profile enhanced status {}", result.status);
}
result.error.map(|err| log::error!("{err}"));
result.error.map(|err| log::error!(target: "app", "{err}"));
});
let verge = self.verge.lock();

View File

@@ -53,12 +53,10 @@ impl Service {
Ok(status) => {
// 未启动clash
if status.code != 0 {
if let Err(err) = Self::start_clash_by_service().await {
log::error!("{err}");
}
log_if_err!(Self::start_clash_by_service().await);
}
}
Err(err) => log::error!("{err}"),
Err(err) => log::error!(target: "app", "{err}"),
}
});
@@ -77,9 +75,7 @@ impl Service {
}
tauri::async_runtime::spawn(async move {
if let Err(err) = Self::stop_clash_by_service().await {
log::error!("{err}");
}
log_if_err!(Self::stop_clash_by_service().await);
});
Ok(())
@@ -109,8 +105,11 @@ impl Service {
tauri::async_runtime::spawn(async move {
while let Some(event) = rx.recv().await {
match event {
CommandEvent::Stdout(line) => log::info!("[clash]: {}", line),
CommandEvent::Stderr(err) => log::error!("[clash]: {}", err),
CommandEvent::Stdout(line) => {
let stdout = if line.len() > 33 { &line[33..] } else { &line };
log::info!(target: "app" ,"[clash]: {}", stdout);
}
CommandEvent::Stderr(err) => log::error!(target: "app" ,"[clash error]: {}", err),
_ => {}
}
}
@@ -152,7 +151,7 @@ impl Service {
match builder.send().await {
Ok(resp) => {
if resp.status() != 204 {
log::error!("failed to activate clash with status \"{}\"", resp.status());
log::error!(target: "app", "failed to activate clash with status \"{}\"", resp.status());
}
notice.refresh_clash();
@@ -160,10 +159,10 @@ impl Service {
// do not retry
break;
}
Err(err) => log::error!("failed to activate for `{err}`"),
Err(err) => log::error!(target: "app", "failed to activate for `{err}`"),
}
}
Err(err) => log::error!("failed to activate for `{err}`"),
Err(err) => log::error!(target: "app", "failed to activate for `{err}`"),
}
sleep(Duration::from_millis(500)).await;
}
@@ -186,7 +185,7 @@ impl Service {
match builder.send().await {
Ok(_) => notice.refresh_clash(),
Err(err) => log::error!("{err}"),
Err(err) => log::error!(target: "app", "{err}"),
}
}
});

View File

@@ -2,7 +2,6 @@ use super::{Clash, Verge};
use crate::{log_if_err, utils::sysopt::SysProxyConfig};
use anyhow::{bail, Result};
use auto_launch::{AutoLaunch, AutoLaunchBuilder};
// use parking_lot::Mutex;
use std::sync::Arc;
use tauri::{async_runtime::Mutex, utils::platform::current_exe};
@@ -46,7 +45,7 @@ impl Sysopt {
if enable {
if let Err(err) = sysproxy.set_sys() {
log::error!("failed to set system proxy for `{err}`");
log::error!(target: "app", "failed to set system proxy for `{err}`");
}
}
@@ -90,7 +89,7 @@ impl Sysopt {
if let Some(sysproxy) = self.old_sysproxy.take() {
match sysproxy.set_sys() {
Ok(_) => self.cur_sysproxy = None,
Err(_) => log::error!("failed to reset proxy"),
Err(_) => log::error!(target: "app", "failed to reset proxy"),
}
}
}
@@ -183,7 +182,7 @@ impl Sysopt {
break;
}
log::debug!("try to guard the system proxy");
log::debug!(target: "app", "try to guard the system proxy");
let clash = Clash::new();
@@ -194,7 +193,7 @@ impl Sysopt {
log_if_err!(sysproxy.set_sys());
}
None => log::error!("failed to parse clash port"),
None => log::error!(target: "app", "failed to parse clash port"),
}
}

View File

@@ -139,7 +139,7 @@ impl Timer {
/// the task runner
async fn async_task(core: Core, uid: String) {
log::info!("running timer task `{uid}`");
log::info!(target: "app", "running timer task `{uid}`");
log_if_err!(Core::update_profile_item(core, uid, None).await);
}
}