logger

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2023 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DebugLevel = "debug"
	InfoLevel  = "info"
	WarnLevel  = "warn"
	ErrorLevel = "error"
	PanicLevel = "panic"
	FatalLevel = "fatal"
)

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(opts ...Option) error

func InitLogger

func InitLogger(opts ...Option)

InitLogger init customize logger

func Log

func Log(level string, v ...interface{})

func Logf

func Logf(level string, format string, v ...interface{})

func Warn

func Warn(args ...interface{})

func Warnf

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

Types

type Logger

type Logger interface {
	// Init initializes options
	Init(options ...Option) error
	// Fields set fields to always be logged
	Fields(fields map[string]interface{}) Logger
	// Log writes a log entry
	Log(level string, v ...interface{})
	// Logf writes a formatted log entry
	Logf(level string, format string, v ...interface{})
}

Logger is a generic logging interface.

func Fields

func Fields(fields map[string]interface{}) Logger

func NewExampleLogger

func NewExampleLogger() Logger

NewExampleLogger builds a Logger that's designed for use in zap's testable

func NewLogger

func NewLogger(opts ...Option) Logger

NewLogger New builds a new logger based on options.

type Option

type Option func(*Options)

func WithCallerSkipCount

func WithCallerSkipCount(c int) Option

func WithDebug

func WithDebug() Option

func WithDisableConsole

func WithDisableConsole() Option

func WithFields

func WithFields(fields map[string]interface{}) Option

func WithJsonEncoding

func WithJsonEncoding() Option

func WithLevel

func WithLevel(level string) Option

func WithLogDir

func WithLogDir(dir string) Option

func WithRotation

func WithRotation(r Rotation) Option

type Options

type Options struct {
	Debug           bool
	DisableConsole  bool
	JsonEncoding    bool
	CallerSkipCount int
	LogDir          string
	Level           string
	Fields          map[string]any
	Rotation        Rotation
}

type Rotation

type Rotation struct {
	MaxSize    int  // 单个文件最大尺寸,默认单位 M
	MaxBackups int  // 最多保留 300 个备份
	MaxAge     int  // 最大时间,默认单位 day
	LocalTime  bool // 使用本地时间
	Compress   bool // 是否压缩 disabled by default
}

Jump to

Keyboard shortcuts

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