mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
rpc: truncate errdata at all log levels
This commit is contained in:
parent
7f6283e10a
commit
a15b9c88cb
1 changed files with 7 additions and 12 deletions
|
|
@ -477,12 +477,8 @@ func (h *handler) handleCallMsg(ctx *callProc, msg *jsonrpcMessage) *jsonrpcMess
|
|||
if resp.Error != nil {
|
||||
logCtx = append(logCtx, "err", resp.Error.Message)
|
||||
if resp.Error.Data != nil {
|
||||
// If the log level is debug, log the full error data. Otherwise, try to truncate it.
|
||||
if h.log.Enabled(context.Background(), log.LvlDebug) {
|
||||
logCtx = append(logCtx, "errdata", resp.Error.Data)
|
||||
} else {
|
||||
errDataStr := fmt.Sprintf("%v", resp.Error.Data)
|
||||
// Truncate the error data if it is too long. Otherwise, preserve the original data.
|
||||
// Truncate the error data as string if it is too long. Otherwise, preserve the original data.
|
||||
if len(errDataStr) > callErrorDataLogTruncateLimit {
|
||||
remaining := len(errDataStr) - callErrorDataLogTruncateLimit
|
||||
errDataStr = fmt.Sprintf("%s... (truncated remaining %d chars)", errDataStr[:callErrorDataLogTruncateLimit], remaining)
|
||||
|
|
@ -491,7 +487,6 @@ func (h *handler) handleCallMsg(ctx *callProc, msg *jsonrpcMessage) *jsonrpcMess
|
|||
logCtx = append(logCtx, "errdata", resp.Error.Data)
|
||||
}
|
||||
}
|
||||
}
|
||||
h.log.Warn("Served "+msg.Method, logCtx...)
|
||||
} else {
|
||||
h.log.Debug("Served "+msg.Method, logCtx...)
|
||||
|
|
|
|||
Loading…
Reference in a new issue