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

Loading…
Cancel
Save