feat: add log debug level (#2411)

This commit is contained in:
MarkJoyMa
2022-09-20 07:50:11 +08:00
committed by GitHub
parent 4c927624b0
commit e6aa6fc361
8 changed files with 153 additions and 3 deletions

View File

@@ -64,6 +64,26 @@ func Close() error {
return nil
}
// Debug writes v into access log.
func Debug(v ...interface{}) {
writeDebug(fmt.Sprint(v...))
}
// Debugf writes v with format into access log.
func Debugf(format string, v ...interface{}) {
writeDebug(fmt.Sprintf(format, v...))
}
// Debugv writes v into access log with json content.
func Debugv(v interface{}) {
writeDebug(v)
}
// Debugw writes msg along with fields into access log.
func Debugw(msg string, fields ...LogField) {
writeDebug(msg, fields...)
}
// Disable disables the logging.
func Disable() {
atomic.StoreUint32(&disableLog, 1)
@@ -352,6 +372,8 @@ func handleOptions(opts []LogOption) {
func setupLogLevel(c LogConf) {
switch c.Level {
case levelDebug:
SetLevel(DebugLevel)
case levelInfo:
SetLevel(InfoLevel)
case levelError:
@@ -392,6 +414,12 @@ func shallLogStat() bool {
return atomic.LoadUint32(&disableStat) == 0
}
func writeDebug(val interface{}, fields ...LogField) {
if shallLog(DebugLevel) {
getWriter().Debug(val, addCaller(fields...)...)
}
}
func writeError(val interface{}, fields ...LogField) {
if shallLog(ErrorLevel) {
getWriter().Error(val, addCaller(fields...)...)