kazu-yamamoto / logger

A fast logging system for Haskell
159 stars 68 forks source link

withFastLogger should flush on exit #124

Closed andrewthad closed 7 years ago

andrewthad commented 7 years ago

I have an application that looks like this:

main :: IO ()
main = withFastLogger (LogStdOut 4096) program

program :: (FL.LogStr -> IO ()) -> IO ()
program putLog = ...

However, the program terminates without all logs getting flushed to stdout. I think that a better behavior for withFastLogger would be to flush when it terminates. I can implement this without changing the existing api. Here is my plan: add an unexported function newFastLoggerInternal that returns a triple that includes the LoggerSet. This function would basically have the same implementation as newFastLogger currently does. Then, reimplement newFastLogger to simply call this function and discard the LoggerSet. Then, reimplement withFastLogger to call this new function and flush on exit. I would adjust the logger functions that provide timestamps as well. Let me know if this is acceptable, and I can PR it.

kazu-yamamoto commented 7 years ago

Yes. Please send me a PR.

andrewthad commented 7 years ago

I tried replicating the problem in a smaller project, and I can't. Browsing the source code, it actually looks like withFastLogger should already be triggering a flush because it calls rmLoggerSet at the end. I'm going to close this because I suspect that my larger project actually has something else wrong with it.