#logging-tracing #log-level #toml-config #logging #logger #config-file #tracing

dyn-logger

Crate to configure tracing logger dynamically via configuration file in toml format

12 releases

0.2.7 Jan 10, 2024
0.2.6 Jan 10, 2024
0.2.5 Oct 7, 2023
0.2.4 Jul 18, 2023
0.1.0 Mar 17, 2023

#231 in Debugging

Download history 1/week @ 2024-07-20 19/week @ 2024-07-27 9/week @ 2024-09-21 2/week @ 2024-09-28

119 downloads per month

EUPL-1.2

15KB
291 lines

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.

Dependencies

~6–8.5MB
~149K SLoC