Skip to content

Commit

Permalink
Allow chain-index to print silently. (#401)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
zmrocze committed May 12, 2022
1 parent 6d0596e commit 27820e5
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions plutus-chain-index/src/Plutus/ChainIndex/App.hs
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

0 comments on commit 27820e5

Please sign in to comment.