-
Notifications
You must be signed in to change notification settings - Fork 61
feat: 138: Enable logging to be pluggable #327
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
base: main
Are you sure you want to change the base?
Conversation
…figured logger from a remote implementation
…es as structured log attributes
|
@microsoft-github-policy-service agree |
…ttributes as structured log attributes
…sing Go 1.20 in go.mod; bump golangci-lint to latest version
|
currently in Draft to fix the data races raised when reading the (pointer) elements of I will address it, then release the PR from draft once again :D |
…nditions on concurrent reads / writes to its pointer elements; added Lock and Unlock methods; protecting String method call with mutex
…uctor frames.NewPerformFlow; lock existing frames when writing to them
|
addressed the issue with the race condition on |
Hi folks :D
This PR adds support for configurable logging in
go-amqpusinglog/slog.The logger is kept in a global state, within the
internal/debugpackage, as before. However, it is initialized with a no-op implementation of aslog.Handler. Doing so, allows sane defaults (disabled logging) while allowing the caller to still register their ownslog.Handlerif they desire.This is done via a
RegisterLoggerininternal/debugwhich is then made public in a top-leveldebug.gofile. We're able to discuss the approach to this change, if you'd maybe prefer to ditchinternal/debugall together, moving that logic into top-leveldebug.go.The signature of
Logis changed to allow consuming contexts, defining level withslog.Levelvalues, just likeAssertwhich should work like before, but the caller is also able to pass arguments (likeslog.Attr), and makingAssertfno longer necessary. Minimal tests added for both of these functions.The new log levels respect the verbosity as defined before, but we can also discuss any changes you'd like to see in that regard.
As for a client or consumer of this library, they are able to enable and disable logging by registering a
slog.Handlerusingamqp.RegisterLogger. This is in line of strategies seen in libraries likeopentelemetry-go. Provided that the global-state objects are initialized with sane defaults, I don't perceive any particular issue with this approach, but curious on your input on this.Calling
amqp.RegisterLoggercould happen from themain.gofile for the client application that usesgo-amqp, if the app sends and / or receives messages using this library; or by a client library that wrapsgo-amqpA race condition on
*frames.PerformFlowwas found after publishing this PR, since this frame is overwritten in a*Session.muxcall. With this implementation, passing frames asslog.Attrattributes, it causes it to be read and written to at the same time in certain occasions. This may not have been noticeable before due to the (complete) no-op implementation of the debug logging function.Added a (private)
*sync.Mutexto*frames.PerformFlow, alongside aframes.NewPerformFlowconstructor and*frames.PerformFlow.Lockand*frames.PerformFlow.UnlockmethodsCloses #138