我不明白为什么hslogger在这段代码中调用infoM时没有写任何日志:
{-# LANGUAGE CPP #-}
-- hslogger
import System.Log.Logger ( Priority(INFO, WARNING), addHandler
, infoM, warningM, updateGlobalLogger
)
import System.Log.Handler.Simple (fileHandler)
#define INF
main :: IO ()
main = do
let logger = "main"
#ifdef INF
let fileName = "info.log"
h1 <- fileHandler fileName INFO
putStrLn "opened file1"
updateGlobalLogger logger $ addHandler h1
putStrLn "will write1"
infoM logger "writing 1"
putStrLn "did write1"
#else
let fileName = "warn.log"
h2 <- fileHandler fileName WARNING
putStrLn "opened file2"
updateGlobalLogger logger $ addHandler h2
putStrLn "will write2"
warningM logger "writing 2"
putStrLn "did write2"
#endif
编译并运行此代码时,info.log为空。但是,如果我注释掉或删除#define INF
,则warn.log包含“写入2”。这是为什么?
答案 0 :(得分:1)
如果我没记错,hslogger
中的默认日志级别为WARNING
,如果您想查看INFO
消息,则应将其设置为INFO
。
updateGlobalLogger logger $ setLevel INFO
答案 1 :(得分:0)
updateGlobalLogger rootLoggerName (setLevel INFO)