logform-rs
A flexible log formatting library for Rust, inspired by the Node.js logform package.
use ;
let format = combine;
let mut info = new;
let formatted_info = format.transform.unwrap;
println!;
Features
- Composable log formats
- Various built-in formats
- Extensible with custom formats
- Chainable options for each format
Table of Contents
LogInfo Objects
The LogInfo struct represents a single log message:
Formats
Align
The align format adds a tab character before the message.
let aligned_format = align;
Colorize
The colorize format adds colors to log levels and messages.
let colorizer = colorize
.with_option
.with_option;
Combine
The combine format allows you to chain multiple formats together.
let combined_format = combine;
JSON
The json format converts the log info into a JSON string.
let json_format = json;
Ms
The ms format adds the time in milliseconds since the last log message.
let ms_format = ms;
PrettyPrint
The pretty_print format provides a more readable output of the log info.
let pretty_format = pretty_print.with_option;
Printf
The printf format allows you to define a custom formatting function.
let printf_format = printf;
Simple
The simple format provides a basic string representation of the log info.
let simple_format = simple;
Timestamp
The timestamp format adds a timestamp to the log info.
let timestamp_format = timestamp
.with_option
.with_option;
Uncolorize
The uncolorize format removes ANSI color codes from the log info.
let uncolorize_format = uncolorize;
Usage
To use logform-rs in your project, add it to your Cargo.toml:
[]
= "0.1.0"
Then, in your Rust code:
use ;
let format = combine;
let info = new;
let formatted_info = format.transform.unwrap;
println!;
Testing
Run the tests using:
License
This project is licensed under the MIT License.
Acknowledgements
This library is inspired by the logform package for Node.js.