-
Notifications
You must be signed in to change notification settings - Fork 20
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
Simplify logging by using slog #1572
Conversation
5f9eed6
to
5b42985
Compare
a586156
to
004c58c
Compare
@@ -31,15 +33,15 @@ func main() { | |||
if _, err := toml.DecodeFile(CONFIG_FILE, &participantOpts); err != nil { | |||
panic(err) | |||
} | |||
logger, logFile := utils.CreateLogger(LOG_FILE, "alice") | |||
defer logFile.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can avoid closing the log file manually, since that should happen anyways when the test/execution halts.
Level(zerolog.TraceLevel). | ||
With(). | ||
Timestamp(). | ||
Str("rpc", rpcRole), clientName). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that the RPC client/server no longer accept a logger, we can't easily add log attribute (like "rpc") in the test, like we did before. Instead the RPC client/server would have to add the "rpc" attribute when it sets up it's own sub-logger off the DefaultLogger
. I think this is an OK tradeoff for reducing the complexity of having to pass loggers around.
✅ Deploy Preview for nitro-gui canceled.
|
👷 Deploy Preview for nitrodocs processing.
|
✅ Deploy Preview for nitro-storybook canceled.
|
@@ -236,6 +244,7 @@ func (rc *rpcClient) subscribeToNotifications(ctx context.Context, notificationC | |||
case serde.ObjectiveCompleted: | |||
rpcRequest := serde.JsonRpcSpecificRequest[protocols.ObjectiveId]{} | |||
err := json.Unmarshal(data, &rpcRequest) | |||
rc.logger.Debug("Received notification", "method", method, "data", rpcRequest) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of passing in the raw JSON we pass in a struct that will get serialized automatically for us.
{"time":"2023-08-22T11:43:47.327969-07:00","level":"INFO","msg":"Received notification","client":"aliceLedger","notification":{"time":"2023-08-22T11:55:29.002799-07:00","level":"DEBUG","msg":"Received notification","address":"0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf","method":"objective_completed","data":{"jsonrpc":"2.0","id":1892133135947938969,"method":"objective_completed","params":"DirectDefunding-0xf4e942489cfdf77d22aa589353b9f3ac6d09eceb833a1d8e5a2634140be38aef"}}
Otherwise we'd just get a string:
{"time":"2023-08-22T11:50:48.815977-07:00","level":"DEBUG","msg":"Received notification","address":"0x2B5AD5c4795c026514f8317c7a215E218DcCD6cF","method":"objective_completed","data":"{\"jsonrpc\":\"2.0\",\"id\":11801681279923878936,\"method\":\"objective_completed\",\"params\":\"DirectDefunding-0x5cd0a2e5d660edf0c41cb3902f3350b8346da7be031a7bbf7ec57d3ca775808f\"}"}
a struct will get serialized out properly
We may want to update these instructions Line 165 in 96c012c
|
@lalexgap I am seeing some log lines like this:
Interesting that this is a silent failure -- are we swallowing an error somewhere? |
Ah good catch, that was caused by passing in a function instead of the address into a log attribute. That is fixed in 2139142.
Right now malformed arguments silently fail. It looks like there is an open issuegolang/go#59407 to add this to |
Fixes #1571
This PR updates go-nitro to use
slog
instead ofzerolog
with the goal of simplifying our logging. Instead of having to pass loggers or log destinations around we now rely on setting a global DefaultLogger.How does it work?
e.logger.Info("Engine started")
). If there is no sub-logger, you can just useslog
which will resolve to the default logger (IE:slog.Info("Hello World")
)What does it look like?
Performance
Based on the benchmarks maintained by zap it looks like
slog
is slower thanzerolog
but relatively close to other logging frameworks.