-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.hs
executable file
·51 lines (44 loc) · 2.16 KB
/
Logger.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
module Turbinado.Environment.Logger where
import qualified System.Log.Logger as L
import qualified System.Log.Handler.Simple as S
import Control.Concurrent.MVar
import Control.Monad.State
import Control.Monad.Trans
import Turbinado.Environment.Types
import Config.Master
import Data.Dynamic
import Data.Maybe
import System.IO.Unsafe
import Turbinado.Utility.Data
addLoggerToEnvironment :: (HasEnvironment m) => m ()
addLoggerToEnvironment = do e <- getEnvironment
f <- liftIO $ S.fileHandler "log" logLevel
liftIO $ L.updateGlobalLogger "Turbinado" ( L.setLevel logLevel . L.setHandlers [f])
mv <- liftIO $ newMVar ()
setEnvironment $ e {getLoggerLock = Just mv}
takeLoggerLock :: (HasEnvironment m) => m ()
takeLoggerLock = do e <- getEnvironment
liftIO $ takeMVar (fromJust' "Logger: takeLoggerLock" $ getLoggerLock e)
putLoggerLock :: (HasEnvironment m) => m ()
putLoggerLock = do e <- getEnvironment
liftIO $ putMVar (fromJust' "Logger: putLoggerLock" $ getLoggerLock e) ()
wrapLoggerLock :: (HasEnvironment m) => (String -> IO ()) -> String -> m ()
wrapLoggerLock lf s = do takeLoggerLock
liftIO $ lf s
putLoggerLock
debugM :: (HasEnvironment m) => String -> m ()
debugM = wrapLoggerLock (L.logM "Turbinado" L.DEBUG)
infoM :: (HasEnvironment m) => String -> m ()
infoM = wrapLoggerLock (L.logM "Turbinado" L.INFO)
noticeM :: (HasEnvironment m) => String -> m ()
noticeM = wrapLoggerLock (L.logM "Turbinado" L.NOTICE)
warningM :: (HasEnvironment m) => String -> m ()
warningM = wrapLoggerLock (L.logM "Turbinado" L.WARNING)
errorM :: (HasEnvironment m) => String -> m ()
errorM = wrapLoggerLock (L.logM "Turbinado" L.ERROR)
criticalM :: (HasEnvironment m) => String -> m ()
criticalM = wrapLoggerLock (L.logM "Turbinado" L.CRITICAL)
alertM :: (HasEnvironment m) => String -> m ()
alertM = wrapLoggerLock (L.logM "Turbinado" L.ALERT)
emergencyM :: (HasEnvironment m) => String -> m ()
emergencyM = wrapLoggerLock (L.logM "Turbinado" L.EMERGENCY)