12 unstable releases (3 breaking)
0.4.2 | Jun 8, 2020 |
---|---|
0.4.1 | Feb 4, 2020 |
0.3.1 | Jan 29, 2020 |
0.2.3 | Jan 22, 2020 |
0.1.2 | Jan 16, 2020 |
#51 in #terminal-file
48 downloads per month
28KB
499 lines
loge
It helps to be diligent in recording and willing to review.
A simple logger with formatted output for easy analysis. Free your productivity start with best practices logs.
loge
is currently controlled by features and environment variables:
- If you need to record time, enable
chrono
; - When you enable
json
, you also need to enablechrono
; - For pretty output, enable
colored
. - By default, we turn on all three features.
- You can choose one of three formats:
target
,fileline
orjson
. (Set environment variableLOGE_FORMAT
.)
Examples:
-
target:
date time [level] target ... message
(enablechrono
) orlevel target ... message
: -
fileline:
date time [level] file - target (line) ... message
(enablechrono
) orlevel file - target (line) ... message
: -
json: You should enable
json
andchrono
; for pretty output, enablecolored
.{ "time": "2020-02-02 18:33:33.645", "level": "ERROR", "message": "boom -> tests/simple-jsonified-log.rs:17", "service": { "name": "loge", "version": "0.4.1" }, "location": { "file": "tests/simple-jsonified-log.rs", "line": 17, "target": "simple_jsonified_log::tests" } }
-
file: If you want to print log to a file, enable it, and you will see output both in terminal and file.
TODO
- Format
- Simple JSON Logger. // Unoptimized.
- Colorful, Intuitive.
- Analysis
- Basic Parser.
- Coarse-grained Chart.
- Others
- Lightweight - As few dependencies as possible.
- Clear architecture and flexible configuration.
- Asynchronous.
- Output to file.
Usage
At first, you should add it to your Cargo.toml
file.
[dependencies]
log = "0.4.8"
loge = "0.4.2"
After that, set the RUST_LOG
& LOGE_FORMAT
variable in your code and initialize the logger.
std::env::set_var("RUST_LOG", "trace");
std::env::set_var("LOGE_FORMAT", "target"); // `fileline` or `json`(need enable `json` and `chrono`)
loge::init(); // If you enable `file`, you can't use this func.
// Or `loge::init_with_file("your-app.log");`, but need enable `file`, and will see output both in terminal and file.
Just run your project, you will get logs in the terminal.
Contact
Chojan Shang - @PsiACE - psiace@outlook.com
Project Link: https://github.com/psiace/loge
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
Acknowledge
- Thank you Sean McArthur for
pretty_env_log
. - Thank you Sam Clements for
rust-simple_logger
. - Thank you Christopher Blanchard for
file-logger
.
Dependencies
~1.1–8.5MB
~69K SLoC