-
Notifications
You must be signed in to change notification settings - Fork 51
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
refactor: Replace logging package with corelog #2406
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #2406 +/- ##
===========================================
- Coverage 75.07% 74.90% -0.17%
===========================================
Files 272 268 -4
Lines 26332 25856 -476
===========================================
- Hits 19768 19367 -401
+ Misses 5225 5162 -63
+ Partials 1339 1327 -12
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 8 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
Hi Keenan - could you please summarise the key differences between the And has the |
I think it'd be nice to have them both reviewed before merging. |
Thanks Keenan :)
What is the reasoning behind this change? Is there a Source use-case for calling And did you consider calling it |
There's a few cases within DefraDB that did not have a proper context and I wanted it to be flexible for the other projects.
This is the same API as the |
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.
The code changes in this repo look good, but I want the coreLog lib to be reviewed before this is merged, and there is a design change that I would like the team to chat about and agree upon too (RE log args).
http/logger.go
Outdated
logging.NewKV("Status", status), | ||
logging.NewKV("LengthBytes", bytes), | ||
logging.NewKV("ElapsedTime", elapsed.String()), | ||
"Method", e.req.Method, |
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.
todo: These no longer look 'structured' looking at the call "Method": methodValue, "Path": pathValue, etc
, instead it looks like they would be logged as equal and independent values "Method", methodValue, "Path", pathValue, ...
?
I think that is a loss, and one worth chatting about with the team.
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.
It is possible to use slog.String("key", "val")
or any of the other variants here in place of the alternating key value pairs. I have a slight preference for the alternating key values but happy to hear more opinions.
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'm also in favour of using slog.String("key", "val")
. Is there a reason for your preference of the alternating key value pairs that could help change our minds?
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.
Is there a reason for your preference of the alternating key value pairs that could help change our minds?
It's easier for me to read, but I don't mind the other option.
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.
It's easier for me to read, but I don't mind the other option.
Might be worth chatting with the protocol (and the rest of the db team) about this - whilst the current interface allows for both to be used, we might want to force slog.Foo("Key", val)
like the old logging package used to.
Changing func (l *Logger) Info(msg string, args ...any)
into func (l *Logger) Info(msg string, args ...slog.Attr)
.
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.
Feedback methods have been removed in favor of restricting the output to stderr and stdout
The Feedback methods allowed sending the logs to a log file but also return useful messages to the terminal. Any plans to support the same functionality? Or is there a more devex appropriate way to do this?
datastore/blockstore.go
Outdated
@@ -64,7 +64,7 @@ func (bs *bstore) HashOnRead(enabled bool) { | |||
// Get returns a block from the blockstore. | |||
func (bs *bstore) Get(ctx context.Context, k cid.Cid) (blocks.Block, error) { | |||
if !k.Defined() { | |||
log.Error(ctx, "Undefined CID in blockstore") | |||
log.ErrorContext(ctx, "Undefined CID in blockstore") |
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.
suggestion: We should remove the error logging here since an error is returned to the caller.
http/logger.go
Outdated
logging.NewKV("Status", status), | ||
logging.NewKV("LengthBytes", bytes), | ||
logging.NewKV("ElapsedTime", elapsed.String()), | ||
"Method", e.req.Method, |
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'm also in favour of using slog.String("key", "val")
. Is there a reason for your preference of the alternating key value pairs that could help change our minds?
net/server.go
Outdated
return nil, err | ||
} | ||
|
||
ctx := grpcpeer.NewContext(s.peer.ctx, &grpcpeer.Peer{ | ||
Addr: addr{from}, | ||
}) | ||
if _, err := s.PushLog(ctx, req); err != nil { | ||
log.ErrorE(ctx, "Failed pushing log for doc", err, logging.NewKV("Topic", topic)) | ||
log.ErrorContextE(ctx, "Failed pushing log for doc", err, "Topic", topic) |
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.
todo: This error log should just be removed.
My main concern with logging to a file is that we don't have a log rotation system. Cloud deployments usually come with a way to automatically capture logs, docker has a built in logging driver, and linux deployments can use syslog or systemd / journalctl. |
I just tested out what it looks like in the terminal.
One thing that I would prefer is the have the |
Very nice spot :) I think it should be before |
It's possible to change the order but we'll need to rename the variables. This should also help avoid attribute name collisions. Which version does everyone prefer?
|
Weirdly I think I prefer the |
Same 👍 |
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.
LGTM, thanks a bunch Keenan :)
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.
LGTM!
Relevant issue(s)
Resolves #2405
Description
This PR replaces the logging package with the
corelog
library.Please review along with sourcenetwork/corelog#2
corelog
utilizes thelog/slog
standard library package to produce structured logs.The interface is kept mostly the same with some modifications:
Debug
andFatal
levels have been removedcontext
for logging calls has been moved to a context specific variant. For exampleInfo
has aInfoContext
variant.Feedback
methods have been removed in favor of restricting the output tostderr
andstdout
.text
orjson
.csv
is not supported byslog
Tasks
How has this been tested?
Manually tested
Specify the platform(s) on which this was tested: