Log writes a structured log entry to the chain/log logger with information about the error and the HTTP response.
(ctx context.Context, err error)
| 79 | // Log writes a structured log entry to the chain/log logger with |
| 80 | // information about the error and the HTTP response. |
| 81 | func (f Formatter) Log(ctx context.Context, err error) { |
| 82 | var errorMessage string |
| 83 | if err != nil { |
| 84 | // strip the stack trace, if there is one |
| 85 | errorMessage = err.Error() |
| 86 | } |
| 87 | |
| 88 | resp := f.Format(err) |
| 89 | keyvals := []interface{}{ |
| 90 | "status", resp.HTTPStatus, |
| 91 | "chaincode", resp.ChainCode, |
| 92 | "path", reqid.PathFromContext(ctx), |
| 93 | log.KeyError, errorMessage, |
| 94 | } |
| 95 | if resp.HTTPStatus == 500 { |
| 96 | keyvals = append(keyvals, log.KeyStack, errors.Stack(err)) |
| 97 | } |
| 98 | log.Printkv(ctx, keyvals...) |
| 99 | } |