luhlog

Crates.ioluhlog
lib.rsluhlog
version0.1.0
created_at2025-11-11 00:48:19.195428+00
updated_at2025-12-06 21:44:18.121697+00
descriptionA horrible Rust logging library
homepage
repositoryhttps://github.com/calizoots/luhlog
max_upload_size
id1926489
size89,392
s (calizoots)

documentation

README

LuhLog

github crates.io docs.rs

A way to log your messages, it is nothing special at all.
It has a formatting system, convient macros and a global logger system >.<

It is made with love though s.c <3

As a library, we expose:

  • luhtwin::Logger and trait luhtwin::Log for creating custom loggers.
  • luhtwin::LogFormatter for formatting logs.
  • luhtwin::Level with 5 well 6 levels (Trace, Debug, Info, Warn, Error and Critical - no macro for critical level -), similar to the log crate.
  • Corresponding macros (trace!, debug!, info!, warn!, error!) for the global logger instance through get_logger().

This is still in development stages. Thank you for your patience.

We also provide luhtwin::GlobalLogger for creating your own global logger instance.


Examples

1. Basic usage

use luhlog::{set_logger, Level, CompactFormatter, info, warn, trace};

fn main() {
    // Level sets the requirement: logs below this won't be logged
    // Formatter must implement LogFormatter
    set_logger!(level: Level::Info, formatter: CompactFormatter);

    info!("hello world");
    warn!(target: "main", "targeting main <3");

    // Won't be printed because it's below the Level::Info threshold
    trace!("bine");
}

2. Using a logger directly

use luhlog::{set_logger, get_logger, Level, LogBuilder, Logger, CompactFormatter};

fn main() {
    set_logger!(level: Level::Trace);

    let logger = get_logger();

    let other_logger = Logger::with_formatter(
        Level::Info,
        std::sync::Arc::new(CompactFormatter)
    ).no_stdout().file("test.log").expect("failed to open test.log");

    // log directly with a custom LogBuilder
    logger.log(
        LogBuilder::new("hello guys <3")
            .level(Level::Trace)
            .build()
    );

    other_logger.log(
        LogBuilder::new("in the file >.<")
            .target("main")
            .level(Level::Warn)
            .location(file!(), line!())
            .build()
    );
}

3. Using GlobalLogger

use luhlog::{GlobalLogger, Log, Level, LogBuilder};

static LOG: GlobalLogger = GlobalLogger::new();

fn main() {
    LOG.get().log(
        LogBuilder::new("test for GlobalLogger :3")
            .target("LOG")
            .level(Level::Info)
            .location(file!(), line!())
            .build()
    );
}

4. Custom formatters

use luhlog::{set_logger, Level, Logger, LogBuilder};
use std::sync::Arc;

#[derive(Debug)]
struct MyFormatter;

impl luhtwin::LogFormatter for MyFormatter {
    fn format(&self, record: &luhtwin::LogRecord) -> String {
        format!(">>> {} <<<", record.msg)
    }
}

fn main() {
    let logger = Logger::with_formatter(Level::Info, Arc::new(MyFormatter));
    set_logger!(logger);

    luhtwin::info!("custom format");
}

5. No stdout

use luhlog::{set_logger, Level, Logger, info};

fn main() {
    let logger = Logger::new(Level::Info).no_stdout();
    set_logger!(logger);

    info!("this won't print to stdout");
}
Commit count: 0

cargo fmt