-
Notifications
You must be signed in to change notification settings - Fork 36
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
Settable global logger #1348
Settable global logger #1348
Conversation
Example with a custom logger; {
"severity": "debug",
"timestamp": "2022-09-08T18:13:49.429+00:00",
"service_id": "Meridio-LB",
"message": "(7) ⎆ sdk/pkg/registry/core/trace/traceNetworkServiceEndpointRegistryFindClient.Recv()",
"version": "1.0.0",
"extra_data": {
"subsystem": "NSM",
"type": "registry"
}
} |
About failed CI;
The others seem to be minor updates. I can fix those. |
@uablrek There is also failed build/tests. Could you have a look? |
I'm just interested in why we can't just declare a global context and put there a logger. @uablrek Could you remind me why we can't use a global context? |
Not sure, but nobody else does that AFAIK so I suppose there are reasons. It is recommended to pass context as the first parameter (not using a global context) and context's are more often derived than a logger. |
59a7e13
to
c78978d
Compare
Signed-off-by: Lars Ekman <lars.g.ekman@est.tech>
Signed-off-by: Lars Ekman <lars.g.ekman@est.tech>
…k@main PR link: networkservicemesh/sdk#1348 Commit: fd7a204 Author: Lars Ekman Date: 2022-11-01 16:17:33 +0100 Message: - Settable global logger (#1348) * Add a settable global logger Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> * Use the global logger for trace-logging Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main PR link: networkservicemesh/sdk#1348 Commit: fd7a204 Author: Lars Ekman Date: 2022-11-01 16:17:33 +0100 Message: - Settable global logger (#1348) * Add a settable global logger Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> * Use the global logger for trace-logging Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main PR link: networkservicemesh/sdk#1348 Commit: fd7a204 Author: Lars Ekman Date: 2022-11-01 16:17:33 +0100 Message: - Settable global logger (#1348) * Add a settable global logger Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> * Use the global logger for trace-logging Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main PR link: networkservicemesh/sdk#1348 Commit: fd7a204 Author: Lars Ekman Date: 2022-11-01 16:17:33 +0100 Message: - Settable global logger (#1348) * Add a settable global logger Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> * Use the global logger for trace-logging Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main PR link: networkservicemesh/sdk#1348 Commit: fd7a204 Author: Lars Ekman Date: 2022-11-01 16:17:33 +0100 Message: - Settable global logger (#1348) * Add a settable global logger Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> * Use the global logger for trace-logging Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main PR link: networkservicemesh/sdk#1348 Commit: fd7a204 Author: Lars Ekman Date: 2022-11-01 16:17:33 +0100 Message: - Settable global logger (#1348) * Add a settable global logger Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> * Use the global logger for trace-logging Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main PR link: networkservicemesh/sdk#1348 Commit: fd7a204 Author: Lars Ekman Date: 2022-11-01 16:17:33 +0100 Message: - Settable global logger (#1348) * Add a settable global logger Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> * Use the global logger for trace-logging Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main PR link: networkservicemesh/sdk#1348 Commit: fd7a204 Author: Lars Ekman Date: 2022-11-01 16:17:33 +0100 Message: - Settable global logger (#1348) * Add a settable global logger Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> * Use the global logger for trace-logging Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main PR link: networkservicemesh/sdk#1348 Commit: fd7a204 Author: Lars Ekman Date: 2022-11-01 16:17:33 +0100 Message: - Settable global logger (#1348) * Add a settable global logger Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> * Use the global logger for trace-logging Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main PR link: networkservicemesh/sdk#1348 Commit: fd7a204 Author: Lars Ekman Date: 2022-11-01 16:17:33 +0100 Message: - Settable global logger (#1348) * Add a settable global logger Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> * Use the global logger for trace-logging Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main PR link: networkservicemesh/sdk#1348 Commit: fd7a204 Author: Lars Ekman Date: 2022-11-01 16:17:33 +0100 Message: - Settable global logger (#1348) * Add a settable global logger Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> * Use the global logger for trace-logging Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main PR link: networkservicemesh/sdk#1348 Commit: fd7a204 Author: Lars Ekman Date: 2022-11-01 16:17:33 +0100 Message: - Settable global logger (#1348) * Add a settable global logger Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> * Use the global logger for trace-logging Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main PR link: networkservicemesh/sdk#1348 Commit: fd7a204 Author: Lars Ekman Date: 2022-11-01 16:17:33 +0100 Message: - Settable global logger (#1348) * Add a settable global logger Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> * Use the global logger for trace-logging Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@main (#551) PR link: networkservicemesh/sdk#1348 Commit: fd7a204 Author: Lars Ekman Date: 2022-11-01 16:17:33 +0100 Message: - Settable global logger (#1348) * Add a settable global logger Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> * Use the global logger for trace-logging Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io> Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io> Co-authored-by: NSMBot <nsmbot@networkservicmesh.io>
…d-nsmgr@main PR link: networkservicemesh/cmd-nsmgr#551 Commit: 4a90d30 Author: Network Service Mesh Bot Date: 2022-11-08 03:02:24 -0600 Message: - Update go.mod and go.sum to latest version from networkservicemesh/sdk@main (#551) PR link: networkservicemesh/sdk#1348 Commit: fd7a204 Author: Lars Ekman Date: 2022-11-01 16:17:33 +0100 Message: - Settable global logger (#1348) * Add a settable global logger Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> * Use the global logger for trace-logging Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io> Signed-off-by: Lars Ekman <lars.g.ekman@est.tech> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
Description
It should be possible to set an own customizwd Logger to be used by NSM. Now the logger is hard-coded in some places, most notable the
logruslogger.FromSpan()
used for trace logging. The intention for this PR is to fix the most urgent needs in a backward compatible way with as little changes as possible.This PR adds a global logger reachable with
log.L()
(same as zap) and settable withlog.SetGlobalLogger(l Logger)
.logruslogger.FromSpan()
has been altered to become generic by using thelog.Logger
interface rather than a variation oflogruslogger
. It uses the global logger as base (callslog.L()
) and thus allows users to specify the logger used for trace.For backward compatibility the global Logger is set to aIf no logger is specified (logger is log.Default()) a backward compatible logger (logrus) is used.logruslogger
on init.The global logger should be set early in
main()
. Example;Tasks that should be done but are not backward compatible
FromSpan()
from packagelogruslogger
tolog
(since it's not logrus specific any more)FromSpan()
->NewTraceLogger()
I will not add these things since it affects code all over the place I guess. Also
FromSpan()
is a horrible hack IMHO and should be re-written.Issue link
#1272
How Has This Been Tested?
I have used this PR in our NSM application with trace and it works fine. The example above is from real code. I have also used a
logruslogger/logruslogger_test.go
unit test to exercise the code in a convenient way. I have not included it since it doesn't really make any automatic tests, it just emits logs in various ways to be eyeballed by the developer.Types of changes