SimpleCloudNotifier/scnserver/test/util/log.go
Mike Schwörer 7546c2a1a4
All checks were successful
Build Docker and Deploy / Build Docker Container (push) Successful in 1m17s
Build Docker and Deploy / Run Unit-Tests (push) Successful in 2m38s
Build Docker and Deploy / Deploy to Server (push) Successful in 9s
Fix test pipeline
2024-09-20 21:23:26 +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...)
}
}
}