mlog

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClearOpt

type ClearOpt struct {
	Type   []string // 要删除的日志类型,为空则删除全部类型
	Before int      // 保留多少天之前的日志会被删除(天数),为空或<=0 则默认90
}

ClearOpt 表示清理日志的参数。

type Config

type Config struct {
	Path string
	Name string
}

Config 用于构造 Logger 的配置。

type Logger

type Logger struct {
	Path string // 存放日志的目录,默认为 ./logs
	Name string // 日志名称,默认为 log
	// contains filtered or unexported fields
}

Logger 是简单日志器的实例。它负责根据名称、类型和日期将日志写入文件。

func New

func New(cfg Config) *Logger

New 根据传入的配置创建并返回一个 Logger 实例。 如果 Path 为空则使用 ./logs;如果 Name 为空则使用 log。

func (*Logger) Clear

func (l *Logger) Clear(opt ClearOpt)

Clear 按配置删除匹配的历史日志文件。 - Type: 指定要删除的类型(info,warn,error,debug),为空则删除全部类型 - Before: 距离现在的天数,默认 90 天,删除早于该天数的日志文件

func (*Logger) Debug

func (l *Logger) Debug(v ...any) error

Debug 写一条 debug 级别的日志。

func (*Logger) Error

func (l *Logger) Error(v ...any) error

Error 写一条 error 级别的日志。

func (*Logger) Info

func (l *Logger) Info(v ...any) error

Info 写一条 info 级别的日志。

func (*Logger) Warn

func (l *Logger) Warn(v ...any) error

Warn 写一条 warn 级别的日志。

Jump to

Keyboard shortcuts

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