27 releases (breaking)

0.19.0 Dec 7, 2024
0.18.1 Nov 17, 2024
0.17.1 Nov 12, 2024

#78 in Debugging

Download history 389/week @ 2024-08-24 503/week @ 2024-08-31 362/week @ 2024-09-07 764/week @ 2024-09-14 1506/week @ 2024-09-21 654/week @ 2024-09-28 1273/week @ 2024-10-05 1623/week @ 2024-10-12 1536/week @ 2024-10-19 2222/week @ 2024-10-26 1629/week @ 2024-11-02 2998/week @ 2024-11-09 2828/week @ 2024-11-16 2621/week @ 2024-11-23 1967/week @ 2024-11-30 2599/week @ 2024-12-07

10,525 downloads per month
Used in 5 crates (3 directly)

Apache-2.0

140KB
2.5K SLoC

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.

Stabilize targets

To release a 1.0 version, it's essential to declare what targets this crate wants to stabilize. Even beyond 1.0, it's helpful to distinguish different portions of this crate to allow unstable modules to make breaking changes to improve their quality, just as how rust-lang's stabilization mechanism works.

Basically, this crate contains:

  • Fundamental logging APIs (Appender, Layout, Filter, Dispatch, Logger, etc.): these MUST BE stabilized before 1.0.
  • Basic layouts and filters (all current existing): these SHOULD BE stabilized before 1.0.
  • Basic appenders (Stdout, Stderr, RollingFile): these SHOULD BE stabilized before 1.0.
  • Advanced appenders (Fastrace, OpentelemetryLog, Syslog, etc.): to-be-determined how to stabilize them.

Generally, there are known usage for Fastrace and OpentelemetryLog, so we can confidently announce their stable version; others are still waiting for feedback.

License and Origin

This project is licensed under Apache License, Version 2.0.

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

Dependencies

~6–18MB
~246K SLoC