logx

package
v0.0.0-...-c6e4f4a Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: MulanPSL-2.0 Imports: 14 Imported by: 0

README

日志库

结构化日志库,该日志库在logrus和zap的基础上进行了封装。

目前,日志库支持:

  • 标准输出
  • 文件输出
    • 日志文件按时间切割
    • 日志文件按大小切割
    • 日志文件按时间和大小切割

Documentation

Index

Constants

View Source
const (
	FileRotateByTime = "time"
	FileRotateBySize = "size"
	FileRotateByMix  = "mix"
)
View Source
const (
	//DebugLevel has verbose message
	DebugLevel = "debug"
	//InfoLevel is default log level
	InfoLevel = "info"
	//WarnLevel is for logging messages about possible issues
	WarnLevel = "warn"
	//ErrorLevel is for logging errors
	ErrorLevel = "error"
)

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

func Debugf

func Debugf(format string, args ...interface{})

func Error

func Error(args ...interface{})

func Errorf

func Errorf(format string, args ...interface{})

func Fatal

func Fatal(args ...interface{})

func Fatalf

func Fatalf(format string, args ...interface{})

func Info

func Info(args ...interface{})

func Infof

func Infof(format string, args ...interface{})

func Init

func Init(config Config) error

func Output

func Output() io.Writer

func Panic

func Panic(args ...interface{})

func Panicf

func Panicf(format string, args ...interface{})

func Warn

func Warn(args ...interface{})

func Warnf

func Warnf(format string, args ...interface{})

Types

type Config

type Config struct {
	Level          string
	DisableConsole bool
	JsonFormat     bool
	File           FileConfig
}

type Fields

type Fields map[string]interface{}

type FileConfig

type FileConfig struct {
	Enable       bool
	Filename     string
	RotateType   string // the type of rotation, support time and size
	RotateTimeS  int    // the number of seconds between rotation
	RotateSize   int    // the maximum size in megabytes of the log file before it gets rotated
	RotateCount  int    // the maximum number of log files to retain
	RotateMaxAge int    // the maximum number of days to retain
}

type ILogger

type ILogger interface {
	Debug(args ...interface{})
	Debugf(format string, args ...interface{})
	Info(args ...interface{})
	Infof(format string, args ...interface{})
	Warn(args ...interface{})
	Warnf(format string, args ...interface{})
	Error(args ...interface{})
	Errorf(format string, args ...interface{})
	Panic(args ...interface{})
	Panicf(format string, args ...interface{})
	Fatal(args ...interface{})
	Fatalf(format string, args ...interface{})
	WithFields(fields Fields) ILogger
	WithField(key string, value interface{}) ILogger
	WithKVs(kvs ...interface{}) ILogger
	WithError(err error) ILogger
	Output() io.Writer
}

func WithError

func WithError(err error) ILogger

func WithField

func WithField(key string, value interface{}) ILogger

func WithFields

func WithFields(fields Fields) ILogger

func WithKVs

func WithKVs(kvs ...interface{}) ILogger

type LoggerFactory

type LoggerFactory struct {
}

func NewLoggerFactory

func NewLoggerFactory() *LoggerFactory

func (*LoggerFactory) Create

func (f *LoggerFactory) Create(t LoggerType, opt *Option) ILogger

type LoggerType

type LoggerType int
const (
	Logrus LoggerType = iota
	Zap
)

type LogrusLogger

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

func NewLogrusLogger

func NewLogrusLogger(opt *Option) *LogrusLogger

func (*LogrusLogger) Debug

func (l *LogrusLogger) Debug(args ...interface{})

func (*LogrusLogger) Debugf

func (l *LogrusLogger) Debugf(format string, args ...interface{})

func (*LogrusLogger) Error

func (l *LogrusLogger) Error(args ...interface{})

func (*LogrusLogger) Errorf

func (l *LogrusLogger) Errorf(format string, args ...interface{})

func (*LogrusLogger) Fatal

func (l *LogrusLogger) Fatal(args ...interface{})

func (*LogrusLogger) Fatalf

func (l *LogrusLogger) Fatalf(format string, args ...interface{})

func (*LogrusLogger) Info

func (l *LogrusLogger) Info(args ...interface{})

func (*LogrusLogger) Infof

func (l *LogrusLogger) Infof(format string, args ...interface{})

func (*LogrusLogger) Output

func (l *LogrusLogger) Output() io.Writer

func (*LogrusLogger) Panic

func (l *LogrusLogger) Panic(args ...interface{})

func (*LogrusLogger) Panicf

func (l *LogrusLogger) Panicf(format string, args ...interface{})

func (*LogrusLogger) Warn

func (l *LogrusLogger) Warn(args ...interface{})

func (*LogrusLogger) Warnf

func (l *LogrusLogger) Warnf(format string, args ...interface{})

func (*LogrusLogger) WithError

func (l *LogrusLogger) WithError(err error) ILogger

func (*LogrusLogger) WithField

func (l *LogrusLogger) WithField(key string, value interface{}) ILogger

func (*LogrusLogger) WithFields

func (l *LogrusLogger) WithFields(fields Fields) ILogger

func (*LogrusLogger) WithKVs

func (l *LogrusLogger) WithKVs(kvs ...interface{}) ILogger

type Option

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

func NewOption

func NewOption() *Option

func (*Option) AddCallerSkip

func (o *Option) AddCallerSkip(skip int) *Option

func (*Option) AddOutput

func (o *Option) AddOutput(out io.Writer) *Option

func (*Option) AddOutputs

func (o *Option) AddOutputs(out ...io.Writer) *Option

func (*Option) SetJsonFormat

func (o *Option) SetJsonFormat() *Option

func (*Option) SetLevel

func (o *Option) SetLevel(level string) *Option

func (*Option) SetTextFormat

func (o *Option) SetTextFormat() *Option

type ZapLogger

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

func NewZapLogger

func NewZapLogger(opt *Option) *ZapLogger

func (*ZapLogger) Debug

func (l *ZapLogger) Debug(args ...interface{})

func (*ZapLogger) Debugf

func (l *ZapLogger) Debugf(format string, args ...interface{})

func (*ZapLogger) Error

func (l *ZapLogger) Error(args ...interface{})

func (*ZapLogger) Errorf

func (l *ZapLogger) Errorf(format string, args ...interface{})

func (*ZapLogger) Fatal

func (l *ZapLogger) Fatal(args ...interface{})

func (*ZapLogger) Fatalf

func (l *ZapLogger) Fatalf(format string, args ...interface{})

func (*ZapLogger) Info

func (l *ZapLogger) Info(args ...interface{})

func (*ZapLogger) Infof

func (l *ZapLogger) Infof(format string, args ...interface{})

func (*ZapLogger) Output

func (l *ZapLogger) Output() io.Writer

func (*ZapLogger) Panic

func (l *ZapLogger) Panic(args ...interface{})

func (*ZapLogger) Panicf

func (l *ZapLogger) Panicf(format string, args ...interface{})

func (*ZapLogger) Warn

func (l *ZapLogger) Warn(args ...interface{})

func (*ZapLogger) Warnf

func (l *ZapLogger) Warnf(format string, args ...interface{})

func (*ZapLogger) WithError

func (l *ZapLogger) WithError(err error) ILogger

func (*ZapLogger) WithField

func (l *ZapLogger) WithField(key string, value interface{}) ILogger

func (*ZapLogger) WithFields

func (l *ZapLogger) WithFields(fields Fields) ILogger

func (*ZapLogger) WithKVs

func (l *ZapLogger) WithKVs(kvs ...interface{}) ILogger

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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