Help us shape the future of Go! Take the 2026 Go Developer Survey

logger

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Configure added in v0.1.4

func Configure(opts Options)

Configure 使用给定参数重新配置全局日志。

优先级(低 → 高):

  1. Options 传入的取值(通常来自 config.yml 的 log 段)
  2. LOG_LEVEL / LOG_PATH 环境变量

可重复调用(例如加载 config.yml 之后),每次都会关闭旧的日志文件句柄。

func ConfigureFromEnv

func ConfigureFromEnv()

ConfigureFromEnv 使用环境变量重新配置日志(向后兼容入口)。 这允许在 main() 中加载 .env 后,让 LOG_LEVEL / LOG_PATH 立即生效。

func Debugf

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

Debugf 使用格式化字符串输出调试级别的日志

func Error

func Error(c context.Context, args ...interface{})

Error 输出错误级别的日志

func ErrorWithFields

func ErrorWithFields(c context.Context, err error, fields logrus.Fields)

ErrorWithFields 输出带有额外字段的错误级别日志

func Errorf

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

Errorf 使用格式化字符串输出错误级别的日志

func Fatalf

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

Fatalf 使用格式化字符串输出致命级别的日志并退出程序

func GetLogger

func GetLogger(c context.Context) *logrus.Entry

GetLogger 获取日志实例

func Info

func Info(c context.Context, args ...interface{})

Info 输出信息级别的日志

func Infof

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

Infof 使用格式化字符串输出信息级别的日志

func LevelFromString added in v0.1.4

func LevelFromString(s string) logrus.Level

LevelFromString 把字符串解析为 logrus.Level。 支持 trace/debug/info/warn(warning)/error/fatal/panic; 空值或未识别的取值返回默认级别。

func Warn

func Warn(c context.Context, args ...interface{})

Warn 输出警告级别的日志

func Warnf

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

Warnf 使用格式化字符串输出警告级别的日志

Types

type CustomFormatter

type CustomFormatter struct {
	ForceColor bool // 是否强制使用颜色,即使在非终端环境下
}

func (*CustomFormatter) Format

func (f *CustomFormatter) Format(entry *logrus.Entry) ([]byte, error)

type Options added in v0.1.4

type Options struct {
	// Level 日志级别:trace/debug/info/warn/error/fatal/panic。
	Level string
	// Path 日志文件路径;为空时回退到默认路径(logs/app.log)。
	Path string
	// Color 颜色模式:auto(默认,仅终端着色)/always/never。
	Color string
}

Options 描述一次日志重新配置所需的参数。 它由 config.yml 的 log 段映射而来,所有字段都可省略。

Jump to

Keyboard shortcuts

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