haskell-hvr / hslogger

Logging framework for Haskell
https://hackage.haskell.org/package/hslogger
BSD 3-Clause "New" or "Revised" License
64 stars 36 forks source link

Enable by-line buffering for stderr #33

Open k-bx opened 9 years ago

k-bx commented 9 years ago

It turned out that GHC by default does "no buffering" for stderr, and for hslogger this might be a huge performance-bottleneck.

Here's an example of a script that confirms performance problems: https://gist.github.com/k-bx/ccf6fd1c73680c8a4345 (please, don't pay any attention to "timeout" thing, initiall I thought the problem lies in concurrent usage of hslogger).

In order to resolve problem, you can either manually put hSetBuffering stderr LineBuffering in your program, or disable logging to stderr at all.

I think that hslogger should do its best in order to not put a person into a situation when logging consumes huge amount of time, and I would propose to somehow determine that user is willing to use logging to stderr and in that case doing hSetBuffering stderr LineBuffering in order to switch buffering to LineBuffering mode.

jgoerzen commented 8 years ago

I would be open to documenting this. However, I do not think that hslogger changing the behavior of stderr is a desired side-effect. The user could easily enough do that themselves if that's what they want.

anacrolix commented 6 years ago

I've just run into this problem too. Stumbled on to this issue with some googling. I am getting log messages interleaved character for character when logging to stderr. I'll try hSetBuffering stderr LineBuffering.