SimpleCloudNotifier/scnserver/test/util/log.go
Mike Schwörer b3ce926309
Some checks failed
Build Docker and Deploy / Build Docker Container (push) Successful in 1m19s
Build Docker and Deploy / Run Unit-Tests (push) Failing after 2m36s
Build Docker and Deploy / Deploy to Server (push) Has been skipped
Fis test pipeline
2024-09-20 21:14:40 +02:00

50 lines
952 B
Go

package util
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog"
"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)
}
}
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...)
}
}
}
func TPrintln(lvl zerolog.Level, a ...any) {
if zerolog.GlobalLevel() <= lvl {
if buflogger != nil {
buflogger.Println(a...)
} else {
fmt.Println(a...)
}
}
}