@@ -1,5 +1,6 @@
1{-# LANGUAGE DeriveGeneric #-}
1{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE FlexibleContexts #-}
3+{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4{-# LANGUAGE MultiParamTypeClasses #-}
5{-# LANGUAGE MultiParamTypeClasses #-}
5{-# LANGUAGE OverloadedStrings #-}
6{-# LANGUAGE OverloadedStrings #-}
@@ -14,8 +15,15 @@ import Control.Applicative
14import Control.AutoUpdate
15import Control.AutoUpdate
15import Control.Concurrent
16import Control.Concurrent
16import Control.Lens
17import Control.Lens
17import Control.Monad.Catch
19import Control.Monad.Catch
18−import Control.Monad.Reader
20+import Control.Monad.IO.Class
21+import Control.Monad.Trans.Class
22+import Control.Monad.Trans.Either
23+import Control.Monad.Trans.Maybe
24+import Control.Monad.Trans.Reader
25+import Control.Monad.Trans.State
26+import Control.Monad.Trans.Writer
19import Data.Aeson (ToJSON (..))
27import Data.Aeson (ToJSON (..))
20import qualified Data.Aeson as A
28import qualified Data.Aeson as A
21import Data.Aeson.Lens
29import Data.Aeson.Lens
@@ -59,14 +67,14 @@ newtype Environment = Environment { getEnvironment :: Text }
60-------------------------------------------------------------------------------
68-------------------------------------------------------------------------------
61data Severity
69data Severity
62− = Debug -- ^ Debug messages
70+ = DebugS -- ^ Debug messages
63− | Info -- ^ Information
71+ | InfoS -- ^ Information
64− | Notice -- ^ Normal runtime Conditions
72+ | NoticeS -- ^ Normal runtime Conditions
65− | Warning -- ^ General Warnings
73+ | WarningS -- ^ General Warnings
66− | Error -- ^ General Errors
74+ | ErrorS -- ^ General Errors
67− | Critical -- ^ Severe situations
75+ | CriticalS -- ^ Severe situations
68− | Alert -- ^ Take immediate action
76+ | AlertS -- ^ Take immediate action
69− | Emergency -- ^ System is unusable
77+ | EmergencyS -- ^ System is unusable
70 deriving (Eq, Ord, Show, Read, Generic)
78 deriving (Eq, Ord, Show, Read, Generic)
@@ -85,14 +93,14 @@ data Verbosity = V0 | V1 | V2 | V3
85-------------------------------------------------------------------------------
93-------------------------------------------------------------------------------
86renderSeverity :: Severity -> Text
94renderSeverity :: Severity -> Text
87renderSeverity s = case s of
95renderSeverity s = case s of
88− Debug -> "Debug"
96+ DebugS -> "Debug"
89− Info -> "Info"
97+ InfoS -> "Info"
90− Notice -> "Notice"
98+ NoticeS -> "Notice"
91− Warning -> "Warning"
99+ WarningS -> "Warning"
92− Error -> "Error"
100+ ErrorS -> "Error"
93− Critical -> "Critical"
101+ CriticalS -> "Critical"
94− Alert -> "Alert"
102+ AlertS -> "Alert"
95− Emergency -> "Emergency"
103+ EmergencyS -> "Emergency"
98-------------------------------------------------------------------------------
106-------------------------------------------------------------------------------
@@ -108,6 +116,9 @@ newtype LogStr = LogStr { unLogStr :: B.Builder }
108instance IsString LogStr where
116instance IsString LogStr where
109 fromString = LogStr . B.fromString
117 fromString = LogStr . B.fromString
119+instance Monoid LogStr where
120+ mappend (LogStr a) (LogStr b) = LogStr (a `mappend` b)
121+ mempty = LogStr mempty
112-------------------------------------------------------------------------------
123-------------------------------------------------------------------------------
113-- | Pack any string-like thing into a 'LogMsg'. This will
124-- | Pack any string-like thing into a 'LogMsg'. This will
@@ -123,6 +134,11 @@ ls :: StringConv a Text => a -> LogStr
123ls = logStr
134ls = logStr
137+-------------------------------------------------------------------------------
138+showLS :: Show a => a -> LogStr
126-------------------------------------------------------------------------------
142-------------------------------------------------------------------------------
127-- | This has everything each log message will contain.
143-- | This has everything each log message will contain.
128data Item a = Item {
144data Item a = Item {
@@ -263,11 +279,35 @@ class MonadIO m => Katip m where
263 getLogEnv :: m LogEnv
279 getLogEnv :: m LogEnv
282+instance Katip m => Katip (ReaderT s m) where
283+ getLogEnv = lift getLogEnv
286+instance Katip m => Katip (EitherT s m) where
287+ getLogEnv = lift getLogEnv
290+instance Katip m => Katip (MaybeT m) where
291+ getLogEnv = lift getLogEnv
294+instance Katip m => Katip (StateT s m) where
295+ getLogEnv = lift getLogEnv
298+instance (Katip m, Monoid s) => Katip (WriterT s m) where
299+ getLogEnv = lift getLogEnv
266-------------------------------------------------------------------------------
302-------------------------------------------------------------------------------
267-- | A concrete monad you can use to run logging actions.
303-- | A concrete monad you can use to run logging actions.
268newtype KatipT m a = KatipT { unKatipT :: ReaderT LogEnv m a }
304newtype KatipT m a = KatipT { unKatipT :: ReaderT LogEnv m a }
305+ deriving ( Functor, Applicative, Monad, MonadIO
269− deriving ( Monad, MonadIO, MonadMask, MonadCatch, MonadThrow
306+ , MonadMask, MonadCatch, MonadThrow )
270− , MonadReader LogEnv)
307+
309+instance MonadIO m => Katip (KatipT m) where
310+ getLogEnv = KatipT ask
273-------------------------------------------------------------------------------
313-------------------------------------------------------------------------------
@@ -345,14 +385,14 @@ instance TH.Lift Verbosity where
347instance TH.Lift Severity where
387instance TH.Lift Severity where
348− lift Debug = [| Debug |]
388+ lift DebugS = [| DebugS |]
349− lift Info = [| Info |]
389+ lift InfoS = [| InfoS |]
350− lift Notice = [| Notice |]
390+ lift NoticeS = [| NoticeS |]
351− lift Warning = [| Warning |]
391+ lift WarningS = [| WarningS |]
352− lift Error = [| Error |]
392+ lift ErrorS = [| ErrorS |]
353− lift Critical = [| Critical |]
393+ lift CriticalS = [| CriticalS |]
354− lift Alert = [| Alert |]
394+ lift AlertS = [| AlertS |]
355− lift Emergency = [| Emergency |]
395+ lift EmergencyS = [| EmergencyS |]
358-- | Lift a location into an Exp.
398-- | Lift a location into an Exp.