-
Notifications
You must be signed in to change notification settings - Fork 20.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
eth/tracers/logger: use omitempty in error JSON tag to avoid unnecessary log bloat #24487
Labels
Comments
I take it you're using the diff --git a/eth/tracers/logger/gen_structlog.go b/eth/tracers/logger/gen_structlog.go
index 9e71b555c..7818fbe70 100644
--- a/eth/tracers/logger/gen_structlog.go
+++ b/eth/tracers/logger/gen_structlog.go
@@ -30,7 +30,7 @@ func (s StructLog) MarshalJSON() ([]byte, error) {
RefundCounter uint64 `json:"refund"`
Err error `json:"-"`
OpName string `json:"opName"`
- ErrorString string `json:"error"`
+ ErrorString string `json:"error,omitempty"`
}
var enc StructLog
enc.Pc = s.Pc
diff --git a/eth/tracers/logger/logger.go b/eth/tracers/logger/logger.go
index 846193582..444a665d6 100644
--- a/eth/tracers/logger/logger.go
+++ b/eth/tracers/logger/logger.go
@@ -82,8 +82,8 @@ type structLogMarshaling struct {
GasCost math.HexOrDecimal64
Memory hexutil.Bytes
ReturnData hexutil.Bytes
- OpName string `json:"opName"` // adds call to OpName() in MarshalJSON
- ErrorString string `json:"error"` // adds call to ErrorString() in MarshalJSON
+ OpName string `json:"opName"` // adds call to OpName() in MarshalJSON
+ ErrorString string `json:"error,omitempty"` // adds call to ErrorString() in MarshalJSON
}
// OpName formats the operand name in a human-readable format. |
odeke-em
added a commit
to orijtech/go-ethereum
that referenced
this issue
Mar 2, 2022
…oat from blank fields Noticed while debugging Tharsis/EVMOS logs that the logs were extraneous with empty fields such as ```json {"pc":4716,"op":80,"gas":"0x688e5","gasCost":"0x2","memory":"0x","memSize":352,"stack":["0xfa31de01","0x29a","0x7d0","0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd","0x80","0x534","0xc0","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7","0x15dc","0x34","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7"],"returnData":"0x","depth":2,"refund":0,"opName":"POP","error":""} {"pc":4717,"op":80,"gas":"0x688e3","gasCost":"0x2","memory":"0x","memSize":352,"stack":["0xfa31de01","0x29a","0x7d0","0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd","0x80","0x534","0xc0","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7","0x15dc","0x34"],"returnData":"0x","depth":2,"refund":0,"opName":"POP","error":""} ``` with empty fields like "error", "refund", "memory", "returnData". This change adds the JSON tag ",omitempty" to remove the bloat from the above empty fields which shows immediate impact of reducing the logs to ```json {"pc":4716,"op":80,"gas":"0x688e5","gasCost":"0x2","memSize":352,"stack":["0xfa31de01","0x29a","0x7d0","0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd","0x80","0x534","0xc0","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7","0x15dc","0x34","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7"],"depth":2,"opName":"POP"} {"pc":4717,"op":80,"gas":"0x688e3","gasCost":"0x2","memSize":352,"stack":["0xfa31de01","0x29a","0x7d0","0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd","0x80","0x534","0xc0","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7","0x15dc","0x34"],"depth":2,"opName":"POP"} ``` and not only does that reduce the size of logs but it also makes it much easier to quickly debug and grep for errors, which will only be present if erroring. Fixes ethereum#24487
holiman
pushed a commit
to holiman/go-ethereum
that referenced
this issue
Mar 16, 2022
…oat from blank fields Noticed while debugging Tharsis/EVMOS logs that the logs were extraneous with empty fields such as ```json {"pc":4716,"op":80,"gas":"0x688e5","gasCost":"0x2","memory":"0x","memSize":352,"stack":["0xfa31de01","0x29a","0x7d0","0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd","0x80","0x534","0xc0","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7","0x15dc","0x34","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7"],"returnData":"0x","depth":2,"refund":0,"opName":"POP","error":""} {"pc":4717,"op":80,"gas":"0x688e3","gasCost":"0x2","memory":"0x","memSize":352,"stack":["0xfa31de01","0x29a","0x7d0","0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd","0x80","0x534","0xc0","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7","0x15dc","0x34"],"returnData":"0x","depth":2,"refund":0,"opName":"POP","error":""} ``` with empty fields like "error", "refund", "memory", "returnData". This change adds the JSON tag ",omitempty" to remove the bloat from the above empty fields which shows immediate impact of reducing the logs to ```json {"pc":4716,"op":80,"gas":"0x688e5","gasCost":"0x2","memSize":352,"stack":["0xfa31de01","0x29a","0x7d0","0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd","0x80","0x534","0xc0","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7","0x15dc","0x34","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7"],"depth":2,"opName":"POP"} {"pc":4717,"op":80,"gas":"0x688e3","gasCost":"0x2","memSize":352,"stack":["0xfa31de01","0x29a","0x7d0","0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd","0x80","0x534","0xc0","0x5f646b5592c4159d4963fbf901f81144ef53cc51a7082435e3a6120a45002ff7","0x15dc","0x34"],"depth":2,"opName":"POP"} ``` and not only does that reduce the size of logs but it also makes it much easier to quickly debug and grep for errors, which will only be present if erroring. Fixes ethereum#24487
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
System information
Geth version:
geth version
Not ApplicableOS & Version: Windows/Linux/OSX Not Applicable
Commit hash : 687e4dc
Expected behaviour
Lack of error strings should NOT log
"error":""
which bloats logs and can actually be confusing when you grep for "error" in logs when things are failing.Actual behaviour
Looking at such logs like
Notice that each log line has
"error":""
perSteps to reproduce the behaviour
Just run the tracers
This bug was sponsored by Tharsis / evmos.org
The text was updated successfully, but these errors were encountered: