Open locallycompact opened 6 years ago
Better docs for this would definitely be a good thing. If we can come up with a solution, would you consider sending a doc PR?
I think what you're looking for is the Monoid
instance of LogFunc
itself:
withLogFunc options1 $ \lf1 -> withLogFunc options2 $ \lf2 ->
runRIO (lf1 <> lf2) ...
Does that work for you?
Happy to put together a PR. :) That certainly compiles but it doesn't seem to be writing to file. Here's what I have:
{-# LANGUAGE NoImplicitPrelude #-}
import RIO
import System.IO
main = do
configHandle <- openFile "foo.txt" WriteMode
logStdout <- logOptionsHandle stdout True
logFoo <- logOptionsHandle configHandle True
withLogFunc logStdout $ \lfs ->
withLogFunc logFoo $ \lfo ->
runRIO (lfs <> lfo) $
logInfo . displayShow $ "foo"
This touches foo.txt but leaves it empty, and similarly if I run with just logFoo. What could be wrong here?
I think it's a lack of flushing. Using withBinaryFile
instead seems to work:
{-# LANGUAGE NoImplicitPrelude #-}
import RIO
main = withBinaryFile "foo.txt" WriteMode $ \configHandle -> do
logStdout <- logOptionsHandle stdout True
logFoo <- logOptionsHandle configHandle True
withLogFunc logStdout $ \lfs ->
withLogFunc logFoo $ \lfo ->
runRIO (lfs <> lfo) $
logInfo . displayShow $ "foo"
Hi, I can't find anywhere in the documentation that covers writing out a log to both a file and to stdout. I expected to be able to do something like this:
which is obviously wrong as LogOptions isn't a monoid, but I can't see the actual way to do this.
Thanks