blob: 5091b23ecab96f781b755d6cc254df77f6a2fba8 (
plain)
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
|
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Com.MusicMeetsComics.Server.Logger
( adapt
, defaultLogEnv
, Katip.logMsg
, Katip.runKatipT
, Katip.KatipT(..)
, Katip.Katip(..)
, Katip.LogEnv
, Katip.Severity(..)
)
where
import qualified Control.Monad.Logger as Logger
import qualified Katip
import Protolude
import qualified System.IO as IO
import qualified System.Log.FastLogger as FastLogger
defaultLogEnv :: IO Katip.LogEnv
defaultLogEnv = do
handleScribe <- Katip.mkHandleScribe Katip.ColorIfTerminal
IO.stdout
(Katip.permitItem Katip.DebugS)
Katip.V2
env <- Katip.initLogEnv "hero" "production"
Katip.registerScribe "stdout" handleScribe Katip.defaultScribeSettings env
fromLevel :: Logger.LogLevel -> Katip.Severity
fromLevel Logger.LevelDebug = Katip.DebugS
fromLevel Logger.LevelInfo = Katip.InfoS
fromLevel Logger.LevelWarn = Katip.WarningS
fromLevel Logger.LevelError = Katip.ErrorS
fromLevel (Logger.LevelOther _) = Katip.NoticeS
-- | Transforms Katip logMsg into monadLoggerLog to be used inside
-- MonadLogger monad
adapt
:: (FastLogger.ToLogStr msg, Applicative m, Katip.Katip m)
=> (Katip.Namespace -> Katip.Severity -> Katip.LogStr -> m ())
-> Logger.Loc
-> Logger.LogSource
-> Logger.LogLevel
-> msg
-> m ()
adapt f _ src lvl msg = f ns (fromLevel lvl) $ logStr' msg
where
ns = Katip.Namespace [src]
-- not sure how fast this is going to be
logStr' = Katip.logStr . FastLogger.fromLogStr . Logger.toLogStr
|