Crate luhlog

Crate luhlog 

Source
Expand description

githubcrates-iodocs-rs

§LuhLog


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

So as a library we expose luhlog::Logger and trait luhlog::Log for making custom log and also exposing luhlog::LogFormatter for formatting.

luhlog::Level has 6 levels similar to the log crate with Trace being the lowest and Critical being the heighest in terms of precedence we have corresponding macros for those levels for now they only correspond to the global logger instance through get_logger().

This is still in dev stages I will amend that soon. Thank you for your patience.

We also provide luhlog::GlobalLogger for making your own global logger instance. Look at examples below for usage…

§Examples


use luhlog::{set_logger, Level, CompactFormatter, info, warn, trace};
fn main() {
    // level sets the requirement... logs below this wont be logged
    // formatter sets the formatter needs to implement LogFormatter
    set_logger!(level: Level::Info, formatter: CompactFormatter);
    info!("hello world");
    warn!(target: "main", "targeting main <3");
    // wont be printed
    trace!("bine");
}

use luhlog::{set_logger, get_logger, Level, LogBuilder, Log, 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");
    // this allows for finer control of what your printing
    logger.log(
        // this has a default level of Info
        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()
    );
}

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()
    );
}

Hope you guys enjoy… any features or issues please message me

  • Thank you for reading :)

Modules§

macros

Macros§

debug
Logs a message at [Level::Debug].
error
Logs a message at [Level::Error].
info
Logs a message at [Level::Info].
log
The base macro for all logging in luhlog.
set_logger
A convenient macro for setting up the global logger.
trace
Logs a message at [Level::Trace].
warn
Logs a message at [Level::Warn].

Structs§

CompactFormatter
Small basic formatter
DefaultFormatter
In the name a default formatter <3
GlobalLogger
luhlog::GlobalLogger provides a simple thread-safe global logging container. It allows you to store and retrieve a single shared logger instance across your entire program.
JsonFormatter
luhlog::JsonFormatter barely works at all if you need this write your own implementation using serde escaping json this will not work in prod!!!
LogBuilder
luhlog::LogBuilder is an easy way to build a LogRecord. Doesn’t really do much apart from shorter combinators and a predefined level for the record.
LogRecord
luhlog::LogRecord carries all appropriate metadata for a given log entry. There are two ways this is useful to you.
Logger
luhlog::Logger is the main logging backend implementation. It handles log filtering, formatting, writing to files, and optional output to stdout.

Enums§

Level
luhlog::Level is an enum representing the verbosity of a given message

Traits§

Log
luhlog::Log is the core trait that powers all logging backends.
LogFormatter
luhlog::LogFormatter decides how your logs look.

Functions§

clear_logger
Clears the currently active global logger.
flush
Flushes the global logger’s internal records.
get_logger
Retrieves the active global logger instance.
set_logger
Sets the global logger for this library instance.