百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
L

log4rs

> 编程语言
开源

一个高度可配置的日志记录框架,用于 Rust

1.1K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

一个高度可配置的日志记录框架,用于 Rust

log4rs

log4rs is a highly configurable logging framework modeled after Java's Logback and log4j libraries.

Quick Start

log4rs.yaml:

refresh_rate: 30 seconds
appenders:
  stdout:
    kind: console
  requests:
    kind: file
    path: "log/requests.log"
    encoder:
      pattern: "{d} - {m}{n}"
root:
  level: warn
  appenders:
    - stdout
loggers:
  app::backend::db:
    level: info
  app::requests:
    level: info
    appenders:
      - requests
    additive: false

lib.rs:

use log::{error, info, warn};
use log4rs;

fn main() {
    log4rs::init_file("config/log4rs.yaml", Default::default()).unwrap();

    info!("booting up");

    // ...
}

Rust Version Requirements

1.82

Building for Dev

  • Run the tests: cargo test --all-features
  • Run the tests for windows with cross: cross test --target x86_64-pc-windows-gnu
  • Run the tests for all individual features: ./test.sh
  • Run the tests for all individual features for windows with cross: ./test.sh win

Compression

If you are using the file rotation in your configuration there is a known substantial performance issue with either the gzip or zstd features. When rolling files it will zip log archives automatically. This is a problem when the log archives are large as the zip process occurs in the main thread and will halt the process until the zip process completes.

The methods to mitigate this are as follows.

  1. Use the background_rotation feature which spawns an os thread to do the compression.
  2. Do not enable the gzip nor the zstd features.
  3. Ensure the archives are small enough that the compression time is acceptable.

For more information see the PR that added background_rotation.

Wasm Support

If you are building this library for a Wasm target with the time_trigger feature enabled, you need to make sure the Rust flag --cfg getrandom_backend="wasm_js" is supplied to the compiler. This should be automatic when compiling with Cargo, but some configurations and tooling might require you to set an environment variable:

export RUSTFLAGS='--cfg getrandom_backend="wasm_js"'

License

Licensed under either of

  • Apache License, Version 2.0 (LICENSE-APACHE or )
  • MIT license (LICENSE-MIT or )

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rustjsonlogloggingrust

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言