logrus
logrus copied to clipboard
fix #1272
https://github.com/sirupsen/logrus/issues/1272
Thanks for your contribution, but we already have the ReplaceHooks
method which would perfectly solve your use case. Why don't just use it ?
Thanks for your contribution, but we already have the
ReplaceHooks
method which would perfectly solve your use case. Why don't just use it ? But if this method is called in parallel, an exception will occur, as you can see for details https://github.com/sirupsen/logrus/issues/1272#issuecomment-917586020
Thanks for your contribution, but we already have the
ReplaceHooks
method which would perfectly solve your use case. Why don't just use it ?
I replace the implementation ReplaceHook
I found another problem . Replication can indeed improve performance, but it will lead to this instant.
If a new hook is added, the hook may not be triggered
you can look this gist: https://github.com/lwydyby/logrus/blob/master/logger_test.go TestLogger_concurrentLock
and debug here
func (s *LogFormatter) Format(entry *Entry) ([]byte, error) {
timestamp := time.Now().Format("2006-01-02 15:04:05")
var file string
var line int
if entry.Caller != nil {
file = filepath.Base(entry.Caller.File)
line = entry.Caller.Line
}
level := entry.Level.String()
if entry.Context == nil || entry.Context.Value("trace_id") == "" {
//debug in here
uuid := "NO UUID"
entry.Context = context.WithValue(context.Background(), "trace_id", uuid)
}
msg := fmt.Sprintf("%-15s [%-3d] [%-5s] [%s] %s:%d %s\n", timestamp, getGID(), level, entry.Context.Value("trace_id"), file, line, entry.Message)
return []byte(msg), nil
}
```