logs

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Reset      = "\033[0m"
	Bold       = "\033[1m"
	Red        = "\033[31m"
	Green      = "\033[32m"
	Yellow     = "\033[33m"
	Blue       = "\033[34m"
	Purple     = "\033[35m"
	Cyan       = "\033[36m"
	White      = "\033[37m"
	BoldRed    = "\033[1;31m"
	BoldGreen  = "\033[1;32m"
	BoldYellow = "\033[1;33m"
	BoldBlue   = "\033[1;34m"
	BoldPurple = "\033[1;35m"
	BoldCyan   = "\033[1;36m"
	BoldWhite  = "\033[1;37m"
)

ANSI 颜色代码

Variables

This section is empty.

Functions

func Debug added in v1.0.8

func Debug(args ...interface{})

Debug 全局 Debug 日志

func Debugf added in v1.0.8

func Debugf(format string, args ...interface{})

func Error added in v1.0.8

func Error(args ...interface{})

Error 全局 Error 日志

func Errorf added in v1.0.8

func Errorf(format string, args ...interface{})

func Fatal added in v1.0.8

func Fatal(args ...interface{})

Fatal 全局 Fatal 日志

func Fatalf added in v1.0.8

func Fatalf(format string, args ...interface{})

func Info added in v1.0.8

func Info(args ...interface{})

Info 全局 Info 日志

func Infof added in v1.0.8

func Infof(format string, args ...interface{})

func SetLogger added in v1.0.8

func SetLogger(logger *Log)

SetLogger 设置全局日志实例

func Warn added in v1.0.8

func Warn(args ...interface{})

Warn 全局 Warn 日志

func Warnf added in v1.0.8

func Warnf(format string, args ...interface{})

Types

type CallerInfo added in v1.0.8

type CallerInfo struct {
	File     string
	Line     int
	Function string
}

CallerInfo 调用者信息

type Config added in v1.0.8

type Config struct {
	Level      Level     `json:"level"`       // 日志级别
	FilePath   string    `json:"file_path"`   // 日志文件路径
	MaxSize    int64     `json:"max_size"`    // 单个日志文件最大大小(MB)
	MaxAge     int       `json:"max_age"`     // 日志保留天数
	Compress   bool      `json:"compress"`    // 是否压缩
	Formatter  Formatter `json:"formatter"`   // 日志格式化器
	ForceColor bool      `json:"force_color"` // 强制启用颜色
	NoColor    bool      `json:"no_color"`    // 禁用颜色
	Console    bool      `json:"console"`     // 是否输出到控制台
}

Config 日志配置

type Formatter added in v1.0.8

type Formatter interface {
	Format(level Level, msg string, caller *CallerInfo) string
}

Formatter 日志格式化器接口

type JSONFormatter added in v1.0.8

type JSONFormatter struct {
	TimeFormat string
}

JSONFormatter JSON格式化器

func NewJSONFormatter added in v1.0.8

func NewJSONFormatter() *JSONFormatter

func (*JSONFormatter) Format added in v1.0.8

func (f *JSONFormatter) Format(level Level, msg string, caller *CallerInfo) string

type Level added in v1.0.8

type Level int

Level 日志级别

const (
	DebugLevel Level = iota
	InfoLevel
	WarnLevel
	ErrorLevel
	FatalLevel
)

func ParseLevel added in v1.0.8

func ParseLevel(level string) Level

ParseLevel 从字符串解析日志级别

func (Level) String added in v1.0.8

func (l Level) String() string

String 返回日志级别的字符串表示

type Log added in v1.0.8

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

func GetLogger added in v1.0.8

func GetLogger() *Log

GetLogger 获取全局日志实例

func NewLogger added in v1.0.8

func NewLogger(config *Config) (*Log, error)

NewLogger 创建日志记录器

func (*Log) Close added in v1.0.8

func (l *Log) Close() error

Close 关闭日志

func (*Log) Debug added in v1.0.8

func (l *Log) Debug(args ...interface{})

Debug 级别日志

func (*Log) Debugf added in v1.0.8

func (l *Log) Debugf(format string, args ...interface{})

func (*Log) Error added in v1.0.8

func (l *Log) Error(args ...interface{})

Error 级别日志

func (*Log) Errorf added in v1.0.8

func (l *Log) Errorf(format string, args ...interface{})

func (*Log) Fatal added in v1.0.8

func (l *Log) Fatal(args ...interface{})

Fatal 级别日志

func (*Log) Fatalf added in v1.0.8

func (l *Log) Fatalf(format string, args ...interface{})

func (*Log) GetLevel added in v1.0.8

func (l *Log) GetLevel() Level

func (*Log) Info added in v1.0.8

func (l *Log) Info(args ...interface{})

Info 级别日志

func (*Log) Infof added in v1.0.8

func (l *Log) Infof(format string, args ...interface{})

func (*Log) SetLevel added in v1.0.8

func (l *Log) SetLevel(level Level)

func (*Log) SetOutput added in v1.0.8

func (l *Log) SetOutput(path string) error

SetOutput 设置日志输出

func (*Log) Warn added in v1.0.8

func (l *Log) Warn(args ...interface{})

Warn 级别日志

func (*Log) Warnf added in v1.0.8

func (l *Log) Warnf(format string, args ...interface{})

type Logger added in v1.0.8

type Logger interface {
	// 基础日志方法
	Debug(args ...interface{})
	Info(args ...interface{})
	Warn(args ...interface{})
	Error(args ...interface{})
	Fatal(args ...interface{})

	// 格式化日志方法
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warnf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})

	// 设置日志级别
	SetLevel(level Level)
	// 获取日志级别
	GetLevel() Level
}

Logger 日志接口

type Rotator added in v1.0.8

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

Rotator 日志轮转器

func NewRotator added in v1.0.8

func NewRotator(config *Config, log *Log) *Rotator

NewRotator 创建日志轮转器

func (*Rotator) Clean added in v1.0.8

func (r *Rotator) Clean() error

Clean 清理旧日志

func (*Rotator) Rotate added in v1.0.8

func (r *Rotator) Rotate() error

Rotate 执行日志轮转

type TextFormatter added in v1.0.8

type TextFormatter struct {
	// 时间格式
	TimeFormat string
	// 是否显示完整路径
	FullPath   bool
	ForceColor bool // 强制启用颜色
	NoColor    bool // 禁用颜色
}

TextFormatter 文本格式化器

func NewTextFormatter added in v1.0.8

func NewTextFormatter() *TextFormatter

func (*TextFormatter) Format added in v1.0.8

func (f *TextFormatter) Format(level Level, msg string, caller *CallerInfo) string

Jump to

Keyboard shortcuts

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