Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
123 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE NamedFieldPuns #-} | ||
{-# LANGUAGE MonoLocalBinds #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE UndecidableInstances #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# OPTIONS_GHC -fno-warn-orphans #-} | ||
-- | A 'Control.Monad.Logger.Logger' instance | ||
-- using the 'Control.Monad.Freer.Log.Log' effect | ||
module Plutus.SCB.MonadLoggerBridge( | ||
MonadLoggerMsg(..) | ||
) where | ||
|
||
import Control.Monad.Logger (MonadLogger(..), Loc, LogSource, LogLevel(..), LogStr, ToLogStr(..)) | ||
import Control.Monad.Freer | ||
import Control.Monad.Freer.Log (LogMsg(..), LogMessage(..)) | ||
import qualified Control.Monad.Freer.Log as L | ||
import Data.Text.Prettyprint.Doc (Pretty(..), (<+>), vsep, viaShow) | ||
|
||
data MonadLoggerMsg = | ||
MonadLoggerMsg | ||
{ mlmLocation :: Loc | ||
, mlmLogSource :: LogSource | ||
, mlmLogStr :: LogStr | ||
} | ||
|
||
instance Pretty MonadLoggerMsg where | ||
pretty MonadLoggerMsg{mlmLocation, mlmLogSource, mlmLogStr} = | ||
vsep | ||
[ "Location:" <+> viaShow mlmLocation | ||
, "Source:" <+> viaShow mlmLogSource | ||
, "Message:" <+> viaShow mlmLogStr | ||
] | ||
|
||
instance (Member (LogMsg MonadLoggerMsg) effs) => MonadLogger (Eff effs) where | ||
monadLoggerLog l ls ll msg = | ||
send | ||
$ LMessage | ||
$ LogMessage | ||
{ _logLevel = toLogLevel ll | ||
, _logMessageContent = | ||
MonadLoggerMsg | ||
{ mlmLocation = l | ||
, mlmLogSource = ls | ||
, mlmLogStr = toLogStr msg | ||
} | ||
} | ||
|
||
toLogLevel :: LogLevel -> L.LogLevel | ||
toLogLevel = \case | ||
LevelDebug -> L.Debug | ||
LevelInfo -> L.Info | ||
LevelWarn -> L.Warning | ||
LevelError -> L.Error | ||
LevelOther _ -> L.Info |