Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging for different logging levels #169

Closed
threeh11 opened this issue Jul 27, 2024 · 1 comment
Closed

Logging for different logging levels #169

threeh11 opened this issue Jul 27, 2024 · 1 comment
Labels

Comments

@threeh11
Copy link

Hi! Thanks for your library. The question is whether it is possible to create two instances logging different levels and having different paths. Or there can't be more than 1 instance at all. I'm sorry if my question may seem silly. I'm just learning all this) Example:

Logger::try_with_str("info")?
    .log_to_file(
        FileSpec::default()
            .directory(self.path)
            .basename("path1")
            .use_timestamp(false)
            .suffix("log")
    )
    .write_mode(WriteMode::Direct)
    .format(detailed_format)
    .duplicate_to_stderr(Duplicate::Error)
    .start()?;
Logger::try_with_str("error")?
    .log_to_file(
        FileSpec::default()
            .directory(self.path)
            .basename("path2")
            .use_timestamp(false)
            .suffix("log")
    )
    .write_mode(WriteMode::Direct)
    .format(detailed_format)
    .duplicate_to_stderr(Duplicate::Error)
    .start()?;
@emabee
Copy link
Owner

emabee commented Jul 29, 2024

flexi_logger is one of several alternative backends for the log crate. The log crate defines some macros that applications and libraries use in their code to write log entries.
By registering a log backend in its main method, the application finally defines if and how these write calls will be handled.
Registering two or more backends is not possible. flexi_logger offers instead some flexibility to handle various backends in parallel (stdout stderr, files, syslog, other writers).

See module writers for details how to direct individual log calls to explicitly registered writers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants