ocharles/logging-effect

Logs are discarded when stdout is a pipe

Closed this issue · 7 comments

I'm using nosh (a daemontools derivative) as a process supervisor and stdout is piped to a logging process. This causes all logs to be discarded.

As a simple test I simply piped my program through cat and logs are, again, discarded. Being a pedant I even double checked with strace! When stdout is a tty I see: write(1, "...") ... but when stdout is a pipe nothing is written to file descriptor 1.

I can understand interactive programs discarding output when stdout is a pipe but surely not a logging library!

Could you provide me with a minimal example to reproduce this problem?

Yeah, I will do. I'm still trying to work out what's actually going on; sometimes it works and others not. I'll try and get an example together soon.

Ok, I created a repo and have written up what I think is going on in the README.

In short I don't think this is a bug but an interaction with stdout buffering. I'm not sure what the best answer is but it might be worth at least documenting that this can happen.

I was thinking that the library could set stdout and stderr's buffer options to LineBuffering but that goes against the grain of what batching is doing. Maybe it should be set when not using the batching (I haven't tested whether this shows the same behaviour).

@filterfish I have pushed what I think is a fix for this problem to the master branch - could you try that and see if it does indeed fix the problem?

Works like a charm! Thanks for fixing it.

Wonderful, I've now released that as 1.2.0 on Hackage. It's a major bump as this is an observable change.