-
Notifications
You must be signed in to change notification settings - Fork 59
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
feat: 138: Enable logging to be pluggable #327
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-amqp
usinglog/slog
.The logger is kept in a global state, within the
internal/debug
package, 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.Handler
if they desire.This is done via a
RegisterLogger
ininternal/debug
which is then made public in a top-leveldebug.go
file. We're able to discuss the approach to this change, if you'd maybe prefer to ditchinternal/debug
all together, moving that logic into top-leveldebug.go
.The signature of
Log
is changed to allow consuming contexts, defining level withslog.Level
values, just likeAssert
which should work like before, but the caller is also able to pass arguments (likeslog.Attr
), and makingAssertf
no 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.Handler
usingamqp.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.RegisterLogger
could happen from themain.go
file 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-amqp
A race condition on
*frames.PerformFlow
was found after publishing this PR, since this frame is overwritten in a*Session.mux
call. With this implementation, passing frames asslog.Attr
attributes, 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.Mutex
to*frames.PerformFlow
, alongside aframes.NewPerformFlow
constructor and*frames.PerformFlow.Lock
and*frames.PerformFlow.Unlock
methodsCloses #138