Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kernelerr/moe-logger
A Rust logger with various features.
https://github.com/kernelerr/moe-logger
Last synced: 3 months ago
JSON representation
A Rust logger with various features.
- Host: GitHub
- URL: https://github.com/kernelerr/moe-logger
- Owner: KernelErr
- License: apache-2.0
- Created: 2021-09-14T14:26:11.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-09-15T14:23:09.000Z (over 3 years ago)
- Last Synced: 2024-10-12T02:21:36.847Z (3 months ago)
- Language: Rust
- Homepage:
- Size: 8.79 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# Moe Logger
(>ω<) Another logger based on [pretty-env-logger](https://github.com/seanmonstar/pretty-env-logger) and [env_logger](https://github.com/env-logger-rs/env_logger/). Allow writing log to file with features like formatting, file rotation.
## Usage
Append following lines to `Cargo.toml`:
```rust
log = "0.4"
moe_logger = "0.2"
```There's an example:
```rust
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 >_<");
}
```## Features
(^ω^) Here is some notice about features provided.
### Output
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.
### Format
We are using [TinyTemplate](https://github.com/bheisler/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:
- t - [RFC3339](https://www.ietf.org/rfc/rfc3339.txt) Date & Time
- L - Log Level
- T - Log Target
- M - Log Message
- F - File NameDefault format: `{L} {T} > {M}\n`
(;>△<) DO NOT FORGET `\n`
### Rotation
You can specify after how many line written, Moe Logger would rename it like `output.log.x`. Default 0 for disabled.
## Performance
(。・`ω´・)ノ 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 |## License
Moe Logger is distributed under the terms of both Apache-2.0 and MIT license.