-
Notifications
You must be signed in to change notification settings - Fork 3
/
LogMsg.hs
87 lines (73 loc) · 2 KB
/
LogMsg.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
module LogMsg (initLog,
FacilityString, LevelString, LogSystem(..),
errorMsg, warnMsg, noticeMsg,
infoMsg, debugMsg) where
import Data.Maybe
import System.Log.Handler.Syslog
import System.Log.Logger
errorMsg :: String -> IO ()
errorMsg = errorM rootLoggerName
warnMsg :: String -> IO ()
warnMsg = warningM rootLoggerName
noticeMsg :: String -> IO ()
noticeMsg = noticeM rootLoggerName
infoMsg :: String -> IO ()
infoMsg = infoM rootLoggerName
debugMsg :: String -> IO ()
debugMsg = debugM rootLoggerName
type FacilityString = String
type LevelString = String
data LogSystem = StdErr | SysLog
initLog :: String
-> FacilityString
-> LevelString
-> LogSystem
-> IO ()
initLog name fcl lvl SysLog = do
let level = toLevel lvl
facility = toFacility fcl
s <- openlog name [PID] facility level
updateGlobalLogger rootLoggerName (setLevel level . setHandlers [s])
initLog _ _ lvl StdErr = do
let level = toLevel lvl
updateGlobalLogger rootLoggerName (setLevel level)
toLevel :: String -> Priority
toLevel str = fromMaybe (error ("Unknown level " ++ show str))
(lookup str levelDB)
toFacility :: String -> Facility
toFacility str = fromMaybe (error ("Unknown facility " ++ show str))
(lookup str facilityDB)
levelDB :: [(String, Priority)]
levelDB = [
("debug",DEBUG)
, ("info",INFO)
, ("notice",NOTICE)
, ("warning",WARNING)
, ("error",ERROR)
, ("critical",CRITICAL)
, ("alert",ALERT)
, ("emergency",EMERGENCY)
]
facilityDB :: [(String, Facility)]
facilityDB = [
("kern",KERN)
, ("use",USER)
, ("mail",MAIL)
, ("daemon",DAEMON)
, ("auth",AUTH)
, ("syslog",SYSLOG)
, ("lpr",LPR)
, ("news",NEWS)
, ("uucp",UUCP)
, ("cron",CRON)
, ("authpriv",AUTHPRIV)
, ("ftp",FTP)
, ("local0",LOCAL0)
, ("local1",LOCAL1)
, ("local2",LOCAL2)
, ("local3",LOCAL3)
, ("local4",LOCAL4)
, ("local5",LOCAL5)
, ("local6",LOCAL6)
, ("local7",LOCAL7)
]