Comments (5)
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?
from flexi_logger.
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 log_target
is Stderr or Stdout ^^'
from flexi_logger.
Yup sounds good!
I would never have thought about using LogTarget::DevNull
to "pretend" to log in order to be able to duplicate
. It might be worth mentioning it in the docs somewhere (my two cents! :)).
Thank you so much for your help!
from flexi_logger.
Implemented with version 0.15.5.
from flexi_logger.
@emabee Getting back to this issue, I think I'm missing something like format_for_stdout()
to be able to log with colors to stdout, while keeping LogTarget::Stderr and LogTarget::File without colors. Should I try submitting a PR for this one?
from flexi_logger.
Related Issues (20)
- Allow different log levels for file and stderr logging HOT 1
- Consider removing feature flag from `DeferredNow::format_rfc3339`
- `DeferredNow::format_rfc3339` uses wrong timezone information
- FileLogWriter feature duplicate_to_stderr
- Keeping the logger handle alive HOT 1
- RUSTSEC-2021-0145 HOT 1
- Add support for capturing in tests HOT 1
- Get all log files include rolling
- There is no line number in the log? HOT 2
- Option to disable stderr/stdout output? HOT 4
- How to reopen the output file of a FileLogWriter after Logger::add_writer took it over? HOT 2
- Dynamic logging for parent/daemon HOT 1
- bufsize in std_writer::AsyncHandle HOT 2
- Missing `regex` and `log` dependencies - fail to compile HOT 1
- Method on LoggerHandle for manually forcing rotation?
- Remove remnants of the external_rotation feature
- Rotation may overwrite existing log file HOT 9
- Different logger instances per thread? HOT 1
- GlobError unwrap happens HOT 3
- [trc] Improve usability by getting values from `Logger` or integrating with it HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flexi_logger.