Skip to content

Commit a8bc20d

Browse files
committed
Map some messages
Signed-off-by: Sasha Bogicevic <[email protected]>
1 parent e6a0ac3 commit a8bc20d

File tree

1 file changed

+50
-8
lines changed
  • hydra-node/exe/visualize-logs

1 file changed

+50
-8
lines changed

hydra-node/exe/visualize-logs/Main.hs

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,30 @@ module Main where
55

66
import Hydra.Cardano.Api
77
import Hydra.Prelude hiding (encodeUtf8)
8+
import Hydra.Prelude qualified as P
89

910
import Conduit
1011
import Control.Lens ((^?))
1112
import Data.Aeson (eitherDecode')
1213
import Data.Aeson.Lens (key, _String)
1314
import Data.ByteString.Lazy.Char8 qualified as C8
15+
import Data.Text qualified as T
1416
import Data.Text.Encoding (encodeUtf8)
17+
import GHC.Show (show)
18+
import Hydra.Chain (ChainEvent (..))
19+
import Hydra.HeadLogic (Effect (..), Input (..), Outcome (..))
1520
import Hydra.Logging (Envelope (..))
1621
import Hydra.Logging.Messages (HydraLog (..))
22+
import Hydra.Node (HydraNodeLog (..))
1723

18-
newtype Decoded tx
24+
data Decoded tx
1925
= DecodedHydraLog Text
20-
deriving newtype (Show)
26+
| DropLog
27+
deriving (Eq)
28+
29+
instance Show (Decoded tx) where
30+
show (DecodedHydraLog txt) = T.unpack txt
31+
show DropLog = ""
2132

2233
main :: IO ()
2334
main = do
@@ -28,20 +39,51 @@ main = do
2839
.| mapMC
2940
( \l ->
3041
case l ^? key "message" . _String of
31-
Nothing -> error "Failed to find key 'message' which was expected"
42+
Nothing -> P.error "Failed to find key 'message' which was expected"
3243
Just line ->
3344
let envelope = fromStrict $ encodeUtf8 line
3445
in case decodeAs envelope (undefined :: Envelope (HydraLog Tx)) of
35-
Left e -> error $ show e <> line
46+
Left e -> P.error $ P.show e <> line
3647
Right decoded ->
3748
case decoded.message of
38-
NodeOptions opt -> pure $ DecodedHydraLog $ "NODE STARTING: " <> show opt
39-
Node msg -> pure $ DecodedHydraLog $ "NODE LOG: " <> show msg
40-
_ -> pure $ DecodedHydraLog "_____"
49+
NodeOptions opt -> pure $ DecodedHydraLog $ "NODE STARTING: \n" <> P.show opt
50+
Node msg ->
51+
case msg of
52+
BeginInput{input} ->
53+
case input of
54+
ClientInput{clientInput} ->
55+
pure $ DecodedHydraLog $ "NODE LOG: \n" <> P.show clientInput
56+
NetworkInput{} -> pure DropLog
57+
ChainInput{chainEvent} ->
58+
case chainEvent of
59+
Observation{observedTx} -> pure $ DecodedHydraLog $ "OBESERVATION: " <> P.show observedTx
60+
Rollback{} -> pure DropLog
61+
Tick{} -> pure DropLog
62+
PostTxError{postTxError} ->
63+
pure $ DecodedHydraLog $ "ERROR: " <> P.show postTxError
64+
EndInput{} -> pure DropLog
65+
BeginEffect{effect} ->
66+
case effect of
67+
ClientEffect{} -> pure DropLog
68+
NetworkEffect{message} -> pure $ DecodedHydraLog $ P.show message
69+
OnChainEffect{postChainTx} -> pure $ DecodedHydraLog $ "POSTING: " <> P.show postChainTx
70+
EndEffect{} -> pure DropLog
71+
LogicOutcome{outcome} ->
72+
case outcome of
73+
Continue{} -> pure DropLog
74+
Wait{} -> pure DropLog
75+
Error{error = err} -> pure $ DecodedHydraLog $ "LOGIC ERROR: " <> P.show err
76+
DroppedFromQueue{} -> pure DropLog
77+
LoadingState -> pure $ DecodedHydraLog "Loading state..."
78+
LoadedState{} -> pure $ DecodedHydraLog "Loaded."
79+
ReplayingState -> pure $ DecodedHydraLog "Replaying state..."
80+
Misconfiguration{} -> pure $ DecodedHydraLog "MISCONFIG!"
81+
_ -> pure DropLog
4182
)
83+
.| filterC (\a -> P.show a /= ("" :: Text))
4284
.| sinkList
4385
forM_ decodedLines $ \l ->
44-
putTextLn (show l)
86+
putTextLn (P.show l)
4587

4688
decodeAs :: forall a. FromJSON a => C8.ByteString -> a -> Either String a
4789
decodeAs l _ =

0 commit comments

Comments
 (0)