dyn-logger

Crates.iodyn-logger
lib.rsdyn-logger
version0.2.7
sourcesrc
created_at2023-03-17 17:25:24.631263
updated_at2024-01-10 17:44:34.404946
descriptionCrate to configure tracing logger dynamically via configuration file in toml format.
homepage
repositoryhttps://github.com/koopa1338/dyn-logger
max_upload_size
id812872
size15,637
koopa (koopa1338)

documentation

README

Dyn Logger

This crate provides a configuration option for the tracing logging crate, allowing you to configure the logging based on a logging.toml file. With this file, you can easily change the log level per module, as well as the format and other options for the logger. Additionally, the crate allows you to configure multiple file loggers, each with its own log level, format, color, and path options.

Usage

To use this crate, simply add it as a dependency to your Cargo.toml file:

[dependencies]
dyn-logger = "0.2"

Then, configure your logger as shown below. This will read the logging.toml file in your project's root directory, and apply the configuration settings to your tracing logger.

fn main() -> Result<(), Box<dyn std::error::Error>>  {
    let logger = DynamicLogger::new("path/to/logging.toml")?
        .with_stdout()?
        .with_file_logger()?;
    logger.init();

    // ...

    Ok(())
}

Configuration

The logging.toml file allows you to configure the logging options for your application. Here is an example:

# global logging options
[global]
log_level = "trace"
enabled = false
format = "compact" # Options: `full`, `compact`, `pretty` and `json`
line_number = true
file = true
thread_name = true
thread_id = true

 # special std out logging, overrides global settings
[stream_logger]
enabled = true
color = true
format = "pretty" # Options: `full`, `compact`, `pretty` and `json`
line_number = true
file = true
thread_name = true
thread_id = true
modules = [
    "module=trace",
    "module::submodule_one=trace",
    "module::submodule_two=debug",
    "module::submodule_three=info",
]

# logging to files, uses global options
[[file_logger]]
enabled = true
filename = "logfile.log"
path = "./logs"
line_number = false # override global options
thread_id = false # override global options
format = "json" # Options: `full`, `compact`, `pretty` and `json`
modules = [
    "module_name::submodule::example=trace",
]

[[file_logger]]
enabled = true
filename = "another_logfile.log"
path = "./logs"
format = "compact" # Options: `full`, `compact`, `pretty` and `json`
modules = [
    "module_name::submodule=trace",
    "module_name::other_submodule=debug",
]

License

This crate is licensed under the EUPL-1.2 License. See the LICENSE file for more information.

Commit count: 19

cargo fmt