-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Format #10
Comments
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 <[email protected]> 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.
|
Thank you! I was about to go down this route but in the end I settled for Katip which has support out of the box for what I needed, timestamps are added by default and writting to multiple targets is done by defining scribes. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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. Therewrite, however, requires considerable effort and is by no means user-friendly.
For example, I had to tinker around with
MonadBaseControl
.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, itwould 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?
The text was updated successfully, but these errors were encountered: