Skip to content
/ logforth Public

A versatile and extensible logging implementation.

License

Notifications You must be signed in to change notification settings

fast/logforth

Repository files navigation

Logforth

Crates.io Documentation MSRV 1.75 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.
  • Custom Layouts: Format log records using predefined layouts or create your own.

Getting Started

Add log and logforth to your Cargo.toml:

cargo add log
cargo add logforth

Simple Usage

Set up a basic logger that outputs to stdout:

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

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

Advanced Usage

Configure multiple dispatches with different filters and appenders:

use logforth::append;
use log::LevelFilter;

fn main() {
    logforth::builder()
        .dispatch(|d| d
            .filter(LevelFilter::Error)
            .append(append::Stderr::default()))
        .dispatch(|d| d
            .filter(LevelFilter::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.

Minimum Rust version policy

This crate is built against the latest stable release, and its minimum supported rustc version is 1.75.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.20.0, then Logforth 1.0.z for all values of z will also require Rust 1.20.0 or newer. However, Logforth 1.y for y > 0 may require a newer minimum version of Rust.

When to release a 1.0 version

After one year of practicing the interfaces, if there are no further blockers, I'll release a 1.0 version. So consequently, it can be as early as 2025-08.

License and Origin

This project is licensed under Apache License, Version 2.0.

The name Logforth comes from an antonym to the Logback project.