-
Notifications
You must be signed in to change notification settings - Fork 54
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
Make primary writers public? #47
Comments
To make sure we avoid the XY problem, I'm trying to build a logger that works like this: let log_file: Option<PathBuf>; // path to directory
let stderr_isatty = atty::is(atty::Stream::Stderr); // whether stderr is attached to a terminal or not
match (log_file, isatty) {
(None, true) => , // Only log to stderr
(None, false) => , // Log to stderr, and duplicate >= INFO to stdout
(Some(dir), true) => ,// Log to file, duplicate ALL to stderr, nothing to stdout
(Some(dir), false) => , // Log to file, duplicate to stderr, and duplicate >= INFO to stdout
} edit: just noticed that duplication does not occur if |
In branch issue-47 I added a builder option 'Logger::duplicate_to_stdout()'. With this, you could use // Only log to stderr
.log_target(LogTarget::StdErr)
// Log to stderr, and duplicate >= INFO to stdout
.log_target(LogTarget::DevNull) // only pretends to log
.duplicate_to_stderr(Duplicate::All)
.duplicate_to_stdout(Duplicate::Info)
// Log to file, duplicate ALL to stderr, nothing to stdout
.log_target(LogTarget::File)
.duplicate_to_stderr(Duplicate::All)
// Log to file, duplicate to stderr, and duplicate >= INFO to stdout
.log_target(LogTarget::File)
.duplicate_to_stderr(Duplicate::All)
.duplicate_to_stdout(Duplicate::Info) What do you think? |
Yup sounds good! Thank you so much for your help! |
Implemented with version 0.15.5. |
@emabee Getting back to this issue, I think I'm missing something like |
I'm trying to log things to a file, stderr, and stdout at the same time.
To do that I must create a new writer for Stdout which I've done this way:
However, I was wondering if flexi_logger couldn't expose the
StdoutWriter
that it already uses internally (as a Primary Writer), to make that easier.Or maybe I'm missing something :)
Thanks!
The text was updated successfully, but these errors were encountered: