2022-12-09 00:40:50 +01:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/gin-gonic/gin"
|
2024-09-20 20:56:22 +02:00
|
|
|
"github.com/rs/zerolog"
|
2022-12-09 00:40:50 +01:00
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
var buflogger *BufferWriter = nil
|
|
|
|
|
|
|
|
func SetBufLogger() {
|
|
|
|
buflogger = &BufferWriter{cw: createConsoleWriter()}
|
|
|
|
log.Logger = createLogger(buflogger)
|
|
|
|
gin.SetMode(gin.ReleaseMode)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ClearBufLogger(dump bool) {
|
|
|
|
size := len(buflogger.buffer)
|
|
|
|
if dump {
|
|
|
|
buflogger.Dump()
|
|
|
|
}
|
|
|
|
log.Logger = createLogger(createConsoleWriter())
|
|
|
|
buflogger = nil
|
|
|
|
gin.SetMode(gin.TestMode)
|
|
|
|
if !dump {
|
|
|
|
log.Info().Msgf("Suppressed %d logmessages / printf-statements", size)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-20 20:56:22 +02:00
|
|
|
func TPrintf(lvl zerolog.Level, format string, a ...any) {
|
|
|
|
if zerolog.GlobalLevel() <= lvl {
|
|
|
|
if buflogger != nil {
|
|
|
|
buflogger.Printf(format, a...)
|
|
|
|
} else {
|
|
|
|
fmt.Printf(format, a...)
|
|
|
|
}
|
2022-12-09 00:40:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-20 20:56:22 +02:00
|
|
|
func TPrintln(lvl zerolog.Level, a ...any) {
|
|
|
|
if zerolog.GlobalLevel() <= lvl {
|
|
|
|
if buflogger != nil {
|
|
|
|
buflogger.Println(a...)
|
|
|
|
} else {
|
|
|
|
fmt.Println(a...)
|
|
|
|
}
|
2022-12-09 00:40:50 +01:00
|
|
|
}
|
|
|
|
}
|