zaploger

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Auto2Field

func Auto2Field(data ...any) []zap.Field

Auto2Field 自动将数据转换为zap.Field

Types

type Config

type Config struct {
	ConsoleSeparator string               `json:"console_separator" yaml:"console_separator" ini:"console_separator"` // 控制台分隔符
	LogFormat        string               `json:"log_format" yaml:"log_format" ini:"log_format"`                      // 日志格式 默认普通控制台格式,支持json格式
	LogLevel         string               `json:"log_level" yaml:"log_level" ini:"log_level"`
	LogLevelConfigs  map[string]LogConfig `json:"log_level_configs" yaml:"log_level_configs" ini:"log_level_configs"` // key is log level, value is its configuration
}

Config holds the application configuration.

func (*Config) Scan

func (c *Config) Scan(val any) error

func (Config) Value

func (c Config) Value() (driver.Value, error)

type LogConfig

type LogConfig struct {
	FileName   string `json:"file_name" yaml:"file_name" int:"file_name"`       // 日志文件名称
	FilePath   string `json:"file_path" yaml:"file_path" int:"file_path"`       // 日志路径
	MaxSize    int    `json:"max_size" yaml:"max_size" int:"max_size"`          // 文件最大容量 单位MB
	MaxBackups int    `json:"max_backups" yaml:"max_backups" int:"max_backups"` // 文件最多数量
	MaxAge     int    `json:"max_age" yaml:"max_age" int:"max_age"`             // 日志保留最大时长 单位天,0为不限制
	Compress   bool   `json:"compress" yaml:"compress" int:"compress"`          // 是否压缩
	ToStdout   bool   `json:"to_stdout" yaml:"to_stdout" ini:"to_stdout"`       // 是否输出到标准输出
}

LogConfig defines the configuration for each log level.

type Logger

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

Logger implements the gorm.Logger interface.

func New

func New(cfg *Config) (*Logger, error)

New creates a new instance of Logger with given configuration.

func (*Logger) Debug

func (l *Logger) Debug(ctx context.Context, msg string, data ...any)

func (*Logger) Error

func (l *Logger) Error(ctx context.Context, msg string, data ...any)

func (*Logger) Info

func (l *Logger) Info(ctx context.Context, msg string, data ...any)

func (*Logger) LogMode

func (l *Logger) LogMode(level logger.LogLevel) logger.Interface

func (*Logger) Trace

func (l *Logger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

func (*Logger) Warn

func (l *Logger) Warn(ctx context.Context, msg string, data ...any)

Jump to

Keyboard shortcuts

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