Skip to content
Permalink
Browse files

Use logging functionality within `Cardano.Wallet` (instead of putStrLn).

  • Loading branch information...
jonathanknowles committed Jun 12, 2019
1 parent 566c2a6 commit 4efe065dd27e75f479c7d6c17a30776d7af54bb7
Showing with 14 additions and 14 deletions.
  1. +14 −14 lib/core/src/Cardano/Wallet.hs
@@ -53,7 +53,7 @@ import Cardano.Wallet.DB
, PrimaryKey (..)
)
import Cardano.Wallet.Logging
( Logger (..) )
( Logger (..), Severity (..) )
import Cardano.Wallet.Network
( ErrNetworkUnreachable (..), ErrPostTx (..), NetworkLayer (..) )
import Cardano.Wallet.Primitive.AddressDerivation
@@ -167,7 +167,6 @@ import qualified Cardano.Wallet.Primitive.CoinSelection.Random as CoinSelection
import qualified Data.List as L
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
import qualified Data.Text.IO as TIO

{-------------------------------------------------------------------------------
Types
@@ -338,7 +337,7 @@ newWalletLayer
-> NetworkLayer t IO
-> TransactionLayer t
-> IO (WalletLayer s t)
newWalletLayer _ db nw tl = do
newWalletLayer logger db nw tl = do
registry <- newRegistry
return WalletLayer
{ createWallet = _createWallet
@@ -436,7 +435,7 @@ newWalletLayer _ db nw tl = do
worker <- liftIO $ forkIO $ do
runExceptT (networkTip nw) >>= \case
Left e -> do
TIO.putStrLn $ "[ERROR] restoreSleep: " +|| e ||+ ""
logger `log` Error $ "restoreSleep: " +|| e ||+ ""
restoreSleep wid (currentTip w)
Right (_, tip) -> do
restoreStep wid (currentTip w, tip ^. #slotId)
@@ -454,15 +453,16 @@ newWalletLayer _ db nw tl = do
restoreStep wid (slot, tip) = do
runExceptT (nextBlocks nw slot) >>= \case
Left e -> do
TIO.putStrLn $ "[ERROR] restoreStep: " +|| e ||+ ""
logger `log` Error $ "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 _) -> TIO.putStrLn $
"[ERROR] restoreStep: wallet " +| wid |+ " is gone!"
Left (ErrNoSuchWallet _) ->
logger `log` Error $
"restoreStep: wallet " +| wid |+ " is gone!"
Right () -> do
restoreStep wid (next, tip)

@@ -477,7 +477,7 @@ newWalletLayer _ db nw tl = do
let tenSeconds = 10000000 in threadDelay tenSeconds
runExceptT (networkTip nw) >>= \case
Left e -> do
TIO.putStrLn $ "[ERROR] restoreSleep: " +|| e ||+ ""
logger `log` Error $ "restoreSleep: " +|| e ||+ ""
restoreSleep wid slot
Right (_, tip) ->
restoreStep wid (slot, tip ^. #slotId)
@@ -494,8 +494,8 @@ newWalletLayer _ db nw tl = do
( view #slotId . header . head $ blocks
, view #slotId . header . last $ blocks
)
liftIO $ TIO.putStrLn $
"[INFO] Applying blocks ["+| inf |+" ... "+| sup |+"]"
liftIO $ logger `log` Info $
"Applying blocks ["+| inf |+" ... "+| sup |+"]"

-- NOTE
-- Not as good as a transaction, but, with the lock, nothing can make
@@ -516,10 +516,10 @@ newWalletLayer _ db nw tl = do
then Ready
else Restoring progress
let meta' = meta { status = status' } :: WalletMetadata
liftIO $ TIO.putStrLn $
"[INFO] Tx History: " +|| length txs ||+ ""
unless (null txs) $ liftIO $ TIO.putStrLn $ pretty $
"[DEBUG] :\n" <> blockListF (snd <$> Map.elems txs)
liftIO $ logger `log` Info $
"Tx History: " +|| length txs ||+ ""
unless (null txs) $ liftIO $ logger `log` Debug $ pretty $
blockListF (snd <$> Map.elems txs)
DB.putCheckpoint db (PrimaryKey wid) cp'
DB.putTxHistory db (PrimaryKey wid) txs
DB.putWalletMeta db (PrimaryKey wid) meta'

0 comments on commit 4efe065

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