Skip to content
Permalink
Browse files

Remove `Logger` wrapper and use `Trace` object instead.

  • Loading branch information...
jonathanknowles committed Jun 12, 2019
1 parent bcbbc21 commit b360c3a78a6b89c2e219e1826ab0355a5e7b4d40
@@ -28,12 +28,10 @@ import Prelude hiding

import Cardano.BM.Configuration.Static
( defaultConfigStdout )
import Cardano.BM.Data.LogItem
( PrivacyAnnotation (..) )
import Cardano.BM.Setup
( setupTrace )
import Cardano.BM.Trace
( appendName, traceNamedItem )
( Trace, appendName )
import Cardano.CLI
( getLine
, getSensitiveLine
@@ -58,8 +56,6 @@ import Cardano.Wallet.HttpBridge.Compatibility
( HttpBridge )
import Cardano.Wallet.HttpBridge.Environment
( KnownNetwork (..), Network (..) )
import Cardano.Wallet.Logging
( Logger (..) )
import Cardano.Wallet.Network
( defaultRetryPolicy, waitForConnection )
import Cardano.Wallet.Primitive.AddressDerivation
@@ -184,12 +180,11 @@ main = do
Logging
-------------------------------------------------------------------------------}

initLogger :: IO Logger
initLogger = do
initTracer :: IO (Trace IO Text)
initTracer = do
c <- defaultConfigStdout
tr <- setupTrace (Right c) "simple"
trText <- appendName "text" tr
pure $ Logger { log = traceNamedItem trText Public }
appendName "text" tr

{-------------------------------------------------------------------------------
Command and Argument Parsing
@@ -356,7 +351,7 @@ execHttpBridge
:: forall n. (KeyToAddress (HttpBridge n), KnownNetwork n)
=> Arguments -> Proxy (HttpBridge n) -> IO ()
execHttpBridge args _ = do
logger <- initLogger
tracer <- initTracer
(walletPort :: Maybe Int)
<- args `parseOptionalArg` longOption "port"
(bridgePort :: Int)
@@ -366,7 +361,7 @@ execHttpBridge args _ = do
nw <- HttpBridge.newNetworkLayer @n bridgePort
waitForConnection nw defaultRetryPolicy
let tl = HttpBridge.newTransactionLayer @n
wallet <- newWalletLayer @_ @(HttpBridge n) logger db nw tl
wallet <- newWalletLayer @_ @(HttpBridge n) tracer db nw tl
let logStartup port = TIO.hPutStrLn stderr $
"Wallet backend server listening on: " <> toText port
Server.start logStartup walletPort wallet
@@ -82,7 +82,6 @@ library
Cardano.Wallet.DB.Sqlite
Cardano.Wallet.DB.Sqlite.TH
Cardano.Wallet.DB.Sqlite.Types
Cardano.Wallet.Logging
Cardano.Wallet.Network
Cardano.Wallet.Primitive.AddressDerivation
Cardano.Wallet.Primitive.AddressDiscovery
@@ -131,6 +130,7 @@ test-suite unit
, hspec
, hspec-golden-aeson
, http-api-data
, iohk-monitoring
, lens
, memory
, persistent
@@ -46,14 +46,14 @@ module Cardano.Wallet
import Prelude hiding
( log )

import Cardano.BM.Trace
( Trace, logDebug, logError, logInfo )
import Cardano.Wallet.DB
( DBLayer
, ErrNoSuchWallet (..)
, ErrWalletAlreadyExists (..)
, PrimaryKey (..)
)
import Cardano.Wallet.Logging
( Logger (..), Severity (..) )
import Cardano.Wallet.Network
( ErrNetworkUnreachable (..), ErrPostTx (..), NetworkLayer (..) )
import Cardano.Wallet.Primitive.AddressDerivation
@@ -157,6 +157,8 @@ import Data.Maybe
( mapMaybe )
import Data.Quantity
( Quantity (..) )
import Data.Text
( Text )
import Data.Time.Clock
( getCurrentTime )
import Fmt
@@ -332,12 +334,12 @@ cancelWorker (WorkerRegistry mvar) wid =
-- | Create a new instance of the wallet layer.
newWalletLayer
:: forall s t. ()
=> Logger
=> Trace IO Text
-> DBLayer IO s t
-> NetworkLayer t IO
-> TransactionLayer t
-> IO (WalletLayer s t)
newWalletLayer logger db nw tl = do
newWalletLayer tracer db nw tl = do
registry <- newRegistry
return WalletLayer
{ createWallet = _createWallet
@@ -435,7 +437,7 @@ newWalletLayer logger db nw tl = do
worker <- liftIO $ forkIO $ do
runExceptT (networkTip nw) >>= \case
Left e -> do
logger `log` Error $ "restoreSleep: " +|| e ||+ ""
logError tracer $ "restoreSleep: " +|| e ||+ ""
restoreSleep wid (currentTip w)
Right (_, tip) -> do
restoreStep wid (currentTip w, tip ^. #slotId)
@@ -453,15 +455,15 @@ newWalletLayer logger db nw tl = do
restoreStep wid (slot, tip) = do
runExceptT (nextBlocks nw slot) >>= \case
Left e -> do
logger `log` Error $ "restoreStep: " +|| e ||+ ""
logError tracer $ "restoreStep: " +|| e ||+ ""
restoreSleep wid slot
Right [] -> do
restoreSleep wid slot
Right blocks -> do
let next = view #slotId . header . last $ blocks
runExceptT (restoreBlocks wid blocks tip) >>= \case
Left (ErrNoSuchWallet _) ->
logger `log` Error $
logError tracer $
"restoreStep: wallet " +| wid |+ " is gone!"
Right () -> do
restoreStep wid (next, tip)
@@ -477,7 +479,7 @@ newWalletLayer logger db nw tl = do
let tenSeconds = 10000000 in threadDelay tenSeconds
runExceptT (networkTip nw) >>= \case
Left e -> do
logger `log` Error $ "restoreSleep: " +|| e ||+ ""
logError tracer $ "restoreSleep: " +|| e ||+ ""
restoreSleep wid slot
Right (_, tip) ->
restoreStep wid (slot, tip ^. #slotId)
@@ -494,7 +496,7 @@ newWalletLayer logger db nw tl = do
( view #slotId . header . head $ blocks
, view #slotId . header . last $ blocks
)
liftIO $ logger `log` Info $
liftIO $ logInfo tracer $
"Applying blocks ["+| inf |+" ... "+| sup |+"]"

-- NOTE
@@ -516,9 +518,9 @@ newWalletLayer logger db nw tl = do
then Ready
else Restoring progress
let meta' = meta { status = status' } :: WalletMetadata
liftIO $ logger `log` Info $
liftIO $ logInfo tracer $
"Tx History: " +|| length txs ||+ ""
unless (null txs) $ liftIO $ logger `log` Debug $ pretty $
unless (null txs) $ liftIO $ logDebug tracer $ pretty $
blockListF (snd <$> Map.elems txs)
DB.putCheckpoint db (PrimaryKey wid) cp'
DB.putTxHistory db (PrimaryKey wid) txs

This file was deleted.

@@ -14,6 +14,8 @@ module Cardano.WalletSpec

import Prelude

import Cardano.BM.Trace
( nullTracer )
import Cardano.Wallet
( ErrCreateUnsignedTx (..)
, ErrSignTx (..)
@@ -29,8 +31,6 @@ import Cardano.Wallet.DB
( DBLayer, ErrNoSuchWallet (..), PrimaryKey (..) )
import Cardano.Wallet.DB.MVar
( newDBLayer )
import Cardano.Wallet.Logging
( nullLogger )
import Cardano.Wallet.Primitive.AddressDerivation
( ChangeChain (..)
, Depth (..)
@@ -331,7 +331,7 @@ setupFixture (wid, wname, wstate) = do
db <- newDBLayer
let nl = error "NetworkLayer"
let tl = dummyTransactionLayer
wl <- newWalletLayer @_ @DummyTarget nullLogger db nl tl
wl <- newWalletLayer @_ @DummyTarget nullTracer db nl tl
res <- runExceptT $ createWallet wl wid wname wstate
let wal = case res of
Left _ -> []
@@ -149,6 +149,7 @@ test-suite integration
, http-client
, http-api-data
, http-types
, iohk-monitoring
, memory
, process
, retry
@@ -208,6 +209,7 @@ benchmark restore
, digest
, fmt
, generic-lens
, iohk-monitoring
, persistent
, persistent-template
, process
@@ -10,6 +10,8 @@ module Main where

import Prelude

import Cardano.BM.Trace
( nullTracer )
import Cardano.Launcher
( Command (Command), StdStream (..), installSignalHandlers, launch )
import Cardano.Wallet
@@ -24,8 +26,6 @@ import Cardano.Wallet.HttpBridge.Network
( newNetworkLayer )
import Cardano.Wallet.HttpBridge.Transaction
( newTransactionLayer )
import Cardano.Wallet.Logging
( nullLogger )
import Cardano.Wallet.Network
( NetworkLayer (..), networkTip )
import Cardano.Wallet.Primitive.AddressDerivation
@@ -215,7 +215,7 @@ bench_restoration _ (wid, wname, s) = withHttpBridge network $ \port -> do
(_, bh) <- unsafeRunExceptT $ networkTip networkLayer
sayErr . fmt $ network ||+ " tip is at " +|| (bh ^. #slotId) ||+ ""
w <- newWalletLayer @_ @(HttpBridge n)
nullLogger dbLayer networkLayer transactionLayer
nullTracer dbLayer networkLayer transactionLayer
wallet <- unsafeRunExceptT $ createWallet w wid wname s
unsafeRunExceptT $ restoreWallet w wallet
waitForWalletSync w wallet
@@ -8,6 +8,8 @@ module Cardano.WalletSpec

import Prelude

import Cardano.BM.Trace
( nullTracer )
import Cardano.Launcher
( Command (..), StdStream (..), launch )
import Cardano.Wallet
@@ -16,8 +18,6 @@ import Cardano.Wallet.HttpBridge.Compatibility
( HttpBridge )
import Cardano.Wallet.HttpBridge.Environment
( KnownNetwork (..), Network (..) )
import Cardano.Wallet.Logging
( nullLogger )
import Cardano.Wallet.Primitive.AddressDerivation
( Passphrase (..), digest, generateKeyFromSeed, publicKey )
import Cardano.Wallet.Primitive.AddressDiscovery
@@ -79,4 +79,4 @@ spec = do
nl <- HttpBridge.newNetworkLayer @'Testnet port
let tl = HttpBridge.newTransactionLayer
(handle,) <$>
(newWalletLayer @_ @(HttpBridge 'Testnet) nullLogger db nl tl)
(newWalletLayer @_ @(HttpBridge 'Testnet) nullTracer db nl tl)
@@ -7,6 +7,8 @@ module Main where

import Prelude

import Cardano.BM.Trace
( nullTracer )
import Cardano.Faucet
( initFaucet )
import Cardano.Launcher
@@ -17,8 +19,6 @@ import Cardano.Wallet.HttpBridge.Compatibility
( HttpBridge )
import Cardano.Wallet.HttpBridge.Environment
( Network (..) )
import Cardano.Wallet.Logging
( nullLogger )
import Cardano.Wallet.Network
( NetworkLayer (..) )
import Control.Concurrent
@@ -177,7 +177,7 @@ main = hspec $ do
cardanoWalletServer nl serverPort = void $ forkIO $ do
db <- MVar.newDBLayer
let tl = HttpBridge.newTransactionLayer
wallet <- newWalletLayer nullLogger db nl tl
wallet <- newWalletLayer nullTracer db nl tl
Server.start (const $ pure ()) (Just serverPort) wallet

waitForCluster :: String -> IO ()

0 comments on commit b360c3a

Please sign in to comment.
You can’t perform that action at this time.