Skip to content

Commit

Permalink
[FAB-18270] Disable debug of CouchDB response body
Browse files Browse the repository at this point in the history
The CouchDB query response body should not be added to debug log.
This change reduces the debug to the HTTP headers only, so that
the peer debug log can still be associated with the CouchDB logs, without
logging the full response content.

Signed-off-by: David Enyeart <enyeart@us.ibm.com>
  • Loading branch information
denyeart committed Oct 14, 2020
1 parent 75f9fe7 commit 83c833c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions core/ledger/util/couchdb/couchdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -923,11 +923,12 @@ func (dbclient *CouchDatabase) ReadDocRange(startKey, endKey string, limit int32
defer closeResponseBody(resp)

if logger.IsEnabledFor(zapcore.DebugLevel) {
dump, err2 := httputil.DumpResponse(resp, true)
dump, err2 := httputil.DumpResponse(resp, false)
if err2 != nil {
log.Fatal(err2)
}
logger.Debugf("[%s] %s", dbclient.DBName, dump)
// compact debug log to a single line by replacing carriage return / line feed with pipes to separate http headers
logger.Debugf("[%s] HTTP Response: %s", dbclient.DBName, bytes.Replace(dump, []byte{0x0d, 0x0a}, []byte{0x20, 0x7c, 0x20}, -1))
}

//handle as JSON document
Expand Down Expand Up @@ -1059,11 +1060,12 @@ func (dbclient *CouchDatabase) QueryDocuments(query string) ([]*QueryResult, str
defer closeResponseBody(resp)

if logger.IsEnabledFor(zapcore.DebugLevel) {
dump, err2 := httputil.DumpResponse(resp, true)
dump, err2 := httputil.DumpResponse(resp, false)
if err2 != nil {
log.Fatal(err2)
}
logger.Debugf("[%s] %s", dbclient.DBName, dump)
// compact debug log to a single line by replacing carriage return / line feed with pipes to separate http headers
logger.Debugf("[%s] HTTP Response: %s", dbclient.DBName, bytes.Replace(dump, []byte{0x0d, 0x0a}, []byte{0x20, 0x7c, 0x20}, -1))
}

//handle as JSON document
Expand Down

0 comments on commit 83c833c

Please sign in to comment.