changeset 5492:b4f59aef3f9e logging

Use correct calldepth for logging.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 20 Sep 2021 18:09:38 +0200
parents 09346efa7f69
children 0cd4ff1066fe
files pkg/log/log.go
diffstat 1 files changed, 16 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/log/log.go	Mon Sep 20 18:02:09 2021 +0200
+++ b/pkg/log/log.go	Mon Sep 20 18:09:38 2021 +0200
@@ -43,6 +43,8 @@
 	lg.SetFlags(lg.LstdFlags | lg.Lshortfile)
 }
 
+const callDepth = 2
+
 func SetupLog(filename string, perm os.FileMode) error {
 	f, err := os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, perm)
 	if err != nil {
@@ -117,90 +119,90 @@
 func Tracef(f string, args ...interface{}) {
 	if TraceLogLevel >= GetLogLevel() {
 		s := fmt.Sprintf(f, args...)
-		lg.Output(4, "[TRACE] "+s)
+		lg.Output(callDepth, "[TRACE] "+s)
 	}
 }
 
 func Traceln(s string) {
 	if TraceLogLevel >= GetLogLevel() {
-		lg.Output(4, "[TRACE] "+s)
+		lg.Output(callDepth, "[TRACE] "+s)
 	}
 }
 
 func Debugf(f string, args ...interface{}) {
 	if DebugLogLevel >= GetLogLevel() {
 		s := fmt.Sprintf(f, args...)
-		lg.Output(4, "[DEBUG] "+s)
+		lg.Output(callDepth, "[DEBUG] "+s)
 	}
 }
 
 func Debugln(s string) {
 	if DebugLogLevel >= GetLogLevel() {
-		lg.Output(4, "[DEBUG] "+s)
+		lg.Output(callDepth, "[DEBUG] "+s)
 	}
 }
 
 func Infof(f string, args ...interface{}) {
 	if InfoLogLevel >= GetLogLevel() {
 		s := fmt.Sprintf(f, args...)
-		lg.Output(4, "[INFO] "+s)
+		lg.Output(callDepth, "[INFO] "+s)
 	}
 }
 
 func Infoln(s string) {
 	if InfoLogLevel >= GetLogLevel() {
-		lg.Output(4, "[INFO] "+s)
+		lg.Output(callDepth, "[INFO] "+s)
 	}
 }
 
 func Warnf(f string, args ...interface{}) {
 	if WarnLogLevel >= GetLogLevel() {
 		s := fmt.Sprintf(f, args...)
-		lg.Output(4, "[WARN] "+s)
+		lg.Output(callDepth, "[WARN] "+s)
 	}
 }
 
 func Warnln(s string) {
 	if WarnLogLevel >= GetLogLevel() {
-		lg.Output(4, "[WARN] "+s)
+		lg.Output(callDepth, "[WARN] "+s)
 	}
 }
 
 func Errorf(f string, args ...interface{}) {
 	if ErrorLogLevel >= GetLogLevel() {
 		s := fmt.Sprintf(f, args...)
-		lg.Output(4, "[ERROR] "+s)
+		lg.Output(callDepth, "[ERROR] "+s)
 	}
 }
 
 func Errorln(s string) {
 	if ErrorLogLevel >= GetLogLevel() {
-		lg.Output(4, "[ERROR] "+s)
+		lg.Output(callDepth, "[ERROR] "+s)
 	}
 }
 
 func Fatalf(f string, args ...interface{}) {
 	if FatalLogLevel >= GetLogLevel() {
 		s := fmt.Sprintf(f, args...)
-		lg.Output(4, "[FATAL] "+s)
+		lg.Output(callDepth, "[FATAL] "+s)
 		os.Exit(1)
 	}
 }
 
 func Fatalln(s string) {
 	if FatalLogLevel >= GetLogLevel() {
-		lg.Output(4, "[FATAL] "+s)
+		lg.Output(callDepth, "[FATAL] "+s)
 		os.Exit(1)
 	}
 }
 
 func Panicf(f string, args ...interface{}) {
 	s := fmt.Sprintf(f, args...)
-	lg.Output(4, "[PANIC] "+s)
+	lg.Output(callDepth, "[PANIC] "+s)
 	panic(s)
 }
 
 func Panicln(s string) {
-	lg.Output(4, "[PANIC] "+s)
+	lg.Output(callDepth, "[PANIC] "+s)
 	panic(s)
 }