[Haskell-beginners] hslogger question [Solved]
Manfred Lotz
manfred.lotz at arcor.de
Sun Aug 7 09:32:22 CEST 2011
On Sat, 6 Aug 2011 21:43:17 +0200
Manfred Lotz <manfred.lotz at arcor.de> wrote:
> Hi there,
> Using hslogger I want to get
> - error messages and above to stdout and to logfile
> - debug messages and above to logfile only.
>
>
It seems the stderr handler must be redefined.
Solved now by coding like this:
import System.IO
import System.Log.Logger
import System.Log.Handler.Simple
import System.Log.Handler (setFormatter)
import System.Log.Formatter
-- By default, all messages of level WARNING and above are sent to
stderr. -- Everything else is ignored.
main :: IO ()
main = do
-- set global level to DEBUG
updateGlobalLogger rootLoggerName (setLevel DEBUG)
-- want only ERROR and above to stderr
s <- streamHandler stderr ERROR
-- want all log messages to logfile
h <- fileHandler "debug.log" DEBUG >>= \lh -> return $
setFormatter lh (simpleLogFormatter "[$time :
$loggername : $prio] $msg")
-- set handlers completely new
updateGlobalLogger rootLoggerName (setHandlers [s,h])
errorM "MyApp.Init" "This is a bad error"
-- This message will go to logfile only.
debugM "MyApp.Main" "This buggy component is buggy"
-- This message will go to logfile only.
warningM "MyApp.Finish" "Still Buggy"
--
Manfred
More information about the Beginners
mailing list