librarius

Crates.iolibrarius
lib.rslibrarius
version0.1.1
created_at2025-04-14 04:39:54.589904+00
updated_at2025-04-14 04:52:48.335738+00
descriptionA simple and lightweight logging library for Rust. It provides a flexible framework for emitting log messages from Rust programs, with support for different log levels and output formats.
homepage
repositoryhttps://github.com/joaoprado-rs/librarius
max_upload_size
id1632374
size8,331
João Prado (joaoprado-rs)

documentation

README

Librarius

Librarius is a logging library in Rust that provides logging functionality for different severity levels, such as Info, Warn, Error, and Debug. The library allows logs to be sent to the terminal or a file, depending on the configuration. It is easy to integrate and configure within any Rust application.

Features

  • Support for multiple log levels: Info, Warn, Error, Debug.
  • Logs can be output to the terminal or written to a file.
  • Custom log formatting with date, time, and timezone.
  • Easy integration with logging macros (info!, warn!, error!).
  • Simple configuration using the Config struct.

Installation

Add the following dependency to your Cargo.toml:

[dependencies]
librarius = "0.1"

Usage Example

Logging at the terminal

use librarius::{Logger, Level, Config};

fn main() {

    // Create the configuration
    let config = Config::new(Level::Info);
    
    // Initialize the logger
    librarius::init(config);

    // Using the log macros
    info!("This is an info log");
    warn!("This is a warning log");
    error!("This is an error log");
    debug!("This is a debug log");
}

Logging at a file

use librarius::{Logger, Level, Config};

fn main() {

    // Create the configuration
    let config = Config::with_file(Level::Info, "logs.txt");
    
    // Initialize the logger
    librarius::init(config);

    // Using the log macros
    info!("This is an info log");
    warn!("This is a warning log");
    error!("This is an error log");
    debug!("This is a debug log");
}

Configuration

You can configure Librarius by creating a Config, where you define the log level and whether logs should be written to a file:

use librarius::{Config, Level};

let config = Config::with_file(Level::Info, "logs.txt");

License

This project is licensed under the MIT License - see the LICENSE file for details.

Commit count: 12

cargo fmt