log

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: Apache-2.0 Imports: 16 Imported by: 91

Documentation

Index

Constants

View Source
const (
	FatalPre string = "[FATAL]"
	ErrorPre string = "[ERROR]"
	WarnPre  string = "[WARN]"
	InfoPre  string = "[INFO]"
	DebugPre string = "[DEBUG]"
	TracePre string = "[TRACE]"
)

Variables

View Source
var ErrChanFull = errors.New("channel is full")
View Source
var (
	// error
	ErrReopenUnsupported = errors.New("reopen unsupported")
)

Functions

func ClearAll

func ClearAll()

ClearAll created logger, just for test

func CloseAll

func CloseAll() (err error)

CloseAll logger

func DefaultFormatter

func DefaultFormatter(lv string, alert string, format string) string

func InitGlobalRoller

func InitGlobalRoller(roller string) error

InitDefaultRoller

func IsLogRollerSubdirective

func IsLogRollerSubdirective(subdir string) bool

IsLogRollerSubdirective is true if the subdirective is for the log roller.

func PutLogBuffer

func PutLogBuffer(buf LogBuffer) error

PutLogBuffer puts a LogBuffer back to logPool

func Reopen

func Reopen() (err error)

Reopen all logger

func ToggleLogger

func ToggleLogger(p string, disable bool) bool

Types

type ContextLogger

type ContextLogger interface {
	Alertf(ctx context.Context, alert string, format string, args ...interface{})

	Infof(ctx context.Context, format string, args ...interface{})

	Debugf(ctx context.Context, format string, args ...interface{})

	Warnf(ctx context.Context, format string, args ...interface{})

	Errorf(ctx context.Context, format string, args ...interface{})

	Tracef(ctx context.Context, format string, args ...interface{})

	Fatalf(ctx context.Context, format string, args ...interface{})

	// SetLogLevel updates the log level
	SetLogLevel(Level)
	// GetLogLevel returns the logger's level
	GetLogLevel() Level

	// Toggle disable/enable the logger
	Toggle(disable bool)
}
var DefaultContextLogger ContextLogger

type ErrorLogger

type ErrorLogger interface {
	Alertf(alert string, format string, args ...interface{})

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

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

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

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

	Tracef(format string, args ...interface{})

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

	// SetLogLevel updates the log level
	SetLogLevel(Level)
	// GetLogLevel returns the logger's level
	GetLogLevel() Level

	// Toggle disable/enable the logger
	Toggle(disable bool)

	Disable() bool
}

ErrorLogger generates lines of output to an io.Writer ErrorLogger generates lines of output to an io.Writer

var DefaultLogger ErrorLogger

type Level

type Level uint8
const (
	FATAL Level = iota
	ERROR
	WARN
	INFO
	DEBUG
	TRACE
	RAW
)

type LogBuffer

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

LogBuffer is an implementation of api.IoBuffer that used in log package, to distinguish it from api.IoBuffer nolint

func GetLogBuffer

func GetLogBuffer(size int) LogBuffer

GetLogBuffer returns a LogBuffer from logPool

type Logger

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

Logger is a basic sync logger implement, contains unexported fields The Logger Function contains: Print(buffer LogBuffer, discard bool) error Printf(format string, args ...interface{}) Println(args ...interface{}) Fatalf(format string, args ...interface{}) Fatal(args ...interface{}) Fatalln(args ...interface{}) Close() error Reopen() error Toggle(disable bool)

func GetOrCreateLogger

func GetOrCreateLogger(output string, roller *Roller) (*Logger, error)

func (*Logger) Close

func (l *Logger) Close() error

func (*Logger) Disable

func (l *Logger) Disable() bool

func (*Logger) Fatal

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

func (*Logger) Fatalf

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

Fatal cannot be disabled

func (*Logger) Fatalln

func (l *Logger) Fatalln(args ...interface{})

func (*Logger) Print

func (l *Logger) Print(buf LogBuffer, discard bool) error

Print writes the final buffere to the buffer chan if discard is true and the buffer is full, returns an error If a LogBuffer needs to call Print N(N>1) times, the LogBuffer.Count(N-1) should be called or call LogBuffer.Count(1) N-1 times. If the N is 1, LogBuffer.Count should not be called.

func (*Logger) Printf

func (l *Logger) Printf(format string, args ...interface{})

func (*Logger) Println

func (l *Logger) Println(args ...interface{})

func (*Logger) Reopen

func (l *Logger) Reopen() error

func (*Logger) Toggle

func (l *Logger) Toggle(disable bool)

func (*Logger) Write

func (l *Logger) Write(p []byte) (n int, err error)

type LoggerInfo

type LoggerInfo struct {
	LogRoller  Roller
	FileName   string
	CreateTime time.Time
}

type Roller

type Roller struct {
	Filename   string
	MaxSize    int
	MaxAge     int
	MaxBackups int
	Compress   bool
	LocalTime  bool
	// roller rotate time, if the MAxTime is configured, ignore the others config
	MaxTime int64
	Handler RollerHandler
}

roller implements a type that provides a rolling logger.

func DefaultRoller

func DefaultRoller() *Roller

DefaultRoller will roll logs by default.

func ParseRoller

func ParseRoller(what string) (*Roller, error)

ParseRoller parses roller contents out of c.

func (Roller) GetLogWriter

func (l Roller) GetLogWriter() io.Writer

GetLogWriter returns an io.Writer that writes to a rolling logger. it is careful to create only one log writer per log file, even if the log file is shared by different sites or middlewares. This ensures that rolling is synchronized, since a process (or multiple processes) should not create more than one roller on the same file at the same time. See issue #1363.

type RollerHandler

type RollerHandler func(l *LoggerInfo)

type SimpleContextLog

type SimpleContextLog struct {
	*SimpleErrorLog
}

SimpleComtextLog is a wrapper of SimpleErrorLog

func (*SimpleContextLog) Alertf

func (l *SimpleContextLog) Alertf(ctx context.Context, alert string, format string, args ...interface{})

func (*SimpleContextLog) Debugf

func (l *SimpleContextLog) Debugf(ctx context.Context, format string, args ...interface{})

func (*SimpleContextLog) Errorf

func (l *SimpleContextLog) Errorf(ctx context.Context, format string, args ...interface{})

func (*SimpleContextLog) Fatalf

func (l *SimpleContextLog) Fatalf(ctx context.Context, format string, args ...interface{})

func (*SimpleContextLog) Infof

func (l *SimpleContextLog) Infof(ctx context.Context, format string, args ...interface{})

func (*SimpleContextLog) Tracef added in v1.6.0

func (l *SimpleContextLog) Tracef(ctx context.Context, format string, args ...interface{})

func (*SimpleContextLog) Warnf

func (l *SimpleContextLog) Warnf(ctx context.Context, format string, args ...interface{})

type SimpleErrorLog

type SimpleErrorLog struct {
	*Logger
	Formatter func(lv string, alert string, format string) string
	Level     Level
}

func (*SimpleErrorLog) Alertf

func (l *SimpleErrorLog) Alertf(alert string, format string, args ...interface{})

func (*SimpleErrorLog) Debugf

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

func (*SimpleErrorLog) Errorf

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

func (*SimpleErrorLog) Fatalf

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

func (*SimpleErrorLog) GetLogLevel

func (l *SimpleErrorLog) GetLogLevel() Level

func (*SimpleErrorLog) Infof

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

func (*SimpleErrorLog) SetLogLevel

func (l *SimpleErrorLog) SetLogLevel(level Level)

func (*SimpleErrorLog) Tracef

func (l *SimpleErrorLog) Tracef(format string, args ...interface{})

func (*SimpleErrorLog) Warnf

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

Jump to

Keyboard shortcuts

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