mlog

package
v1.12.25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LOG_TRACE   = 1
	LOG_DEBUG   = 2
	LOG_WARN    = 3
	LOG_INFO    = 4
	LOG_ERROR   = 5
	LOG_FATAL   = 6
	FORMAT_LINE = 1
	FORMAT_JSON = 2
)

Variables

This section is empty.

Functions

func Debug

func Debug(args ...any)

func Debugf

func Debugf(format string, args ...any)

func Error

func Error(args ...any)

func Errorf

func Errorf(format string, args ...any)

Errorf 记录ERROR级别格式化日志

func Fatal

func Fatal(args ...any)

func Fatalf

func Fatalf(format string, args ...any)

Fatalf 记录FATAL级别格式化日志

func Info

func Info(args ...any)

func Infof

func Infof(format string, args ...any)

Infof 记录INFO级别格式化日志

func Level2Name

func Level2Name(level int32) string

func Name2Format

func Name2Format(f string) int32

func Name2Level

func Name2Level(name string) int32

func Output

func Output(skip int, level int32, tag string, args ...any)

func Outputf

func Outputf(skip int, level int32, tag, format string, args ...any)

func SetCaller

func SetCaller(val bool)

func SetFormat

func SetFormat(f int32)

func SetLevel

func SetLevel(level int32)

func SetObject

func SetObject(oj *Logger)

func Trace

func Trace(args ...any)

func Tracef

func Tracef(format string, args ...any)

func Warn

func Warn(args ...any)

func Warnf

func Warnf(format string, args ...any)

Warnf 记录WARN级别格式化日志

Types

type Component

type Component struct {
	Config *Config
	// contains filtered or unexported fields
}

func (*Component) Close

func (d *Component) Close()

func (*Component) Init

func (d *Component) Init() error

type Config

type Config struct {
	Mode      string `yaml:"mode,omitempty"`   // 日志模式(debug/release)
	Path      string `yaml:"path,omitempty"`   // 日志文件路径
	Level     string `yaml:"level,omitempty"`  // 日志级别
	Format    string `yaml:"format,omitempty"` // 日志格式(text/json)
	Name      string `yaml:"name,omitempty"`   // 日志名称
	IsCaller  bool   `yaml:"is_caller"`        // 是否开启runtime输出
	CacheSize int    `yaml:"cache_size"`       // 缓存大小
}

type Data

type Data struct {
	// contains filtered or unexported fields
}

type Entry

type Entry struct {
	TS    string `json:"ts,omitempty"`
	Level string `json:"level,omitempty"`
	File  string `json:"file,omitempty"`
	Tag   string `json:"tag,omitempty"`
	Msg   any    `json:"msg,omitempty"`
}

jsonLogEntry JSON 日志条目结构(sonic 零分配序列化)

type GroupWriter

type GroupWriter struct {
	// contains filtered or unexported fields
}

func (*GroupWriter) Close

func (w *GroupWriter) Close() (err error)

func (*GroupWriter) Write

func (w *GroupWriter) Write(now time.Time, msg []byte) (n int, err error)

type IWriter

type IWriter interface {
	Write(time.Time, []byte) (int, error)
	Close() error
}

IWriter 写入器接口

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger() *Logger

NewLogger 创建新的日志记录器

func (*Logger) Close

func (l *Logger) Close()

func (*Logger) Init

func (l *Logger) Init(cfg *Config) error

func (*Logger) Output

func (l *Logger) Output(skip int, level int32, tag string, args ...any)

func (*Logger) Outputf

func (l *Logger) Outputf(skip int, level int32, tag string, format string, args ...any)

func (*Logger) SetCaller

func (l *Logger) SetCaller(val bool)

func (*Logger) SetFormat

func (l *Logger) SetFormat(f int32)

func (*Logger) SetLevel

func (l *Logger) SetLevel(level int32)

type RollingStrategy

type RollingStrategy int

RollingStrategy 日志滚动策略

const (
	RollingByHour RollingStrategy = iota // 按小时滚动
	RollingByDay                         // 按天滚动
)

type RotateWriter

type RotateWriter struct {
	// contains filtered or unexported fields
}

RotateWriter 按小时滚动的日志写入器

func NewRotateWriter

func NewRotateWriter(lpath, lname string, bufferSize int, flushInterval time.Duration, val RollingStrategy) *RotateWriter

New 创建按小时滚动的日志写入器

func (*RotateWriter) Close

func (d *RotateWriter) Close() error

Close 关闭写入器

func (*RotateWriter) Write

func (d *RotateWriter) Write(now time.Time, p []byte) (n int, err error)

Write 写入日志数据

type StdoutWriter

type StdoutWriter struct{}

func (*StdoutWriter) Close

func (w *StdoutWriter) Close() error

func (*StdoutWriter) Write

func (w *StdoutWriter) Write(t time.Time, p []byte) (n int, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL