#logging #debugging #development

bin+lib easylog

一个简单易用的日志记录工具库。将日志消息写入文件。

32 个版本 (20 个稳定版)

2.0.1 2019年12月16日
2.0.0 2019年12月13日
1.4.6 2019年4月22日
1.2.0 2018年8月24日
0.1.0 2018年6月9日

#780开发工具

Download history 32/week @ 2024-04-01

每月下载量 84

MIT/Apache

25KB
304

Latest version Documentation License

注意

仅在 Linux 上进行测试!

描述

easylog - 一个简单易用的 Rust 日志记录工具库。

easylog 允许您将日志消息写入文件,以便以后分析。

示例 1

extern crate easylog;

use easylog::{LogFile, LogFileConfig, LogLevel};

fn main() {
    let default = LogFileConfig::new();
    let mut logfile = match LogFile::new(default) {
        Ok(file) => file,

        Err(error) => {
            panic!("Error: `{}`", error);
        }
    };

    logfile.write(LogLevel::DEBUG, "Insert your logmessage here...");
    logfile.write(LogLevel::INFO, "Insert your logmessage here...");
    logfile.write(LogLevel::WARNING, "Insert your logmessage here...");
    logfile.write(LogLevel::ERROR, "Insert your logmessage here...");
    logfile.write(LogLevel::CRITICAL, "Insert your logmessage here...");
}

示例 2

extern crate easylog;

use easylog::{LogFile, LogFileConfig, LogLevel};

fn main() {
    let mut custom_config = LogFileConfig::new();

    custom_config.max_size_in_mb = 2;
    custom_config.path = String::from("/path/to/logfile/");
    custom_config.name = String::from("my_logfile");
    custom_config.extension = String::from(".txt");
    custom_config.num_files_to_keep = 2;

    let logfile = match LogFile::new(custom_config) {
        Ok(file) => file,

        Err(error) => {
            panic!("Error: `{}`", error);
        }
    };
}

示例 3

extern crate easylog;

use easylog::{LogFile, LogFileConfig, LogLevel};

fn main() {
    let mut custom_config = LogFileConfig::new();

    custom_config.max_size_in_mb = 2;
    custom_config.path = String::from("/path/to/logfile/");
    custom_config.name = String::from("my_logfile");
    custom_config.extension = String::from(".txt");
    custom_config.overwrite = false;
    custom_config.num_files_to_keep = 1337; // has no effect, because overwrite is false

    let logfile = match LogFile::new(custom_config) {
        Ok(file) => file,

        Err(error) => {
            panic!("Error: `{}`", error);
        }
    };
}

示例输出

$ cat ./logfile_0.log
2018-06-09 22:51:37.443883  [DEBUG   ]  Insert your logmessage here...
2018-06-09 22:51:37.443969  [INFO    ]  Insert your logmessage here...
2018-06-09 22:51:37.443996  [WARNING ]  Insert your logmessage here...
2018-06-09 22:51:37.444022  [ERROR   ]  Insert your logmessage here...
2018-06-09 22:51:37.444048  [CRITICAL]  Insert your logmessage here...

依赖项

~1MB
~18K SLoC