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,19 +477,14 @@ func (h *handler) handleCallMsg(ctx *callProc, msg *jsonrpcMessage) *jsonrpcMess
|
||||||
if resp.Error != nil {
|
if resp.Error != nil {
|
||||||
logCtx = append(logCtx, "err", resp.Error.Message)
|
logCtx = append(logCtx, "err", resp.Error.Message)
|
||||||
if resp.Error.Data != nil {
|
if resp.Error.Data != nil {
|
||||||
// If the log level is debug, log the full error data. Otherwise, try to truncate it.
|
errDataStr := fmt.Sprintf("%v", resp.Error.Data)
|
||||||
if h.log.Enabled(context.Background(), log.LvlDebug) {
|
// Truncate the error data as string if it is too long. Otherwise, preserve the original data.
|
||||||
logCtx = append(logCtx, "errdata", resp.Error.Data)
|
if len(errDataStr) > callErrorDataLogTruncateLimit {
|
||||||
|
remaining := len(errDataStr) - callErrorDataLogTruncateLimit
|
||||||
|
errDataStr = fmt.Sprintf("%s... (truncated remaining %d chars)", errDataStr[:callErrorDataLogTruncateLimit], remaining)
|
||||||
|
logCtx = append(logCtx, "errdata", errDataStr)
|
||||||
} else {
|
} else {
|
||||||
errDataStr := fmt.Sprintf("%v", resp.Error.Data)
|
logCtx = append(logCtx, "errdata", resp.Error.Data)
|
||||||
// Truncate the error data 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)
|
|
||||||
logCtx = append(logCtx, "errdata", errDataStr)
|
|
||||||
} else {
|
|
||||||
logCtx = append(logCtx, "errdata", resp.Error.Data)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
h.log.Warn("Served "+msg.Method, logCtx...)
|
h.log.Warn("Served "+msg.Method, logCtx...)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue