Skip to content

A log tool written in Rust that can work in conjunction with the log component of the standard library. It features synchronized log file recording and log file rolling capabilities

Notifications You must be signed in to change notification settings

FredYakumo/LogUtil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust Log util

A log tool written in Rust that can work in conjunction with the log component of the standard library. It features synchronized log file recording and log file rolling capabilities.

Quick start

#[cfg(test)]
mod tests {
    use lazy_static::lazy_static;
    use log::{debug, error, info, warn};
    use log_util::LogUtil;

    use super::*;

    lazy_static! {
        static ref BASE_LOG: LogUtil = LogUtil::new("TestLog");
    }

    #[test]
    fn test_log() {
        LogUtil::init_with_logger(&BASE_LOG).unwrap();

        info!("Test");
        error!("Test: {}", 5);
        warn!("Test: {}", "abc");
        let b = "def";
        debug!("Test: {}, {b}", "abc");
    }
}

Run this test, you will see console print:

image
Debug Log display only when Set environment variable RUST_LOG="debug"
And you will got log/TestLog with 2 log files: TestLog.log, TestLog_xxxxxxxx.log

No global instance LogUtil(No log file out)

If you don't want to use LogUtil with a global variable instance, init LogUtil with:

LogUtil::init().unwrap()

Log messages will only print to console, no log file output.

About

A log tool written in Rust that can work in conjunction with the log component of the standard library. It features synchronized log file recording and log file rolling capabilities

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages