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

MIT/Apache

28KB
499 lines

loge

Crates.io Docs MIT/APACHE-2.0 GitHub Workflow Status

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 enable chrono;
  • For pretty output, enable colored.
  • By default, we turn on all three features.
  • You can choose one of three formats: target, fileline or json. (Set environment variable LOGE_FORMAT.)

Examples:

  • target: date time [level] target ... message(enable chrono) or level target ... message:

    loge output

  • fileline: date time [level] file - target (line) ... message(enable chrono) or level file - target (line) ... message:

    loge fileline output

  • json: You should enable json and chrono; for pretty output, enable colored.

    {
      "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:

Acknowledge

Dependencies

~1.1–8.5MB
~69K SLoC