Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow chain-index to print silently. #401

Merged
merged 2 commits into from
May 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions plutus-chain-index/src/Plutus/ChainIndex/App.hs
Original file line number Diff line number Diff line change
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