Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fast/logforth

Repository files navigation

Logforth

Crates.io Documentation MSRV 1.80 Apache 2.0 licensed Build Status

Logforth is a flexible and easy-to-use logging framework for Rust applications. It allows you to configure multiple dispatches, filters, and appenders to customize your logging setup according to your needs.

Features

  • Multiple Dispatches: Configure different logging behaviors for different parts of your application.
  • Flexible Filters: Use built-in or custom filters to control which log records are processed.
  • Various Appenders: Output logs to stdout, stderr, files, or even send them to OpenTelemetry collectors.
  • Elegant Layouts: Format log records using predefined layouts or create your own.
  • Enrichable Diagnostics: Attach additional context to log records for better debugging and analysis.
  • Custom Components: Easily implement your own appenders, filters, layouts, and diagnostics by implementing the provided traits.
  • Bridges: Out-of-the-box integration with the log crate for seamless logging.

Getting Started

Add log and logforth to your Cargo.toml:

cargo add log
cargo add logforth -F starter-log

Simple Usage

Set up a basic logger that outputs to stdout:

fn main() {
    logforth::starter_log::stdout().apply();

    log::error!("This is an error message.");
    log::info!("This is an info message.");
    log::debug!("This debug message will not be printed by default.");
}

By default, all logging except the error level is disabled. You can enable logging at other levels by setting the RUST_LOG environment variable. For example, RUST_LOG=debug cargo run will print all logs.

Advanced Usage

Configure multiple dispatches with different filters and appenders:

use logforth::append;
use logforth::record::Level;
use logforth::record::LevelFilter;

fn main() {
    logforth::starter_log::builder()
        .dispatch(|d| d
            .filter(LevelFilter::MoreSevereEqual(Level::Error))
            .append(append::Stderr::default()))
        .dispatch(|d| d
            .filter(LevelFilter::MoreSevereEqual(Level::Info))
            .append(append::Stdout::default()))
        .apply();

    log::error!("This error will be logged to stderr.");
    log::info!("This info will be logged to stdout.");
    log::debug!("This debug message will not be logged.");
}

Read more demos under the examples directory.

Documentation

Read the online documents at https://docs.rs/logforth.

Components are organized into several crates:

Minimum Rust version policy

This crate is built against the latest stable release, and its minimum supported rustc version is 1.85.0.

The policy is that the minimum Rust version required to use this crate can be increased in minor version updates. For example, if Logforth 1.0 requires Rust 1.60.0, then Logforth 1.0.z for all values of z will also require Rust 1.60.0 or newer. However, Logforth 1.y for y > 0 may require a newer minimum version of Rust.

Maturity

This crate has been in development since 2024-08. It is being used in several production systems stable enough to be considered mature, but it is still evolving.

All modular components are factored out into separate crates. We are working to stabilize the core APIs and several core components, and then release them as logforth-core 1.0. Other components will be released as separate crates that depend on logforth-core.

License and Origin

This project is licensed under Apache License, Version 2.0.

The name Logforth comes from an antonym of the Logback project, and may also be read as a homophone of "log force".

About

A versatile and extensible logging implementation.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 11

Languages