Skip to content

Commit

Permalink
[FAB-12303] info logging for chaincode invokes (ms)
Browse files Browse the repository at this point in the history
Force the newly added chaincode info log statements to
log duration in milliseconds,
so that a consistent unit is used in all
the log messages for easier log parsing.

Change-Id: I65bc418850005a87602340aeaedb47aac1fb2665
Signed-off-by: David Enyeart <enyeart@us.ibm.com>
  • Loading branch information
denyeart committed Oct 8, 2018
1 parent 389949d commit bcc924d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion core/endorser/endorser.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ func (e *Endorser) callChaincode(txParams *ccprovider.TransactionParams, version
endorserLogger.Infof("[%s][%s] Entry chaincode: %s", txParams.ChannelID, shorttxid(txParams.TxID), cid)
defer func(start time.Time) {
logger := endorserLogger.WithOptions(zap.AddCallerSkip(1))
logger.Infof("[%s][%s] Exit chaincode: %s (%s)", txParams.ChannelID, shorttxid(txParams.TxID), cid, time.Since(start))
elapsedMilliseconds := time.Since(start).Round(time.Millisecond) / time.Millisecond
logger.Infof("[%s][%s] Exit chaincode: %s (%dms)", txParams.ChannelID, shorttxid(txParams.TxID), cid, elapsedMilliseconds)
}(time.Now())

var err error
Expand Down
2 changes: 1 addition & 1 deletion core/endorser/endorser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ func TestEndorserChaincodeCallLogging(t *testing.T) {

t.Logf("contents:\n%s", buf.Contents())
gt.Eventually(buf).Should(gbytes.Say(`INFO.*\[testchainid\]\[[[:xdigit:]]{8}\] Entry chaincode: name:"chaincode-name" version:"chaincode-version"`))
gt.Eventually(buf).Should(gbytes.Say(`INFO.*\[testchainid\]\[[[:xdigit:]]{8}\] Exit chaincode: name:"chaincode-name" version:"chaincode-version" (.*s)`))
gt.Eventually(buf).Should(gbytes.Say(`INFO.*\[testchainid\]\[[[:xdigit:]]{8}\] Exit chaincode: name:"chaincode-name" version:"chaincode-version" (.*ms)`))
}

func TestEndorserLSCC(t *testing.T) {
Expand Down

0 comments on commit bcc924d

Please sign in to comment.