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

Most upvoted comments

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::Pipe because 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 deprecated attribute (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).