env_logger: Target::Pipe doesn't work
In #204, we introduce Target::Pipe to redirect log messages into custom writer. And it’s included in 0.8.4 now.
But when I try the example in that PR, it doesn’t print the message from pipe at all, and not even call WriteAdapter::write. The log::error message just go straight to stderr.
How to make it catch all log message into my custom writer object?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 4
- Comments: 38 (23 by maintainers)
Commits related to this issue
- Replace env_logger with simplelog, for custom log targets env_logger should support it but it is currently broken: https://github.com/env-logger-rs/env_logger/issues/208 — committed to orottier/web-audio-api-rs by orottier 2 years ago
- logging: use our own custom logger I wanted to use the Target::Pipe feature of env_logger so that we could log to a log file as well as stderr, but it just doesn't work (https://github.com/env-logger... — committed to wez/wezterm by wez 2 years ago
- WIP switch to `simplelog` `env_logger` does not handle writing to file for the moment, see https://github.com/env-logger-rs/env_logger/issues/208 — committed to kraktus/rust-clippy by kraktus 2 years ago
- WIP switch to `simplelog` `env_logger` does not handle writing to file for the moment, see https://github.com/env-logger-rs/env_logger/issues/208 — committed to kraktus/rust-clippy by kraktus 2 years ago
- WIP switch to `simplelog` `env_logger` does not handle writing to file for the moment, see https://github.com/env-logger-rs/env_logger/issues/208 — committed to kraktus/rust-clippy by kraktus 2 years ago
- Switch to `simplelog` `env_logger` does not handle writing to file for the moment, see https://github.com/env-logger-rs/env_logger/issues/208 — committed to kraktus/rust-clippy by kraktus 2 years ago
- Better logging for `lintcheck` Use `simplelog` to handle logs, as `env_logger` does not handle writing to file for the moment, see https://github.com/env-logger-rs/env_logger/issues/208 — committed to kraktus/rust-clippy by kraktus 2 years ago
- Better logging for `lintcheck` Use `simplelog` to handle logs, as `env_logger` does not handle writing to file for the moment, see https://github.com/env-logger-rs/env_logger/issues/208 Do not push ... — committed to kraktus/rust-clippy by kraktus 2 years ago
- Better logging for `lintcheck` Use `simplelog` to handle logs, as `env_logger` does not handle writing to file for the moment, see https://github.com/env-logger-rs/env_logger/issues/208 Do not push ... — committed to kraktus/rust-clippy by kraktus 2 years ago
- Better logging for `lintcheck` Use `simplelog` to handle logs, as `env_logger` does not handle writing to file for the moment, see https://github.com/env-logger-rs/env_logger/issues/208 Do not push ... — committed to kraktus/rust-clippy by kraktus 2 years ago
- Better logging for `lintcheck` Use `simplelog` to handle logs, as `env_logger` does not handle writing to file for the moment, see https://github.com/env-logger-rs/env_logger/issues/208 Do not push ... — committed to kraktus/rust-clippy by kraktus 2 years ago
- Better logging for `lintcheck` Use `simplelog` to handle logs, as `env_logger` does not handle writing to file for the moment, see https://github.com/env-logger-rs/env_logger/issues/208 Do not push ... — committed to kraktus/rust-clippy by kraktus 2 years ago
- Better logging for `lintcheck` Use `simplelog` to handle logs, as `env_logger` does not handle writing to file for the moment, see https://github.com/env-logger-rs/env_logger/issues/208 Do not push ... — committed to kraktus/rust-clippy by kraktus 2 years ago
- Better logging for `lintcheck` Use `simplelog` to handle logs, as `env_logger` does not handle writing to file for the moment, see https://github.com/env-logger-rs/env_logger/issues/208 Do not push ... — committed to kraktus/rust-clippy by kraktus 2 years ago
My PR over at the termcolor repo will make a simple path for enabling color for pipe targets down the road. But it doesn’t do us any good until it’s on crates.io.
That approach sounds reasonable, I’d be happy about a PR.
and for the record: this was how I fixed it locally: https://github.com/niklasha/env_logger/tree/issue-208-pipe-fix This is basically just making the uncolored case be used always with Pipe, be it in testing context or not. I know there is already a rejected proposal, but i thought I’d at least share what I did, should anyone like it.
I’ve published version 0.9.1 that deprecates
Target::Pipebecause nobody is working on fixing it.@walkie I thinks that color output should be disabled be default, but I think it still is an important feature, for example I use the color output to combine the indicatif progress bar and pretty env logger in https://gitlab.com/TilCreator/rustycomicscraper/-/blob/master/src/main.rs
Heh, I too burnt hours debugging this, and made a fix of my own before checking the issues. This really ought to be fixed, either by correcting the bug (easy enough), or… if it is easier, just by releasing a new version with fixed documentation (where it is noted that Pipe does not work unless in test context). If it is documented as working, people will continue to trip on this.
Yeah, I suppose some docs plus a
deprecatedattribute (because that is the only way you can make usage of it warn, AFAIK) would be a good interim solution. There has been no progress on #217, help wanted.Ups, it has been a few days… Sry, I opened #211 which fixes this (but it’s not perfect).