lckt-server/initialize/internal/gorm_logger_writer.go
2025-04-09 12:17:33 +08:00

42 lines
946 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package internal
import (
"fmt"
"git.echol.cn/loser/lckt/config"
"git.echol.cn/loser/lckt/global"
"gorm.io/gorm/logger"
)
type Writer struct {
config config.GeneralDB
writer logger.Writer
}
func NewWriter(config config.GeneralDB) *Writer {
return &Writer{config: config}
}
// Printf 格式化打印日志
func (c *Writer) Printf(message string, data ...any) {
// 当有日志时候均需要输出到控制台
fmt.Printf(message, data...)
// 当开启了zap的情况会打印到日志记录
if c.config.LogZap {
switch c.config.LogLevel() {
case logger.Silent:
global.GVA_LOG.Debug(fmt.Sprintf(message, data...))
case logger.Error:
global.GVA_LOG.Error(fmt.Sprintf(message, data...))
case logger.Warn:
global.GVA_LOG.Warn(fmt.Sprintf(message, data...))
case logger.Info:
global.GVA_LOG.Info(fmt.Sprintf(message, data...))
default:
global.GVA_LOG.Info(fmt.Sprintf(message, data...))
}
return
}
}