You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ntool-biz/zero/logz/logz.go

59 lines
1.3 KiB
Go

1 year ago
package logz
import (
"fmt"
"git.noahlan.cn/noahlan/ntool/nlog"
"github.com/zeromicro/go-zero/core/logx"
)
type NLogWriter struct {
}
func NewWriter() logx.Writer {
return &NLogWriter{}
}
func (w *NLogWriter) Alert(v any) {
nlog.Alert(fmt.Sprintf("%s", v))
}
func (w *NLogWriter) Close() error {
return nlog.GetWriter().Close()
}
func (w *NLogWriter) Debug(v any, fields ...logx.LogField) {
nlog.GetWriter().Debug(v, toNLogField(fields...)...)
}
func (w *NLogWriter) Error(v any, fields ...logx.LogField) {
nlog.GetWriter().Error(v, toNLogField(fields...)...)
}
func (w *NLogWriter) Info(v any, fields ...logx.LogField) {
nlog.GetWriter().Info(v, toNLogField(fields...)...)
}
func (w *NLogWriter) Severe(v any) {
nlog.GetWriter().Severe(v)
}
func (w *NLogWriter) Slow(v any, fields ...logx.LogField) {
nlog.GetWriter().Slow(v, toNLogField(fields...)...)
}
func (w *NLogWriter) Stack(v any) {
nlog.GetWriter().Stack(v)
}
func (w *NLogWriter) Stat(v any, fields ...logx.LogField) {
nlog.GetWriter().Stat(v, toNLogField(fields...)...)
}
func toNLogField(fields ...logx.LogField) []nlog.LogField {
zapFields := make([]nlog.LogField, 0, len(fields))
for _, f := range fields {
zapFields = append(zapFields, nlog.Field(f.Key, f.Value))
}
return zapFields
}