MCPcopy Index your code
hub / github.com/estk/log4rs

github.com/estk/log4rs @v1.4.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.4.0 ↗ · + Follow
467 symbols 1,094 edges 39 files 79 documented · 17%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

log4rs

docs crates.io License: MIT OR Apache-2.0 Minimum rustc version CI

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.75

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.

License

Licensed under either of

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.

Extension points exported contracts — how you extend this code

Write (Interface)
A trait for types that an `Encode`r will write to. It extends `std::io::Write` and adds some extra functionality. [25 …
src/encode/mod.rs
Deserializable (Interface)
A trait implemented by traits which are deserializable. [6 implementers]
src/config/raw.rs
Append (Interface)
A trait implemented by log4rs appenders. Appenders take a log record and processes them, for example, by writing it to [6 …
src/append/mod.rs
Filter (Interface)
The trait implemented by log4rs filters. Filters are associated with appenders and limit the log events that will be se [3 …
src/filter/mod.rs
Encode (Interface)
A trait implemented by types that can serialize a `Record` into a `Write`r. `Encode`rs are commonly used by `Append`ers [4 …
src/encode/mod.rs
Deserialize (Interface)
A trait for objects that can deserialize log4rs components out of a config. [23 implementers]
src/config/raw.rs
Trigger (Interface)
A trait which identifies if the active log file should be rolled over. [3 implementers]
src/append/rolling_file/policy/compound/trigger/mod.rs
ErasedDeserialize (Interface)
(no doc) [1 implementers]
src/config/raw.rs

Core symbols most depended-on inside this repo

build
called by 72
src/append/file.rs
path
called by 51
src/append/rolling_file/mod.rs
encode
called by 21
src/encode/pattern/mod.rs
write_all
called by 21
src/encode/writer/ansi.rs
level
called by 20
src/config/runtime.rs
appender
called by 19
src/config/runtime.rs
insert
called by 19
src/config/raw.rs
len
called by 17
src/append/rolling_file/mod.rs

Shape

Method 210
Function 121
Class 104
Enum 22
Interface 10

Languages

Rust100%

Modules by API surface

src/encode/pattern/mod.rs58 symbols
src/config/raw.rs32 symbols
src/config/runtime.rs30 symbols
src/append/rolling_file/mod.rs25 symbols
src/append/rolling_file/policy/compound/roll/fixed_window.rs24 symbols
src/append/rolling_file/policy/compound/trigger/time.rs22 symbols
src/append/console.rs22 symbols
src/lib.rs20 symbols
src/append/file.rs20 symbols
examples/custom_config.rs17 symbols
src/encode/writer/console.rs16 symbols
src/encode/pattern/parser.rs16 symbols

For agents

$ claude mcp add log4rs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact