logger_bro

Crates.iologger_bro
lib.rslogger_bro
version0.3.0
created_at2025-09-11 03:58:24.902523+00
updated_at2025-09-13 08:18:34.272618+00
descriptionA simple, aligned, colorful logger with [level] [obj]: message formatting.
homepage
repositoryhttps://github.com//logger_bro
max_upload_size
id1833307
size5,986
Dingyi Sun (dingyisun0101)

documentation

README

logger_bro

Introduction

This Rust program defines a lightweight logging utility with custom formatting:

  • Log Levels: Three severity levels (INFO, WARN, CRIT), each automatically colored (red for level, green for object tag).
  • Custom Object Tag: Each log message includes a user-defined obj string, centered to a fixed width for clean alignment.
  • Formatted Output: Messages are written in the style
[LEVEL] (obj): message

with a consistent gap after the colon.

  • Unicode Support: Object names are centered by display width, handling wide characters gracefully.
  • Convenient Macros: info!, warn!, and crit! macros provide shorthand for logging messages without manually calling format_args!.
  • Thread Safety: The logger wraps its output writer (stdout by default) in a Mutex, making it safe for concurrent use.

This makes it easy to track structured logs in Rust projects with aligned, color-coded, and thread-safe output.

Instructions

Creating an Instance

For Usage in the Same File

let Logger = Logger::new(obj_txt_width)

For Usage across Files

pub static LOGGER: Lazy<Logger> = Lazy::new(|| Logger::new(obj_txt_width));

Logging a Message

use logger_bro::{info, crit, warn};
use super::{your_file}::LOGGER;    // If it is defined elsewhere

info!(
    &LOGGER,
    "obj",
    "msg",
    args,
);
Commit count: 0

cargo fmt