|
1 | 1 | {-# LANGUAGE OverloadedRecordDot #-}
|
| 2 | +{-# OPTIONS_GHC -Wno-deprecations #-} |
2 | 3 |
|
3 | 4 | module Main where
|
4 | 5 |
|
5 | 6 | import Hydra.Cardano.Api
|
6 | 7 | import Hydra.Prelude hiding (encodeUtf8)
|
7 | 8 |
|
| 9 | +import Conduit |
8 | 10 | import Control.Lens ((^?))
|
9 | 11 | import Data.Aeson (eitherDecode')
|
10 | 12 | import Data.Aeson.Lens (key, _String)
|
11 | 13 | import Data.ByteString.Lazy.Char8 qualified as C8
|
12 | 14 | import Data.Text.Encoding (encodeUtf8)
|
13 | 15 | import Hydra.Logging (Envelope (..))
|
14 |
| -import Hydra.Logging.Messages (HydraLog) |
15 |
| -import Hydra.Node (HydraNodeLog) |
| 16 | +import Hydra.Logging.Messages (HydraLog (..)) |
16 | 17 |
|
17 |
| -data Decoded tx |
18 |
| - = DecodedHydraLog (HydraLog tx) |
19 |
| - | DecodedHydraNodeLog (HydraNodeLog tx) |
20 |
| - deriving (Show) |
| 18 | +newtype Decoded tx |
| 19 | + = DecodedHydraLog Text |
| 20 | + deriving newtype (Show) |
21 | 21 |
|
22 | 22 | main :: IO ()
|
23 | 23 | main = do
|
24 |
| - logLines <- readFileLBS "../devnet/alice-logs.txt" |
25 |
| - let allLogLines = zip [1 :: Int ..] (C8.lines logLines) |
26 |
| - decodedLines <- forM allLogLines $ \(ix, l) -> |
27 |
| - case l ^? key "message" . _String of |
28 |
| - Nothing -> error "Failed to find key 'message' which was expected" |
29 |
| - Just line -> |
30 |
| - let envelope = fromStrict $ encodeUtf8 line |
31 |
| - in case decodeAs envelope (undefined :: Envelope (HydraLog Tx)) of |
32 |
| - Left e -> error $ "Line " <> show ix <> ": error - " <> show e <> " line: " <> show line |
33 |
| - Right decoded -> pure $ DecodedHydraLog $ decoded.message |
34 |
| - print decodedLines |
35 |
| - pure () |
| 24 | + decodedLines <- |
| 25 | + runConduitRes $ |
| 26 | + sourceFileBS "../devnet/alice-logs.txt" |
| 27 | + .| linesUnboundedAsciiC |
| 28 | + .| mapMC |
| 29 | + ( \l -> |
| 30 | + case l ^? key "message" . _String of |
| 31 | + Nothing -> error "Failed to find key 'message' which was expected" |
| 32 | + Just line -> |
| 33 | + let envelope = fromStrict $ encodeUtf8 line |
| 34 | + in case decodeAs envelope (undefined :: Envelope (HydraLog Tx)) of |
| 35 | + Left e -> error $ show e <> line |
| 36 | + Right decoded -> |
| 37 | + 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 "_____" |
| 41 | + ) |
| 42 | + .| sinkList |
| 43 | + forM_ decodedLines $ \l -> |
| 44 | + putTextLn (show l) |
36 | 45 |
|
37 | 46 | decodeAs :: forall a. FromJSON a => C8.ByteString -> a -> Either String a
|
38 | 47 | decodeAs l _ =
|
|
0 commit comments