log_warning )
where
-import System.Log.Handler.Simple ( GenericHandler )
+import System.Log.Handler.Simple ( fileHandler )
+import System.Log.Handler.Syslog (
+ Facility ( USER ),
+ Option ( PID ),
+ openlog )
import System.Log.Logger (
Priority ( DEBUG, INFO ),
debugM,
log_warning :: String -> IO ()
log_warning = warningM rootLoggerName
-init_logging :: Bool -> IO ()
-init_logging use_syslog = do
- let max_level = if use_syslog then INFO else DEBUG
- -- We need to specify the type here; otherwise, setHandlers won't
- -- accept the empty list as an instance of [LogHandler a].
- let no_handlers = [] :: [GenericHandler a]
- -- Removes the default "echo to stdout" handler.
- updateGlobalLogger rootLoggerName (setLevel max_level
- . setHandlers no_handlers)
+init_logging :: FilePath -> Priority -> Bool -> IO ()
+init_logging log_file log_level syslog
+ | syslog == True = do
+ handler <- openlog rootLoggerName [PID] USER level
+ updateGlobalLogger rootLoggerName (setLevel level . setHandlers [handler])
+ | otherwise = do
+ handler <- fileHandler log_file level
+ updateGlobalLogger rootLoggerName (setLevel level . setHandlers [handler])
+ where
+ min_level = if syslog then INFO else DEBUG
+ level = if log_level < min_level then min_level else log_level
-- logging before the missing parameter checks below so that we can
-- log the errors.
let cfg = (def :: Configuration) `merge_optional` opt_config
- init_logging (syslog cfg)
+ init_logging (log_file cfg) (log_level cfg) (syslog cfg)
-- Check the optional config for missing required options. This is
-- necessary because if the user specifies an empty list of