@@ -14,7 +14,7 @@ module BotPlutusInterface.Effects (
1414 uploadDir ,
1515 updateInstanceState ,
1616 printLog ,
17- handleLogTrace' ,
17+ handleContractLog ,
1818 logToContract ,
1919 readFileTextEnvelope ,
2020 writeFileJSON ,
@@ -41,9 +41,9 @@ import Cardano.Api (AsType, FileError (FileIOError), HasTextEnvelope, TextEnvelo
4141import Cardano.Api qualified
4242import Control.Concurrent qualified as Concurrent
4343import Control.Concurrent.STM (atomically , modifyTVar , modifyTVar' )
44- import Control.Lens
44+ import Control.Lens ( (^.) )
4545import Control.Monad (void , when )
46- import Control.Monad.Freer (Eff , LastMember , Member , interpret , interpretM , send , type (~> ))
46+ import Control.Monad.Freer (Eff , LastMember , Member , interpretM , reinterpret , send , subsume , type (~> ))
4747import Control.Monad.Freer.Extras (LogMsg (LMessage ))
4848import Control.Monad.Freer.Extras qualified as Freer
4949import Control.Monad.Trans.Except.Extra (handleIOExceptT , runExceptT )
@@ -56,12 +56,11 @@ import Data.Maybe (catMaybes)
5656import Data.String (IsString , fromString )
5757import Data.Text (Text )
5858import Data.Text qualified as Text
59- import Debug.Trace qualified as Trace
6059import Ledger qualified
6160import Plutus.Contract.Effects (ChainIndexQuery , ChainIndexResponse )
6261import Plutus.PAB.Core.ContractInstance.STM (Activity )
6362import PlutusTx.Builtins.Internal (BuiltinByteString (BuiltinByteString ))
64- import Prettyprinter
63+ import Prettyprinter ( Pretty ( pretty ), defaultLayoutOptions , layoutPretty )
6564import Prettyprinter.Render.String qualified as Render
6665import System.Directory qualified as Directory
6766import System.Exit (ExitCode (ExitFailure , ExitSuccess ))
@@ -159,13 +158,16 @@ printLog' :: LogLevel -> LogLevel -> String -> IO ()
159158printLog' logLevelSetting msgLogLvl msg =
160159 when (logLevelSetting >= msgLogLvl) $ putStrLn msg
161160
162- -- | Version of "Control.Monad.Freer.Extras.handleLogTrace" that takes into account the log level setting.
163- handleLogTrace' :: Pretty a => LogLevel -> Eff (LogMsg a ': effs ) ~> Eff effs
164- handleLogTrace' logLevelSetting = interpret $ \ case
161+ -- | Reinterpret contract logs to be handled by PABEffect later down the line.
162+ handleContractLog :: forall w a effs . Member (PABEffect w ) effs => Pretty a => Eff (LogMsg a ': effs ) ~> Eff effs
163+ handleContractLog x = subsume $ handleContractLogInternal @ w x
164+
165+ handleContractLogInternal :: forall w a effs . Pretty a => Eff (LogMsg a ': effs ) ~> Eff (PABEffect w ': effs )
166+ handleContractLogInternal = reinterpret $ \ case
165167 LMessage msg ->
166- if logLevelSetting > = toNativeLogLevel (msg ^. Freer. logLevel)
167- then Trace. trace ( Render. renderString . layoutPretty defaultLayoutOptions . pretty $ msg) $ pure ()
168- else pure ()
168+ let msgLogLevel = toNativeLogLevel (msg ^. Freer. logLevel)
169+ msgPretty = Render. renderString . layoutPretty defaultLayoutOptions . pretty $ msg
170+ in printLog @ w msgLogLevel msgPretty
169171 where
170172 toNativeLogLevel Freer. Debug = Debug
171173 toNativeLogLevel Freer. Info = Info
0 commit comments