fix: optimize logx for less GC objects (#3627)

master
Kevin Wan 1 year ago committed by GitHub
parent 88f60d7736
commit 804a56bd14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -41,68 +41,100 @@ type richLogger struct {
} }
func (l *richLogger) Debug(v ...any) { func (l *richLogger) Debug(v ...any) {
if shallLog(DebugLevel) {
l.debug(fmt.Sprint(v...)) l.debug(fmt.Sprint(v...))
} }
}
func (l *richLogger) Debugf(format string, v ...any) { func (l *richLogger) Debugf(format string, v ...any) {
if shallLog(DebugLevel) {
l.debug(fmt.Sprintf(format, v...)) l.debug(fmt.Sprintf(format, v...))
} }
}
func (l *richLogger) Debugv(v any) { func (l *richLogger) Debugv(v any) {
if shallLog(DebugLevel) {
l.debug(v) l.debug(v)
} }
}
func (l *richLogger) Debugw(msg string, fields ...LogField) { func (l *richLogger) Debugw(msg string, fields ...LogField) {
if shallLog(DebugLevel) {
l.debug(msg, fields...) l.debug(msg, fields...)
} }
}
func (l *richLogger) Error(v ...any) { func (l *richLogger) Error(v ...any) {
if shallLog(ErrorLevel) {
l.err(fmt.Sprint(v...)) l.err(fmt.Sprint(v...))
} }
}
func (l *richLogger) Errorf(format string, v ...any) { func (l *richLogger) Errorf(format string, v ...any) {
if shallLog(ErrorLevel) {
l.err(fmt.Sprintf(format, v...)) l.err(fmt.Sprintf(format, v...))
} }
}
func (l *richLogger) Errorv(v any) { func (l *richLogger) Errorv(v any) {
if shallLog(ErrorLevel) {
l.err(v) l.err(v)
} }
}
func (l *richLogger) Errorw(msg string, fields ...LogField) { func (l *richLogger) Errorw(msg string, fields ...LogField) {
if shallLog(ErrorLevel) {
l.err(msg, fields...) l.err(msg, fields...)
} }
}
func (l *richLogger) Info(v ...any) { func (l *richLogger) Info(v ...any) {
if shallLog(InfoLevel) {
l.info(fmt.Sprint(v...)) l.info(fmt.Sprint(v...))
} }
}
func (l *richLogger) Infof(format string, v ...any) { func (l *richLogger) Infof(format string, v ...any) {
if shallLog(InfoLevel) {
l.info(fmt.Sprintf(format, v...)) l.info(fmt.Sprintf(format, v...))
} }
}
func (l *richLogger) Infov(v any) { func (l *richLogger) Infov(v any) {
if shallLog(InfoLevel) {
l.info(v) l.info(v)
} }
}
func (l *richLogger) Infow(msg string, fields ...LogField) { func (l *richLogger) Infow(msg string, fields ...LogField) {
if shallLog(InfoLevel) {
l.info(msg, fields...) l.info(msg, fields...)
} }
}
func (l *richLogger) Slow(v ...any) { func (l *richLogger) Slow(v ...any) {
if shallLog(ErrorLevel) {
l.slow(fmt.Sprint(v...)) l.slow(fmt.Sprint(v...))
} }
}
func (l *richLogger) Slowf(format string, v ...any) { func (l *richLogger) Slowf(format string, v ...any) {
if shallLog(ErrorLevel) {
l.slow(fmt.Sprintf(format, v...)) l.slow(fmt.Sprintf(format, v...))
} }
}
func (l *richLogger) Slowv(v any) { func (l *richLogger) Slowv(v any) {
if shallLog(ErrorLevel) {
l.slow(v) l.slow(v)
} }
}
func (l *richLogger) Sloww(msg string, fields ...LogField) { func (l *richLogger) Sloww(msg string, fields ...LogField) {
if shallLog(ErrorLevel) {
l.slow(msg, fields...) l.slow(msg, fields...)
} }
}
func (l *richLogger) WithCallerSkip(skip int) Logger { func (l *richLogger) WithCallerSkip(skip int) Logger {
if skip <= 0 { if skip <= 0 {

Loading…
Cancel
Save