Skip to content

Commit

Permalink
Merge pull request #441 from input-output-hk/KtorZ/api-logger-unit-tests
Browse files Browse the repository at this point in the history
Api Logger Middleware - Unit tests
  • Loading branch information
KtorZ authored Jun 20, 2019
2 parents 30d840b + 3e843a4 commit 2e29b8c
Show file tree
Hide file tree
Showing 4 changed files with 407 additions and 4 deletions.
9 changes: 8 additions & 1 deletion lib/core/cardano-wallet-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ library
, fast-logger
, fmt
, generic-lens
, http-types
, http-api-data
, http-media
, http-types
, iohk-monitoring
, memory
, monad-logger
Expand Down Expand Up @@ -133,24 +133,30 @@ test-suite unit
, hspec
, hspec-golden-aeson
, http-api-data
, http-client
, http-types
, iohk-monitoring
, lens
, memory
, network
, persistent
, persistent-sqlite
, QuickCheck
, quickcheck-instances
, quickcheck-state-machine >= 0.6.0
, random
, servant
, servant-server
, servant-swagger
, stm
, swagger2
, text
, text-class
, time
, transformers
, tree-diff
, yaml
, warp
build-tools:
hspec-discover
type:
Expand Down Expand Up @@ -179,6 +185,7 @@ test-suite unit
Cardano.Wallet.Primitive.TypesSpec
Cardano.WalletSpec
Data.QuantitySpec
Network.Wai.Middleware.LoggingSpec

benchmark db
default-language:
Expand Down
6 changes: 4 additions & 2 deletions lib/core/src/Network/Wai/Middleware/Logging.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import Control.Arrow
( second )
import Control.Concurrent.MVar
( MVar, modifyMVar, newMVar )
import Control.Monad
( unless )
import Data.Aeson
( Value (..) )
import Data.ByteString
Expand Down Expand Up @@ -92,7 +94,7 @@ withApiLogger t0 settings app req0 sendResponse = do
let keys = _obfuscateKeys settings req
let safeBody = T.decodeUtf8 $ sanitize keys body
logInfo t $ mconcat [ "[", method, "] ", path, query ]
logDebug t safeBody
unless (BS.null body) $ logDebug t safeBody

logResponse
:: Trace IO Text
Expand All @@ -108,7 +110,7 @@ withApiLogger t0 settings app req0 sendResponse = do
if maybe False ((>= 500) . statusCode) status
then logError t payload
else logInfo t payload
logDebug t $ T.decodeUtf8 body
unless (BS.null body) $ logDebug t (T.decodeUtf8 body)

withRequestId :: RequestId -> LoggerName -> LoggerName
withRequestId (RequestId rid) name = mconcat
Expand Down
Loading

0 comments on commit 2e29b8c

Please sign in to comment.