logger

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 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 ...any)

func Debugf

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

func Error

func Error(args ...any)

func Errorf

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

func Fatal

func Fatal(args ...any)

func Fatalf

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

func Info

func Info(args ...any)

func Infof

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

func Init

func Init(opts ...Option) error

func InitLogger

func InitLogger(opts ...Option)

InitLogger init customize logger

func Log

func Log(level string, v ...any)

func Logf

func Logf(level string, format string, v ...any)

func Warn

func Warn(args ...any)

func Warnf

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

Types

type Logger

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

Logger is a generic logging interface.

func Fields

func Fields(fields map[string]any) 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]any) 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