| Crates.io | code_logger |
| lib.rs | code_logger |
| version | 0.1.2 |
| created_at | 2025-09-26 11:54:53.392075+00 |
| updated_at | 2025-11-04 10:29:10.008749+00 |
| description | A simple, colorful, and flexible logging library for Rust with timestamps, log levels, and custom error codes. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1855796 |
| size | 17,873 |
A simple, colorful, and flexible logging library for Rust with support for timestamps, log levels, custom error codes, and customizable ANSI colors. Built using a builder pattern for ergonomic usage.
Info, Warn, Error, Debugtimestamp_format("%H:%M:%S")(code 123).no_color().colors(AnsiColors { .. }).color_for_level(Level::Error, "\x1b[97;41m")Warn and Error to stderr, others to stdoutAdd code_logger to your Cargo.toml:
[dependencies]
code_logger = "0.1"
use code_logger::log; // if used as a library crate
fn main() {
// Basic with timestamp and code
log("Hello, world!".to_string())
.timestamp()
.code(42)
.info()
.print();
}
use code_logger::logger::{log, AnsiColors, Level};
fn main() {
// Custom timestamp format
log("Custom time format".to_string())
.timestamp_format("%H:%M:%S")
.debug()
.print();
// Disable colors entirely (useful for logs to file)
log("No colors here".to_string())
.no_color()
.warn()
.print();
// Provide custom colors
let mut custom = AnsiColors::default();
custom.info = "\x1b[35m".to_string(); // magenta
custom.warn = "\x1b[36m".to_string(); // cyan
log("Custom color config".to_string())
.colors(custom)
.info()
.print();
// Override a single level color quickly
log("Only ERROR is white on red".to_string())
.color_for_level(Level::Error, "\x1b[97;41m")
.error()
.print();
}
log(message: String) -> LoggerBuilderLoggerBuilder methods:
.code(i32).timestamp().timestamp_format(fmt: &str).no_color().colors(AnsiColors).color_for_level(Level, &str).info()/.warn()/.error()/.debug() → returns LoggerLogger::print() to emit the log immediately.no_color() when redirecting output to files.%Y-%m-%d %H:%M:%S.Warn/Error go to stderr, which helps when piping or filtering output.