-
Notifications
You must be signed in to change notification settings - Fork 10
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
No method available to add Fields to existing globalLogger variable #9
Comments
The You should create a customized var log = slog.NewLogger()
// ...
func init() {
log.BindFields(...) // some global fields
}
func yourFunc() {
log.Info("......") // log with global fields
log.WithFields(...).Warn("...") // log with global and transient fields to log
} |
My requirement is to log sessionid which is one of the element in the JWT token claims body which comes with every request. So the fields which i have to add to logger is not available by the time when init() gets executed. Or can you please let me know how to print sid (sessionid) with every log statement without calling log.WithFields(sid value) everytime. |
OK, this is a good question. What you need is |
This is a very useful feature, but I think i could implement it soon. |
Correct, this is what I need here like MDC in slf4j to add session Ids/any other fields. |
This work has done, in
There hasn't docs yet, but I believe you will know how to use them. You can use those functions to add context variables into goroutine's local storage, and those |
HI,
I want to add few values to Fields of the exiting globalLogger, not to the new one created by GetLogger() or func NewLogger(name string) . because I see that no possiblity to again set back newly created *Logger to globalLogger variable.
This is also becasue , slf_core.go always uses globalLogger & not the one I created instance of Logger
func Debug(v ...interface{}) {
...
...
globalLogger.print(DebugLevel, pc[0], nil, v...)
}
Either provide a method to set the newly created Logger to globalLogger or provide new getGlobalLogger() to get handle to globalLogger so that Fields can be added.
somethig like below in slf_core.go :
func GetGlobalLogger() *Logger {
return globalLogger
}
OR
func AddFields(fields Fields) {
globalLogger.BindFields(fields Fields)
}
The text was updated successfully, but these errors were encountered: