log

package
v1.15.7 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

A constant exposing all logging levels

View Source
var ErrorKey = "error"

Defines the key when adding errors using WithError.

Functions

func Close

func Close()

Close 关闭

func Debug

func Debug(args ...interface{})

Debug logs a message at level Debug on the standard logger.

func DebugF

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

Debug logs a message at level Debug on the standard logger.

func DeferExitHandler

func DeferExitHandler(handler func())

DeferExitHandler prepends a Logrus Exit handler to the list of handlers, call logrus.Exit to invoke all handlers. The handlers will also be invoked when any Fatal log entry is made.

This method is useful when a caller wishes to use logrus to log a fatal message but also needs to gracefully shutdown. An example usecase could be closing database connections, or sending a alert that the application is closing.

func Error

func Error(args ...interface{})

Error logs a message at level Error on the standard logger.

func Errorf

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

Errorf logs a message at level Error on the standard logger.

func Exit

func Exit(code int)

Exit runs all the Logrus atexit handlers and then terminates the program using os.Exit(code)

func Fatal

func Fatal(args ...interface{})

Fatal logs a message at level Fatal on the standard logger then the process will exit with status set to 1.

func Fatalf

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

Fatalf logs a message at level Fatal on the standard logger then the process will exit with status set to 1.

func Info

func Info(args ...interface{})

Info logs a message at level Info on the standard logger.

func Infof

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

Infof logs a message at level Info on the standard logger.

func Panic

func Panic(args ...interface{})

Panic logs a message at level Panic on the standard logger.

func RegisterExitHandler

func RegisterExitHandler(handler func())

RegisterExitHandler appends a Logrus Exit handler to the list of handlers, call logrus.Exit to invoke all handlers. The handlers will also be invoked when any Fatal log entry is made.

This method is useful when a caller wishes to use logrus to log a fatal message but also needs to gracefully shutdown. An example usecase could be closing database connections, or sending a alert that the application is closing.

func Reset

func Reset(transports ...EntryTransporter)

func SetLevel

func SetLevel(level Level)

func SetPrefix

func SetPrefix(prefix string)

func Warn

func Warn(args ...interface{})

Warn logs a message at level Warn on the standard logger.

func Warnf

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

Warnf logs a message at level Info on the standard logger.

Types

type Builder

type Builder interface {
	Logln(level Level, args ...interface{})
	Log(level Level, args ...interface{})
	Logf(level Level, format string, args ...interface{})
	WithError(err error) Builder
	WithField(key string, value interface{}) Builder
	WithFields(fields Fields) Builder
}

func WithFields

func WithFields(fields Fields) Builder

WithFields 写域

type Complex

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

func NewComplex

func NewComplex(transports ...EntryTransporter) *Complex

func (*Complex) Close

func (c *Complex) Close() error

func (*Complex) Level

func (c *Complex) Level() Level

func (*Complex) Reset

func (c *Complex) Reset(transporters ...EntryTransporter) error

func (*Complex) Transport

func (c *Complex) Transport(entry *Entry) error

type Entry

type Entry struct {

	// Contains all the fields set by the user.
	Data Fields

	// Time at which the log entry was created
	Time time.Time

	// Level the log entry was logged at: Trace, Debug, Info, Warn, Error, Fatal or Panic
	// This field will be set on entry firing and the value will be equal to the one in _Logger struct field.
	Level Level

	// Calling method, with package name
	Caller *runtime.Frame

	// Message passed to Trace, Debug, Info, Warn, Error, Fatal or Panic
	Message string
	Err     string
}

An entry is the final or intermediate Logrus logging entry. It contains all the fields passed with WithField{,s}. It's finally logged when Trace, Debug, Info, Warn, Error, Fatal or Panic is called on it. These objects can be reused and passed around as much as you wish to avoid field duplication.

func (*Entry) HasCaller

func (entry *Entry) HasCaller() (has bool)

type EntryBuilder

type EntryBuilder struct {

	// Contains all the fields set by the user.
	Data Fields
	// Time at which the log entry was created
	Time time.Time
	// contains filtered or unexported fields
}

func (*EntryBuilder) Log

func (builder *EntryBuilder) Log(level Level, args ...interface{})

func (*EntryBuilder) Logf

func (builder *EntryBuilder) Logf(level Level, format string, args ...interface{})

func (*EntryBuilder) Logln

func (builder *EntryBuilder) Logln(level Level, args ...interface{})

func (*EntryBuilder) WithError

func (builder *EntryBuilder) WithError(err error) Builder

Add an error as single field (using the key defined in ErrorKey) to the Entry.

func (*EntryBuilder) WithField

func (builder *EntryBuilder) WithField(key string, value interface{}) Builder

Add a single field to the Entry.

func (*EntryBuilder) WithFields

func (builder *EntryBuilder) WithFields(fields Fields) Builder

Add a map of fields to the Entry.

type EntryTransporter

type EntryTransporter interface {
	Transport(entry *Entry) error
	Level() Level
	Close() error
}

type Factory

type Factory interface {
	Get(name string, config interface{}) (*Logger, error)
}

type Fields

type Fields map[string]interface{}

Fields type, used to pass to `WithFields`.

type Formatter

type Formatter interface {
	Format(*Entry) ([]byte, error)
}

The Formatter interface is used to implement a custom Formatter. It takes an `Entry`. It exposes all the fields, including the default ones:

* `entry.Data["msg"]`. The message passed from Info, Warn, Error .. * `entry.Data["time"]`. The timestamp. * `entry.Data["level"]. The level the entry was logged at.

Any additional fields added with `WithField` or `WithFields` are also in `entry.Data`. Format is expected to return an array of bytes which are then logged to `logger.Out`.

type Level

type Level uint32

Level type

const (
	// PanicLevel level, highest level of severity. Logs and then calls panic with the
	// message passed to Debug, Info, ...
	PanicLevel Level = iota
	// FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the
	// logging level is set to Panic.
	FatalLevel
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	ErrorLevel
	// WarnLevel level. Non-critical entries that deserve eyes.
	WarnLevel
	// InfoLevel level. General operational entries about what's going on inside the
	// application.
	InfoLevel
	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
	DebugLevel
	// TraceLevel level. Designates finer-grained informational events than the Debug.
	TraceLevel
)

These are the different logging levels. You can set the logging level to log on your instance of logger, obtained with `logrus.Start()`.

func ParseLevel

func ParseLevel(lvl string) (Level, error)

ParseLevel takes a string level and returns the Logrus log level constant.

func (Level) MarshalText

func (level Level) MarshalText() ([]byte, error)

func (Level) String

func (level Level) String() string

Convert the Level to a string. E.g. PanicLevel becomes "panic".

func (*Level) UnmarshalText

func (level *Level) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type LineFormatter

type LineFormatter struct {
	TimestampFormat  string
	CallerPrettyfier func(*runtime.Frame) (function string, file string)
}

LineFormatter 格式化

func (*LineFormatter) Format

func (f *LineFormatter) Format(entry *Entry) ([]byte, error)

Format 格式化

type Logger

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

func GetLogger

func GetLogger() *Logger

func NewLogger

func NewLogger(transporter EntryTransporter, reportCaller bool, packageName string) *Logger

func (*Logger) Debug

func (logger *Logger) Debug(args ...interface{})

func (*Logger) Debugf

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

func (*Logger) Debugln

func (logger *Logger) Debugln(args ...interface{})

func (*Logger) Error

func (logger *Logger) Error(args ...interface{})

func (*Logger) Errorf

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

func (*Logger) Errorln

func (logger *Logger) Errorln(args ...interface{})

func (*Logger) Exit

func (logger *Logger) Exit(code int)

func (*Logger) Fatal

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

func (*Logger) Fatalf

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

func (*Logger) Fatalln

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

func (*Logger) GetLevel

func (logger *Logger) GetLevel() Level

GetLevel returns the LoggerProxy level.

func (*Logger) Info

func (logger *Logger) Info(args ...interface{})

func (*Logger) Infof

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

func (*Logger) Infoln

func (logger *Logger) Infoln(args ...interface{})

func (*Logger) IsLevelEnabled

func (logger *Logger) IsLevelEnabled(level Level) bool

IsLevelEnabled checks if the log level of the logger is greater than the level param

func (*Logger) Log

func (logger *Logger) Log(level Level, args ...interface{})

func (*Logger) Logf

func (logger *Logger) Logf(level Level, format string, args ...interface{})

func (*Logger) Logln

func (logger *Logger) Logln(level Level, args ...interface{})

func (*Logger) Panic

func (logger *Logger) Panic(args ...interface{})

func (*Logger) Panicf

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

func (*Logger) Panicln

func (logger *Logger) Panicln(args ...interface{})

func (*Logger) SetPrefix

func (logger *Logger) SetPrefix(prefix string)

func (*Logger) SetTransporter

func (logger *Logger) SetTransporter(transporter EntryTransporter)

func (*Logger) Trace

func (logger *Logger) Trace(args ...interface{})

func (*Logger) Tracef

func (logger *Logger) Tracef(format string, args ...interface{})

func (*Logger) Traceln

func (logger *Logger) Traceln(args ...interface{})

func (*Logger) Transport

func (logger *Logger) Transport(entry *Entry) (err error)

func (*Logger) Warn

func (logger *Logger) Warn(args ...interface{})

func (*Logger) Warnf

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

func (*Logger) Warning

func (logger *Logger) Warning(args ...interface{})

func (*Logger) Warningf

func (logger *Logger) Warningf(format string, args ...interface{})

func (*Logger) Warningln

func (logger *Logger) Warningln(args ...interface{})

func (*Logger) Warnln

func (logger *Logger) Warnln(args ...interface{})

func (*Logger) WithError

func (logger *Logger) WithError(err error) Builder

func (*Logger) WithField

func (logger *Logger) WithField(key string, value interface{}) Builder

func (*Logger) WithFields

func (logger *Logger) WithFields(fields Fields) Builder

type Transporter

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

func NewTransport

func NewTransport(out io.Writer, level Level) *Transporter

func (*Transporter) Close

func (t *Transporter) Close() error

func (*Transporter) Level

func (t *Transporter) Level() Level

func (*Transporter) Output

func (t *Transporter) Output() io.Writer

func (*Transporter) SetFormatter

func (t *Transporter) SetFormatter(formatter Formatter)

func (*Transporter) SetLevel

func (t *Transporter) SetLevel(level Level)

SetLevel sets the logger level.

func (*Transporter) SetOutput

func (t *Transporter) SetOutput(output io.Writer)

func (*Transporter) Transport

func (t *Transporter) Transport(entry *Entry) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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