AsperforMias commented on code in PR #146:
URL: https://github.com/apache/dubbo-getty/pull/146#discussion_r4653125779


##########
logger.go:
##########
@@ -58,8 +62,43 @@ const (
        LoggerLevelFatal = LoggerLevel(zapcore.FatalLevel)
 )
 
+// loggerHolder atomically stores the process logger so SetLogger can
+// be called without racing in-flight log calls.
+type loggerHolder struct {
+       inner atomic.Value // Logger
+}
+
+type loggerBox struct {
+       logger Logger
+}
+
+func (l *loggerHolder) current() Logger {
+       v := l.inner.Load()
+       if v == nil {
+               return nil
+       }
+       return v.(loggerBox).logger
+}
+
+func (l *loggerHolder) Info(args ...any)  { l.current().Info(args...) }
+func (l *loggerHolder) Warn(args ...any)  { l.current().Warn(args...) }
+func (l *loggerHolder) Error(args ...any) { l.current().Error(args...) }
+func (l *loggerHolder) Debug(args ...any) { l.current().Debug(args...) }
+func (l *loggerHolder) Infof(fmt string, args ...any) {
+       l.current().Infof(fmt, args...)
+}
+func (l *loggerHolder) Warnf(fmt string, args ...any) {
+       l.current().Warnf(fmt, args...)
+}
+func (l *loggerHolder) Errorf(fmt string, args ...any) {
+       l.current().Errorf(fmt, args...)
+}
+func (l *loggerHolder) Debugf(fmt string, args ...any) {
+       l.current().Debugf(fmt, args...)
+}

Review Comment:
   done in 3d40424. Call sites now use `GetLogger().Xxx(...)`, and 
`loggerHolder` no longer implements `Logger`, so the extra frame cannot come 
back unnoticed. `TestLoggerCallerPointsAtCallSite` checks that a caller-enabled 
Zap logger records `session.go`; on the previous head it reports `logger.go`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to