2 releases
0.1.2 | Feb 4, 2024 |
---|---|
0.1.1 | Feb 3, 2024 |
0.1.0 |
|
#71 in #input-output
7KB
136 lines
ezlog
- a simple, easy-to-configure, lightweight, action-based logger.
The ezlog
crate provides a simple logger. It does not provide any integration with the log
API.
The log request consists of an action, input data and output data. Nothing more.
A lot of things are hardcoded, so using this library as-is is not advised. Save it as your own crate.
Install
cargo add easy-log
Usage
The library has a Logger
type and a map![]
macro.
To build a logger, use the provided methods like this:
use ezlog::{Logger, map, Map};
let default = Logger::new(); // empty
let default2 = Logger::default(); // same as the above
let default = default.ok(); // nothing set => does nothing
let default = default.action("test").ok(); // prints TEST: in green
let default = default.ok();
assert_eq!(
map![test1: 234],
Map(&[("test1".to_string(), "234".to_string())]) // auto conversion to String
);
let test2 = "This is a test.";
assert_eq!(
map![test2],
Map(&[("test2".to_string(), "This is a test.".to_string())]) // auto expansion
);
// you can chain methods
default
.action("test2")
.input(map![test2])
.output(36) // not only maps
.warn(); // prints the action in yellow
default2
.action("test")
.action("third") // you can override the preferences set before
.err();
let really = true;
Logger::new()
.action("final")
.input(map![what: "test"])
.output(map![of_what: "of this lib", really])
.print("purple"); // set a custom color
Dependencies
~1–11MB
~61K SLoC