logger

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultFilename               = "./logs/app.log"
	DebugLevel      zapcore.Level = iota - 1
	InfoLevel
	WarnLevel
	ErrorLevel
)

Variables

This section is empty.

Functions

func Debug

func Debug(msg string, fields ...zap.Field)

以下是一些便捷方法

func Error

func Error(msg string, fields ...zap.Field)

func Fatal

func Fatal(msg string, fields ...zap.Field)

func Info

func Info(msg string, fields ...zap.Field)

func LevelToString

func LevelToString(l zapcore.Level) string

LevelToString 将自定义级别转换为字符串

func Warn

func Warn(msg string, fields ...zap.Field)

Types

type LoggerComponent

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

LoggerComponent 日志组件

func NewLoggerComponent

func NewLoggerComponent(opts ...LoggerOption) *LoggerComponent

NewLoggerComponent 创建日志组件

func (*LoggerComponent) GetLogger

func (l *LoggerComponent) GetLogger() *zap.Logger

func (*LoggerComponent) Start

func (l *LoggerComponent) Start() error

Start 启动日志组件

type LoggerConfig

type LoggerConfig struct {
	Level      string // debug, info, warn, error
	IsStdout   bool   // 是否输出到控制台
	IsFile     bool   // 是否输出到文件
	Filename   string // 日志文件名
	MaxSize    int    // MB
	MaxBackups int    // 最大备份数
	MaxAge     int    // 天
	Compress   bool   // 是否压缩
}

LoggerConfig 日志配置

type LoggerOption

type LoggerOption func(*LoggerComponent)

LoggerOption 定义日志选项函数类型

func WithLoggerCompress

func WithLoggerCompress(compress bool) LoggerOption

WithLoggerCompress 设置是否压缩

func WithLoggerFilename

func WithLoggerFilename(filename string) LoggerOption

WithLoggerFilename 设置日志文件名

func WithLoggerIsFile

func WithLoggerIsFile(isFile bool) LoggerOption

WithLoggerIsFile 设置是否输出到文件

func WithLoggerLevel

func WithLoggerLevel(level string) LoggerOption

WithLoggerLevel 设置日志级别

func WithLoggerMaxAge

func WithLoggerMaxAge(maxAge int) LoggerOption

WithLoggerMaxAge 设置最大保留天数

func WithLoggerMaxBackups

func WithLoggerMaxBackups(maxBackups int) LoggerOption

WithLoggerMaxBackups 设置最大备份数

func WithLoggerMaxSize

func WithLoggerMaxSize(maxSize int) LoggerOption

WithLoggerMaxSize 设置日志文件最大大小

func WithLoggerStdout

func WithLoggerStdout(isStdout bool) LoggerOption

WithLoggerStdout 设置是否输出到控制台

Jump to

Keyboard shortcuts

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