Open dschrempf opened 5 years ago
Hello @dschrempf I'm also interested to logging out to multiple destinations + timestamps, did you managed to do that? any pointers?
Hi Julio,
what I do now is define a custom logging transformer that logs to two handles. Super annoying, but it works. Here is the code (ELynx is the package name, which is irrelevant here):
runELynxFileLoggingT :: MonadBaseControl IO m => FilePath -> LoggingT m a -> m a
runELynxFileLoggingT fp logger = bracket
(liftBase $ openFile fp AppendMode)
(liftBase . hClose)
$ \h -> liftBase (hSetBuffering h LineBuffering) >> runLoggingT logger (output2H stderr h)
output2H :: Handle
-> Handle
-> Loc
-> LogSource
-> LogLevel
-> LogStr
-> IO ()
output2H h1 h2 loc src lvl msg = do
B.hPutStr h1 ls
B.hPutStr h2 ls
where
ls = logStrToBS loc src lvl msg
logStrToBS :: Loc
-> LogSource
-> LogLevel
-> LogStr
-> B.ByteString
logStrToBS _ _ _ msg = fromLogStr msg <> "\n"
I hope I could help!
Dominik
Julio César notifications@github.com writes:
Hello @dschrempf I'm also interested to logging out to multiple destinations + timestamps, did you managed to do that? any pointers?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
I would like to use the
monad-logger
framework but find it very difficult to change the format of log messages.I managed to write my own
runFileLoggingT
function, which uses not thedefaultOutput
function, but a custom function preparing the output. The rewrite, however, requires considerable effort and is by no means user-friendly. For example, I had to tinker around withMonadBaseControl
.Further, is it possible to use time stamps in my log messaes without writing my own
runFileLoggingT
?Do you think it is possible to provide an easier way to format the log messages? It may well be that I missed how
monad-logger
should be used. In this case, it would be good to provide some more documentation.Thank you for your help!
Edit: I also wanted to log to stderr and a file at the same time. Does it also require a custom runLoggingT implementation?