2 releases

new 0.1.3 Oct 19, 2024
0.1.2 Oct 19, 2024
0.0.6 Oct 18, 2024

#200 in Debugging

Download history 812/week @ 2024-10-15

812 downloads per month

MIT license

13KB
244 lines

Rimplog

A simple, colorful, and easy-to-use logging library for Rust

Rimplog means Rainbow Simple Logging

Getting Started with rimplog

rimplog is a simple, colorful, and easy-to-use logging library for Rust. This guide will help you get started with rimplog in your Rust projects.

Dependencies

To use rimplog in your project, add the following to your Cargo.toml file:

[dependencies]
rimplog = "0.1.3"

Building the Logger

rimplog uses a builder pattern to configure the logger. Here's how to create a custom logger:

use rimplog::{LoggerBuilder, LoggerPreset};

pub fn main() {
    let logger = LoggerBuilder {
        level: "info",
        only_project_logs: true,
        path_depth: 1,
        time_format: "%Y-%m-%d %H:%M:%S".to_string(),
        preset: LoggerPreset::FULL,
    };
}

If you're happy with the default settings, you can simply use:

use rimplog::LoggerBuilder;

pub fn main() {
    let logger = LoggerBuilder::default();
}

Customizing the Logger

You can customize the following options:

  • level: Log level (off, error, warn, info, debug, trace)
  • only_project_logs: Whether to show only project logs (true/false)
  • path_depth: Depth of file path to display
  • time_format: Custom time format string
  • preset: Logger preset (FULL, THREAD, SIMPLE)

Initializing the Logger

Once you've built your logger, initialize it at the start of your program:

use rimplog::init_logger;

fn main() {
    init_logger(logger);
}

Using the Logger

After initialization, you can use the logging macros throughout your code:

use rimplog::{info, error, warn, debug, trace};

fn some_function() {
    info!("This is an info log");
    error!("This is an error log");
    warn!("This is a warning log");
    debug!("This is a debug log");
    trace!("This is a trace log");

    loggger::info!("This is an info log")
}

For logs without automatic newlines, use the underscore versions:

use rimplog::{_info};

fn another_function() {
    _info!("installing: ");
    println!("success");
}

That's it! You're now ready to use rimplog in your Rust projects. Enjoy colorful and customizable logging!

Dependencies

~1–11MB
~65K SLoC