blob: cc6a1cc381c45d16789817a162e04e70bd50f11c [file] [log] [blame]
Matthias Andreas Benkard262110d2021-08-24 06:35:55 +02001{-# LANGUAGE RecordWildCards #-}
2
3module Mulkup.Logging where
4
5import Colog (Message, Msg (..), Severity (..))
6import Colog.Polysemy.Effect (Log, log)
7import Data.Text (pack)
8import Mulkup.Prelude
9import Polysemy (Member, Sem)
10
11msg :: Severity -> Text -> Message
12msg msgSeverity msgText = withFrozenCallStack (Msg {msgStack = callStack, ..})
13
14debugMsg :: Text -> Message
15debugMsg = withFrozenCallStack (msg Debug)
16
17infoMsg :: Text -> Message
18infoMsg = withFrozenCallStack (msg Info)
19
20warningMsg :: Text -> Message
21warningMsg = withFrozenCallStack (msg Warning)
22
23errorMsg :: Text -> Message
24errorMsg = withFrozenCallStack (msg Error)
25
26exceptionMsg :: Exception e => e -> Message
27exceptionMsg = withFrozenCallStack (msg Error . pack . displayException)
28
29logDebug :: Member (Log Message) r => Text -> Sem r ()
30logDebug = withFrozenCallStack (log . debugMsg)
31
32logInfo :: Member (Log Message) r => Text -> Sem r ()
33logInfo = withFrozenCallStack (log . infoMsg)
34
35logWarning :: Member (Log Message) r => Text -> Sem r ()
36logWarning = withFrozenCallStack (log . warningMsg)
37
38logError :: Member (Log Message) r => Text -> Sem r ()
39logError = withFrozenCallStack (log . errorMsg)
40
41logException :: Exception e => Member (Log Message) r => e -> Sem r ()
42logException = withFrozenCallStack (log . exceptionMsg)