From 75af2d2920ab019690cfdac61f9d1541ba2df273 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Wed, 29 Mar 2023 13:48:17 +0800 Subject: [PATCH] update: more rust log levels --- include/constant.h.in | 4 ++++ src/assets/src/ffi.rs | 15 +++++++++------ src/cleardns.c | 10 +++++++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/include/constant.h.in b/include/constant.h.in index 768409c..576541a 100644 --- a/include/constant.h.in +++ b/include/constant.h.in @@ -37,6 +37,10 @@ #define ASSET_CHINA_IP "china-ip.txt" #define ASSET_CHINA_LIST "chinalist.txt" +#define RUST_LOG_INFO 0 +#define RUST_LOG_DEBUG 1 +#define RUST_LOG_TRACE 2 + #define EXIT_NORMAL 0 #define EXIT_FORK_ERROR 1 #define EXIT_EXEC_ERROR 2 diff --git a/src/assets/src/ffi.rs b/src/assets/src/ffi.rs index ac41a44..de73eba 100644 --- a/src/assets/src/ffi.rs +++ b/src/assets/src/ffi.rs @@ -1,9 +1,9 @@ use std::io::Write; use std::env::set_var; +use log::{debug, warn}; use std::path::PathBuf; use std::fs::OpenOptions; use std::os::raw::c_char; -use log::{debug, trace, warn}; use std::ffi::{CStr, CString}; use crate::fetch::asset_fetch; @@ -29,12 +29,15 @@ unsafe fn load_c_string_list(ptr: *const *const c_char) -> Vec { string_list } -/// Initialize the rust module log, enable trace level log when verbose is not `0`. +/// Initialize the rust module log, using info level log when verbose is `0`, +/// enable debug level when verbose is `1`, and others for trace level. #[no_mangle] pub unsafe extern "C" fn assets_log_init(verbose: u8, prefix: *const c_char) { - if verbose == FALSE { // bool value `FALSE` + if verbose == 0 { // info level set_var("RUST_LOG", "info"); - } else { + } else if verbose == 1 { // debug level + set_var("RUST_LOG", "debug"); + } else { // trace level set_var("RUST_LOG", "trace"); } let log_prefix = load_c_string(prefix); @@ -68,8 +71,8 @@ pub async unsafe extern "C" fn asset_update( let name = load_c_string(file); // import c-style string let sources = load_c_string_list(sources); let assets_dir = load_c_string(assets_dir); - trace!("Working folder is `{}`", assets_dir); - trace!("Updating `{}` from {:?}", name, sources); + debug!("Working folder is `{}`", assets_dir); + debug!("Updating `{}` from {:?}", name, sources); let assets_dir = PathBuf::from(&assets_dir); let is_remote = |src: &str| { diff --git a/src/cleardns.c b/src/cleardns.c index 75b1b93..084ac23 100644 --- a/src/cleardns.c +++ b/src/cleardns.c @@ -64,12 +64,16 @@ void init(int argc, char *argv[]) { // return config file } void cleardns() { // cleardns service + uint8_t rust_log_level = RUST_LOG_INFO; // using info level as default if (settings.verbose || settings.debug) { LOG_LEVEL = LOG_DEBUG; // enable debug log level - assets_log_init(TRUE, LOG_PREFIX); - } else { - assets_log_init(FALSE, LOG_PREFIX); + rust_log_level = RUST_LOG_DEBUG; + if (settings.debug) { + rust_log_level = RUST_LOG_TRACE; // enable rust trace log + } } + assets_log_init(rust_log_level, LOG_PREFIX); // setting rust log level + create_folder(EXPOSE_DIR); create_folder(WORK_DIR); chdir(EXPOSE_DIR);