alog

package
v1.1.14 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultLogFileName   = "log/a-log.log" // 默认日志文件名
	DefaultLogMaxSize    = 1024            // 默认日志文件最大大小
	DefaultLogMaxAge     = 1               // 默认日志文件最大保存天数
	DefaultLogMaxBackups = 5               // 默认日志文件最多保存多少个备份
	DefaultLogCompress   = false           // 默认日志文件是否压缩
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AlertHook added in v1.1.7

type AlertHook func(msg string, args ...Arg) // 报警钩子

type Arg

type Arg struct {
	Key   string // 日志字段名
	Value any    // 日志字段值
}

type FileLogWriterConfig

type FileLogWriterConfig struct {
	FileName   string // 日志文件名
	MaxSize    int    // 每个日志文件保存的最大尺寸 单位:M
	MaxBackups int    // 日志文件最多保存多少个备份
	MaxAge     int    // 文件最多保存多少天
	Compress   bool   // 是否压缩
	LocalTime  bool   // 是否使用本地时间
}

type GormLogger added in v1.1.9

type GormLogger struct {
	LogLevel logger.LogLevel
	// contains filtered or unexported fields
}

func GetGormLogger added in v1.1.9

func GetGormLogger(log Logger) *GormLogger

GetGormLogger 基于Log创建gorm日志记录器

func NewGormLogger added in v1.1.9

func NewGormLogger(options ...Option) *GormLogger

NewGormLogger 创建gorm日志记录器

func (*GormLogger) Error added in v1.1.9

func (g *GormLogger) Error(ctx context.Context, s string, i ...interface{})

func (*GormLogger) Info added in v1.1.9

func (g *GormLogger) Info(ctx context.Context, s string, i ...interface{})

func (*GormLogger) LogMode added in v1.1.9

func (g *GormLogger) LogMode(level logger.LogLevel) logger.Interface

func (*GormLogger) Trace added in v1.1.9

func (g *GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)

func (*GormLogger) Warn added in v1.1.9

func (g *GormLogger) Warn(ctx context.Context, s string, i ...interface{})

type Level

type Level string // 日志级别
const (
	LogLevelDebug Level = "debug"
	LogLevelInfo  Level = "info"
	LogLevelWarn  Level = "warn"
	LogLevelError Level = "error"
	LogLeveLAlert Level = "alert"
)

type Log

type Log struct {
	FileLogWriterConfig // 文件日志配置
	// contains filtered or unexported fields
}

func (*Log) Alert added in v1.1.7

func (l *Log) Alert(hook AlertHook, msg string, args ...Arg)

func (*Log) Debug

func (l *Log) Debug(msg string, args ...Arg)

func (*Log) Error

func (l *Log) Error(msg string, args ...Arg)

func (*Log) Info

func (l *Log) Info(msg string, args ...Arg)

func (*Log) Warn

func (l *Log) Warn(msg string, args ...Arg)

type Logger

type Logger interface {
	// Debug 日志级别为Debug
	Debug(msg string, args ...Arg)
	// Info 日志级别为Info
	Info(msg string, args ...Arg)
	// Warn 日志级别为Warn
	Warn(msg string, args ...Arg)
	// Error 日志级别为Error
	Error(msg string, args ...Arg)
	// Alert 日志级别为Alert
	Alert(hook AlertHook, msg string, args ...Arg)
}

func NewLogger

func NewLogger(options ...Option) Logger

NewLogger 创建日志记录器

type Option

type Option func(*Log) // 日志配置选项

func WithCompress

func WithCompress(compress bool) Option

WithCompress 设置日志文件是否压缩

func WithFileName

func WithFileName(fileName string) Option

WithFileName 设置日志文件名,不包含路径,只有在输出方式为文件或者控制台+文件时有效

func WithLocalTime

func WithLocalTime(localTime bool) Option

WithLocalTime 设置日志文件是否使用本地时间

func WithMaxAge

func WithMaxAge(maxAge int) Option

WithMaxAge 设置日志文件最大保存天数

func WithMaxBackups

func WithMaxBackups(maxBackups int) Option

WithMaxBackups 设置日志文件最大备份数

func WithMaxSize

func WithMaxSize(maxSize int) Option

WithMaxSize 设置日志文件最大尺寸,单位MB

func WithOutputMode

func WithOutputMode(mode OutputMode) Option

WithOutputMode 设置日志输出方式,控制台、文件、控制台+文件

func WithOutputType

func WithOutputType(outputType OutputType) Option

WithOutputType 设置日志输出类型,JSON或者Console

func WithTimeEncoder

func WithTimeEncoder(timeEncoder zapcore.TimeEncoder) Option

WithTimeEncoder 设置日志时间格式,支持自定义格式

type OutputMode

type OutputMode uint8 // 输出模式
const (
	OutputModeStdout        OutputMode = iota + 1 // 输出到控制台
	OutputModeFile                                // 输出到文件
	OutputModeStdoutAndFile                       // 同时输出到控制台和文件
)

type OutputType

type OutputType uint8 // 输出类型
const (
	OutputJsonType    OutputType = iota + 1 // 输出JSON格式
	OutputConsoleType                       // 输出控制台格式
)

Jump to

Keyboard shortcuts

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