Browse Source

update: more rust log levels

dev
Dnomd343 2 years ago
parent
commit
75af2d2920
  1. 4
      include/constant.h.in
  2. 15
      src/assets/src/ffi.rs
  3. 10
      src/cleardns.c

4
include/constant.h.in

@ -37,6 +37,10 @@
#define ASSET_CHINA_IP "china-ip.txt" #define ASSET_CHINA_IP "china-ip.txt"
#define ASSET_CHINA_LIST "chinalist.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_NORMAL 0
#define EXIT_FORK_ERROR 1 #define EXIT_FORK_ERROR 1
#define EXIT_EXEC_ERROR 2 #define EXIT_EXEC_ERROR 2

15
src/assets/src/ffi.rs

@ -1,9 +1,9 @@
use std::io::Write; use std::io::Write;
use std::env::set_var; use std::env::set_var;
use log::{debug, warn};
use std::path::PathBuf; use std::path::PathBuf;
use std::fs::OpenOptions; use std::fs::OpenOptions;
use std::os::raw::c_char; use std::os::raw::c_char;
use log::{debug, trace, warn};
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
use crate::fetch::asset_fetch; use crate::fetch::asset_fetch;
@ -29,12 +29,15 @@ unsafe fn load_c_string_list(ptr: *const *const c_char) -> Vec<String> {
string_list 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] #[no_mangle]
pub unsafe extern "C" fn assets_log_init(verbose: u8, prefix: *const c_char) { 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"); 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"); set_var("RUST_LOG", "trace");
} }
let log_prefix = load_c_string(prefix); 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 name = load_c_string(file); // import c-style string
let sources = load_c_string_list(sources); let sources = load_c_string_list(sources);
let assets_dir = load_c_string(assets_dir); let assets_dir = load_c_string(assets_dir);
trace!("Working folder is `{}`", assets_dir); debug!("Working folder is `{}`", assets_dir);
trace!("Updating `{}` from {:?}", name, sources); debug!("Updating `{}` from {:?}", name, sources);
let assets_dir = PathBuf::from(&assets_dir); let assets_dir = PathBuf::from(&assets_dir);
let is_remote = |src: &str| { let is_remote = |src: &str| {

10
src/cleardns.c

@ -64,12 +64,16 @@ void init(int argc, char *argv[]) { // return config file
} }
void cleardns() { // cleardns service void cleardns() { // cleardns service
uint8_t rust_log_level = RUST_LOG_INFO; // using info level as default
if (settings.verbose || settings.debug) { if (settings.verbose || settings.debug) {
LOG_LEVEL = LOG_DEBUG; // enable debug log level LOG_LEVEL = LOG_DEBUG; // enable debug log level
assets_log_init(TRUE, LOG_PREFIX); rust_log_level = RUST_LOG_DEBUG;
} else { if (settings.debug) {
assets_log_init(FALSE, LOG_PREFIX); 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(EXPOSE_DIR);
create_folder(WORK_DIR); create_folder(WORK_DIR);
chdir(EXPOSE_DIR); chdir(EXPOSE_DIR);

Loading…
Cancel
Save