log_warning )
where
+import System.Log.Formatter ( simpleLogFormatter )
+import System.Log.Handler ( setFormatter )
import System.Log.Handler.Simple ( fileHandler )
import System.Log.Handler.Syslog (
Facility ( USER ),
- Option ( PID ),
openlog )
import System.Log.Logger (
Priority ( DEBUG, INFO ),
updateGlobalLogger,
warningM )
+
log_debug :: String -> IO ()
log_debug = debugM rootLoggerName
log_warning :: String -> IO ()
log_warning = warningM rootLoggerName
+
+-- | Why don't we take a Configuration as an argument? Because it
+-- would create circular imports!
init_logging :: FilePath -> Priority -> Bool -> IO ()
init_logging log_file log_level syslog
| syslog == True = do
- handler <- openlog rootLoggerName [PID] USER level
+ handler' <- openlog rootLoggerName [] USER level
+ -- Syslog should output the date by itself.
+ let slf = simpleLogFormatter "htsn[$pid] $prio: $msg"
+ let handler = setFormatter handler' slf
updateGlobalLogger rootLoggerName (setLevel level . setHandlers [handler])
| otherwise = do
- handler <- fileHandler log_file level
+ handler' <- fileHandler log_file level
+ let slf = simpleLogFormatter "$time: htsn[$pid] $prio: $msg"
+ let handler = setFormatter handler' slf
updateGlobalLogger rootLoggerName (setLevel level . setHandlers [handler])
where
min_level = if syslog then INFO else DEBUG
connect_and_loop :: Configuration -> String -> IO ()
connect_and_loop cfg host = do
- report_info $ "Connecting to " ++ host ++ "..."
+ report_info $ "Connecting to " ++ host ++ "."
bracket acquire_handle release_handle action
return ()
where