From 67b6a0952282063e954559c126753a4476419a4a Mon Sep 17 00:00:00 2001 From: Zaabson Date: Wed, 6 Apr 2022 16:47:05 +0200 Subject: [PATCH 1/2] Allow chain-index to print silently. Commit adds a new definition `Plutus.ChainIndex.App (runMainWithLog)` allowing to run chain-index with different function to do startup logs. --- .../src/Plutus/ChainIndex/App.hs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/plutus-chain-index/src/Plutus/ChainIndex/App.hs b/plutus-chain-index/src/Plutus/ChainIndex/App.hs index ca91ace306..2d4be2a764 100644 --- a/plutus-chain-index/src/Plutus/ChainIndex/App.hs +++ b/plutus-chain-index/src/Plutus/ChainIndex/App.hs @@ -7,7 +7,7 @@ {-| Main entry points to the chain index. -} -module Plutus.ChainIndex.App(main, runMain) where +module Plutus.ChainIndex.App(main, runMain, runMainWithLog) where import Control.Exception (throwIO) import Data.Aeson qualified as A @@ -70,12 +70,16 @@ main = do runMain logConfig config runMain :: CM.Configuration -> Config.ChainIndexConfig -> IO () -runMain logConfig config = do +runMain = runMainWithLog putStrLn + +-- Run main with provided function to log startup logs. +runMainWithLog :: (String -> IO ()) -> CM.Configuration -> Config.ChainIndexConfig -> IO () +runMainWithLog logger logConfig config = do withRunRequirements logConfig config $ \runReq -> do - putStr "\nThe tip of the local node: " slotNo <- getTipSlot config - print slotNo + let slotNoStr = "\nThe tip of the local node: " <> show slotNo + logger slotNoStr -- Queue for processing events eventsQueue <- newTBMQueueIO (Config.cicAppendTransactionQueueSize config) measureEventByTxs @@ -84,16 +88,15 @@ runMain logConfig config = do & storeFromBlockNo (fromCardanoBlockNo $ Config.cicStoreFrom config) & pure - putStrLn $ "Connecting to the node using socket: " <> Config.cicSocketPath config + logger $ "Connecting to the node using socket: " <> Config.cicSocketPath config syncChainIndex config runReq syncHandler (trace :: Trace IO (PrettyObject SyncLog), _) <- setupTrace_ logConfig "chain-index" withAsync (processEventsQueue trace runReq eventsQueue) $ \processAsync -> do let port = show (Config.cicPort config) - putStrLn $ "Starting webserver on port " <> port - putStrLn $ "A Swagger UI for the endpoints are available at " + logger $ "Starting webserver on port " <> port + logger $ "A Swagger UI for the endpoints are available at " <> "http://localhost:" <> port <> "/swagger/swagger-ui" Server.serveChainIndexQueryServer (Config.cicPort config) runReq wait processAsync - From f82e931f64f56ed8b67d948c92b68ce7327fd764 Mon Sep 17 00:00:00 2001 From: Zaabson Date: Fri, 8 Apr 2022 12:21:13 +0200 Subject: [PATCH 2/2] Stylish-haskell. --- plutus-chain-index/src/Plutus/ChainIndex/App.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plutus-chain-index/src/Plutus/ChainIndex/App.hs b/plutus-chain-index/src/Plutus/ChainIndex/App.hs index 2d4be2a764..4f3cc42f25 100644 --- a/plutus-chain-index/src/Plutus/ChainIndex/App.hs +++ b/plutus-chain-index/src/Plutus/ChainIndex/App.hs @@ -72,7 +72,7 @@ main = do runMain :: CM.Configuration -> Config.ChainIndexConfig -> IO () runMain = runMainWithLog putStrLn --- Run main with provided function to log startup logs. +-- Run main with provided function to log startup logs. runMainWithLog :: (String -> IO ()) -> CM.Configuration -> Config.ChainIndexConfig -> IO () runMainWithLog logger logConfig config = do withRunRequirements logConfig config $ \runReq -> do