logger

package
v0.0.0-...-6819526 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: BSD-3-Clause Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(msg string, keysAndValues ...any)

func Debugf

func Debugf(template string, args ...any)

func Error

func Error(msg string, keysAndValues ...any)

func Errorf

func Errorf(template string, args ...any)

func Info

func Info(msg string, keysAndValues ...any)

func Infof

func Infof(template string, args ...any)

func InitSlog

func InitSlog(handlers ...slog.Handler)

func InitZapLogger

func InitZapLogger(conf Config)

func Panic

func Panic(msg string, keysAndValues ...any)

func Panicf

func Panicf(template string, args ...any)

func SetLogger

func SetLogger(l ILogger)

Types

type Config

type Config struct {
	Level      string `mapstructure:"level"`
	LevelCh    chan LogLevel
	TimeFormat string `mapstructure:"timeFormat"`

	// 完整的文件路径名
	Filepath        string `mapstructure:"filepath"`
	Filename        string `mapstructure:"filename"`
	FilenameSuffix  string `mapstructure:"filenameSuffix"`
	FileExtension   string `mapstructure:"fileExtension"`
	FileJsonEncoder bool   `mapstructure:"fileJsonEncoder"`

	FileMaxSize  uint16 `mapstructure:"fileSizeMax"`  // 单位是MB 默认值是 10MB
	FileMaxAge   uint16 `mapstructure:"fileAgeMax"`   // 留存天数
	FileCompress bool   `mapstructure:"fileCompress"` // 是否归档压缩
}

func NewConfig

func NewConfig(opts ...Option) Config

func (*Config) AddFlags

func (c *Config) AddFlags(fs *pflag.FlagSet)

func (*Config) SetLevel

func (c *Config) SetLevel(level LogLevel)

func (*Config) Validate

func (c *Config) Validate() []error

type ILogger

type ILogger interface {
	Panic(msg string, keysAndValues ...any)
	Panicf(format string, args ...any)
	Panicc(ctx context.Context, msg string, keysAndValues ...any)
	Paniccf(ctx context.Context, format string, args ...any)

	Error(msg string, keysAndValues ...any)
	Errorf(format string, args ...any)
	Errorc(ctx context.Context, msg string, keysAndValues ...any)
	Errorcf(ctx context.Context, format string, args ...any)

	Info(msg string, keysAndValues ...any)
	Infof(format string, args ...any)
	Infoc(ctx context.Context, msg string, keysAndValues ...any)
	Infocf(ctx context.Context, format string, args ...any)

	Debug(msg string, keysAndValues ...any)
	Debugf(format string, args ...any)
	Debugc(ctx context.Context, msg string, keysAndValues ...any)
	Debugcf(ctx context.Context, format string, args ...any)
}

type LogLevel

type LogLevel string
const (
	LogLevel_Debug LogLevel = "debug"
	LogLevel_Error LogLevel = "error"
	LogLevel_Info  LogLevel = "info"
)

func StringToLevel

func StringToLevel(level string) LogLevel

func (LogLevel) String

func (l LogLevel) String() string

type Option

type Option func(*Config)

func WithFileCompress

func WithFileCompress(compress bool) Option

WithFileCompress 是否归档压缩

func WithFileExtension

func WithFileExtension(fileExtension string) Option

WithFileExtension 文件扩展名 (e.g log、txt)

func WithFileJsonEncoder

func WithFileJsonEncoder(isJsonEncoder bool) Option

WithFileJsonEncoder 输出到文件侧是否启用json格式编码

func WithFileMaxAge

func WithFileMaxAge(maxAge uint16) Option

WithFileMaxAge 文件保留时长

func WithFileMaxSize

func WithFileMaxSize(maxSize uint16) Option

WithFileMaxSize 文件最大多少MB就分割

func WithFilename

func WithFilename(filename string) Option

WithFilename 文件名(文件前缀), 随机部分 main-service-2023-11-04

func WithFilenameSuffix

func WithFilenameSuffix(filenameSuffix string) Option

WithFilenameSuffix 文件后缀名, 随机部分 main-service-2023-11-04

func WithFilepath

func WithFilepath(filepath string) Option

WithFilepath 文件目录路径

func WithLevel

func WithLevel(level LogLevel) Option

WithLevel 日志级别

func WithTimeFormat

func WithTimeFormat(timeFormat string) Option

WithTimeFormat 日志时间格式

type ZapLogger

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

func (*ZapLogger) Debug

func (zl *ZapLogger) Debug(msg string, keysAndValues ...any)

func (*ZapLogger) Debugc

func (zl *ZapLogger) Debugc(ctx context.Context, msg string, keysAndValues ...any)

func (*ZapLogger) Debugcf

func (zl *ZapLogger) Debugcf(ctx context.Context, format string, args ...any)

func (*ZapLogger) Debugf

func (zl *ZapLogger) Debugf(format string, args ...any)

func (*ZapLogger) Error

func (zl *ZapLogger) Error(msg string, keysAndValues ...any)

func (*ZapLogger) Errorc

func (zl *ZapLogger) Errorc(ctx context.Context, msg string, keysAndValues ...any)

func (*ZapLogger) Errorcf

func (zl *ZapLogger) Errorcf(ctx context.Context, format string, args ...any)

func (*ZapLogger) Errorf

func (zl *ZapLogger) Errorf(format string, args ...any)

func (*ZapLogger) Info

func (zl *ZapLogger) Info(msg string, keysAndValues ...any)

func (*ZapLogger) Infoc

func (zl *ZapLogger) Infoc(ctx context.Context, msg string, keysAndValues ...any)

func (*ZapLogger) Infocf

func (zl *ZapLogger) Infocf(ctx context.Context, format string, args ...any)

func (*ZapLogger) Infof

func (zl *ZapLogger) Infof(format string, args ...any)

func (*ZapLogger) Panic

func (zl *ZapLogger) Panic(msg string, keysAndValues ...any)

func (*ZapLogger) Panicc

func (zl *ZapLogger) Panicc(ctx context.Context, msg string, keysAndValues ...any)

func (*ZapLogger) Paniccf

func (zl *ZapLogger) Paniccf(ctx context.Context, format string, args ...any)

func (*ZapLogger) Panicf

func (zl *ZapLogger) Panicf(format string, args ...any)

Jump to

Keyboard shortcuts

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