Files
bl/logic/service/common/log.go
xinian d83cf365ac
Some checks failed
ci/woodpecker/push/my-first-workflow Pipeline failed
更新说明
2026-04-05 23:13:06 +08:00

32 lines
645 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 common
import (
"blazing/cool"
"blazing/modules/base/service"
"github.com/gogf/gf/v2/os/glog"
)
// MyWriter 自定义日志写入器,用于逻辑服日志转发。
type MyWriter struct {
logger *glog.Logger // 底层 glog 实例。
user uint32 // 关联的玩家 ID。
}
// Write 实现 io.Writer并将日志写入系统日志与底层 logger。
func (w *MyWriter) Write(p []byte) (n int, err error) {
var (
s = string(p)
)
service.NewBaseSysLogService().RecordLog(w.user, s)
return w.logger.Write(p)
}
func init() {
cool.Logger.SetWriter(&MyWriter{
logger: glog.New(),
})
cool.Logger.SetAsync(true)
}