
Hi there, Using hslogger I want to get - error messages and above to stdout and to logfile - debug messages and above to logfile only. Here is what I tried: 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 -- all messages of level ERROR and above to stderr. updateGlobalLogger rootLoggerName (setLevel ERROR) h <- fileHandler "debug.log" DEBUG >>= \lh -> return $ setFormatter lh (simpleLogFormatter "[$time : $loggername : $prio] $msg") updateGlobalLogger rootLoggerName (addHandler 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" errorM goes to stderr and logfile as expected. However, debugM and warningM are not to be seen at all. What am I doing wrong? -- Manfred

On Sat, 6 Aug 2011 21:43:17 +0200
Manfred Lotz
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
participants (1)
-
Manfred Lotz