Skip to content

Conversation

@TotallyNotChase
Copy link
Collaborator

I'm unsure where to get a Prettyprinter instance for Data.Aeson.Value so I instantiated it inline. It should definitely be replaced by some "official" instance or moved to a separate module. Let me know what to do about that.


-- | Version of "Control.Monad.Freer.Extras.handleLogTrace" that takes into account the log level setting.
handleLogTrace' :: Pretty a => LogLevel -> Eff (LogMsg a ': effs) ~> Eff effs
handleLogTrace' logLevelSetting = interpret $ \case
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a way of disserning contract logs to BPI logs? perhaps a prefix or something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should both type of logs get a prefix?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be noted that while BPI logs look more or less like "bare" strings. Contract logs have the log level prepended as a prefix, e.g [INFO] Minted value: .....

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats a fair point, it would actually be nice to have those log level prefixes on the BPI logs, then something else for separating between the two

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some refactoring that should enable all of this. Added a LogContext.

LMessage msg ->
if logLevelSetting >= toNativeLogLevel (msg ^. Freer.logLevel)
then Trace.trace (Render.renderString . layoutPretty defaultLayoutOptions . pretty $ msg) $ pure ()
else pure ()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use when here

handleLogTrace' logLevelSetting = interpret $ \case
LMessage msg ->
if logLevelSetting >= toNativeLogLevel (msg ^. Freer.logLevel)
then Trace.trace (Render.renderString . layoutPretty defaultLayoutOptions . pretty $ msg) $ pure ()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging with trace seems hacky - especially since PABEffect already has a logging effect, could we instead of handling this effect, reinterpret it in some way to PABEffect and use that code (which does direct putStrLns in IO)
Alternatively, we can add the LastMember constraint on this, and lift to that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I just got lazy and decided to use the IOG handleLogTrace. I changed this to reinterpret the effect to use PABEffect later down the line.

import Cardano.Api qualified
import Control.Concurrent qualified as Concurrent
import Control.Concurrent.STM (atomically, modifyTVar, modifyTVar')
import Control.Lens
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets use explicit imports

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, fixed

import Plutus.Contract.Effects (ChainIndexQuery, ChainIndexResponse)
import Plutus.PAB.Core.ContractInstance.STM (Activity)
import PlutusTx.Builtins.Internal (BuiltinByteString (BuiltinByteString))
import Prettyprinter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imports

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

import Plutus.Contract.Resumable (Resumable (..))
import Plutus.Contract.Types (Contract (..), ContractEffs)
import PlutusTx.Builtins (fromBuiltin)
import Prettyprinter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicit imports

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@samuelWilliams99
Copy link
Contributor

CI isn't running, guessing that because you're running a fork? can you verify it passes build, formatting and lint?

@TotallyNotChase
Copy link
Collaborator Author

CI isn't running, guessing that because you're running a fork? can you verify it passes build, formatting and lint?

cabal build all succeeds; make format_check and make lint also give out no formatting changes/lints

I was unable to run tests due to the missing machinery.

@samuelWilliams99 samuelWilliams99 changed the base branch from master to chase/trace-logs May 30, 2022 14:04
@samuelWilliams99 samuelWilliams99 merged commit 720128a into mlabs-haskell:chase/trace-logs May 30, 2022
@samuelWilliams99
Copy link
Contributor

I've merged this to chase/trace-logs under BPI, created this PR to get it to master, with CI
#107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants