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