Crates.io | moe_logger |
lib.rs | moe_logger |
version | 0.2.0 |
source | src |
created_at | 2021-09-14 14:39:20.11473 |
updated_at | 2021-09-15 14:23:31.686559 |
description | A logger with various features. |
homepage | |
repository | https://github.com/KernelErr/moe-logger |
max_upload_size | |
id | 451246 |
size | 24,649 |
(>ω<) Another logger based on pretty-env-logger and env_logger. Allow writing log to file with features like formatting, file rotation.
Append following lines to Cargo.toml
:
log = "0.4"
moe_logger = "0.2"
There's an example:
use log::{info, warn, error, debug};
use moe_logger::LogConfig;
fn main() {
let log_config = LogConfig::builder()
.env("MOE_LOG_LEVEL")
.output("run.log")
.format("{t} {L} {T} > {M}\n")
.rotation(10000)
.finish();
moe_logger::init(log_config);
info!("Di di ba ba wu~");
debug!("Debug...");
warn!("WARNING!");
error!("Oops >_<");
}
(^ω^) Here is some notice about features provided.
If you specify a path to store log, Moe Logger would write formatted log to that path and unformatted log to stdout in the meanwhile.
(;>△<) If log file exists, Moe Logger will only use stdout! So move old logs to another place before running.
We are using TinyTemplate to format content wrote to file. If you are interested in more fancy logs, you may should check its document. Moe Logger provided variables listed below:
Default format: {L} {T} > {M}\n
(;>△<) DO NOT FORGET \n
You can specify after how many line written, Moe Logger would rename it like output.log.x
. Default 0 for disabled.
(。・`ω´・)ノ Writing log to disk would worse the efficiency of your code. But we are always trying to optimize this problem. If you have any ideas, pull requests and issues are welcomed.
The table below shows the performance difference when you enable different features. (By running an actix-web back-end on my PC)
Feature | Requests per Second |
---|---|
No Log | ~16000 |
Only to Stdout | ~15000 |
Stdout & File | ~5600 |
Stdout & File(with Rotation) | ~5200 |
Moe Logger is distributed under the terms of both Apache-2.0 and MIT license.