Crate loggix

Crate loggix 

Source
Expand description

Loggix is a powerful structured logging library for Rust, inspired by Logrus.

§Features

  • Seven log levels: Trace, Debug, Info, Warning, Error, Fatal, and Panic
  • Structured logging with fields
  • Beautiful terminal output with colors
  • JSON formatter for machine processing
  • Extensible hook system
  • Thread-safe by default
  • Global and local logger instances

§Quick Start

use loggix::{info, with_fields};

fn main() {
    // Simple logging
    info!("A walrus appears");

    // Structured logging with fields
    with_fields!(
        "animal".to_string() => "walrus".to_string(),
        "size".to_string() => 10.to_string()
    )
    .info("A group of walrus emerges");
}

§Advanced Features

§Error Handling

use loggix::with_error;
use std::fs::File;

fn main() {
    let result = File::open("non_existent.txt");
    if let Err(error) = result {
        with_error(&error).error("Failed to open file");
    }
}

§Custom Time Fields

use loggix::with_time;
use chrono::Utc;

fn main() {
    let event_time = Utc::now();
    with_time(event_time).info("Event occurred at specific time");
}

§Multiple Fields

use loggix::{Logger, Fields};

fn main() {
    let fields = vec![
        ("user", "john"),
        ("action", "login"),
        ("ip", "192.168.1.1"),
    ];

    Logger::new()
        .build()
        .with_fields(Fields::new())
        .with_fields_map(fields)
        .info("User login activity");
}

§Level Parsing

use loggix::Level;

fn main() {
    if let Some(level) = Level::from_str("INFO") {
        println!("Parsed level: {}", level);
    }
}

§Thread Safety

Loggix is thread-safe by default, using Arc and Mutex internally to protect shared state. All logging operations are atomic and can be safely used across multiple threads.

§Customization

The library is highly customizable through:

  • Custom formatters implementing the Formatter trait
  • Custom hooks implementing the Hook trait
  • Custom output implementing std::io::Write

§Performance Considerations

  • Zero-allocation logging paths for common use cases
  • Efficient field storage using pre-allocated hashmaps
  • Lock-free architecture where possible
  • Minimal runtime overhead

See the README for more examples and detailed documentation.

Re-exports§

pub use chrono;
pub use colored;
pub use serde;
pub use serde_json;

Macros§

debug
error
fatal
info
panic
trace
warn
with_fields

Structs§

Entry
A log entry containing all information about a log event
EntryBuilder
Builder for log entries
JSONFormatter
JSON formatter for machine-readable output
KafkaHook
A hook that sends log entries to Kafka
Logger
The main logger struct
TextFormatter
Text formatter with optional colors

Enums§

Level
Log levels supported by Loggix

Traits§

Formatter
Formatter trait for implementing custom formatters
Hook
Hook trait for implementing custom hooks

Functions§

parse_level
set_level
with_error
with_fields
with_time

Type Aliases§

Fields
Fields type for structured logging