I have a few forked processes that log in a channel and another one that uses unChanLoggingT + runFileLoggingT to put all of them in one file - but this does not work, neither a file is created nor any lines are added to the (non-existent) file.
I think this is an issue with buffering/flushing - looking at the source code Logger.hs#L661
runFileLoggingT :: MonadBaseControl IO m => FilePath -> LoggingT m a -> m a
runFileLoggingT fp log = bracket
(liftBase $ openFile fp AppendMode)
(liftBase . hClose)
$ \h -> (runLoggingT log) (defaultOutput h)
should be (with the additional import System.IO (BufferMode(LineBuffering), hSetBuffering))
runFileLoggingT :: MonadBaseControl IO m => FilePath -> LoggingT m a -> m a
runFileLoggingT fp log = bracket
(liftBase $ openFile fp AppendMode)
(liftBase . hClose)
$ \h -> hSetBuffering LineBuffering h >> (runLoggingT log) (defaultOutput h)
or configurable -
runFileLoggingT :: MonadBaseControl IO m => FilePath -> BufferMode -> LoggingT m a -> m a
runFileLoggingT fp bm log = bracket
(liftBase $ openFile fp AppendMode)
(liftBase . hClose)
$ \h -> hSetBuffering bm h >> (runLoggingT log) (defaultOutput h)
I have a few forked processes that log in a channel and another one that uses unChanLoggingT + runFileLoggingT to put all of them in one file - but this does not work, neither a file is created nor any lines are added to the (non-existent) file.
I think this is an issue with buffering/flushing - looking at the source code Logger.hs#L661
should be (with the additional
import System.IO (BufferMode(LineBuffering), hSetBuffering)
)or configurable -