log

package
v0.0.0-...-d62e3dc Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LevelDebug = 1 << (iota - 1) // 调试
	LevelInfo                    // 追踪
	LevelWarn                    // 警告
	LevelError                   // 错误

	LevelAll = LevelDebug | LevelInfo | LevelWarn | LevelError
)

Variables

This section is empty.

Functions

func Debug

func Debug(args ...any)

func Debugf

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

func EachLevel

func EachLevel(fn func(level Level) (continued bool))

func Error

func Error(args ...any)

func Errorf

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

func Final

func Final()

func Info

func Info(args ...any)

func Infof

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

func Init

func Init(consoleColorful bool, option *LoggerOption, writers ...IWriter)

func Warn

func Warn(args ...any)

func Warnf

func Warnf(format string, args ...any)

Types

type FileOption

type FileOption struct {
	Name            string        // 文件名
	Dir             string        // 目录
	MaxSize         int64         // 单个文件大小上限
	MaxAge          time.Duration // 文件保存时长
	SeperatedLevels int32         // 单独写文件的等级
	CheckInterval   time.Duration // 检查间隔
}

type ILogger

type ILogger interface {
	Destroy()
	SetLevel(level Level)
	Debug(args ...any)
	Debugf(format string, args ...any)
	Info(args ...any)
	Infof(format string, args ...any)
	Warn(args ...any)
	Warnf(format string, args ...any)
	Error(args ...any)
	Errorf(format string, args ...any)
}

func CreateConsoleLogger

func CreateConsoleLogger() ILogger

func CreateLogger

func CreateLogger(option LoggerOption, writers ...IWriter) (ILogger, error)

func Default

func Default() ILogger

func GetLogger

func GetLogger(name string) (ILogger, bool)

func MustCreateLogger

func MustCreateLogger(option LoggerOption, writers ...IWriter) ILogger

func MustGetLogger

func MustGetLogger(name string) ILogger

type IRecord

type IRecord interface {
	Bytes() []byte
	Level() Level
	Clone() IRecord
	// contains filtered or unexported methods
}

type IWriter

type IWriter interface {
	Write(record IRecord)
	Destroy()
}

func ConsoleWriter

func ConsoleWriter() IWriter

func CreateFileWriter

func CreateFileWriter(option *FileOption) (IWriter, error)

func GetWriter

func GetWriter(name string) (IWriter, bool)

func MustCreateFileWriter

func MustCreateFileWriter(option *FileOption) IWriter

func MustGetWriter

func MustGetWriter(name string) IWriter

type Level

type Level int32 // Level 日志级别

func (Level) IsIn

func (l Level) IsIn(levels int32) bool

func (Level) Prefix

func (l Level) Prefix() (prefix string)

Prefix 每个级别的日志对应的prefix

func (Level) SubName

func (l Level) SubName() string

SubName 需要区分级别存放日志信息时,用于获取每个级别日志存放的子目录

func (Level) Valid

func (l Level) Valid() bool

type LoggerOption

type LoggerOption struct {
	Name            string
	Level           Level
	TimestampFormat string
	Caller          bool
	CallerSkip      int
}

Directories

Path Synopsis
c

Jump to

Keyboard shortcuts

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