log

package
v0.0.0-...-cfa0e61 Latest Latest
Warning

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

Go to latest
Published: May 21, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DebugLevel logs are typically voluminous, and are usually disabled in
	// production.
	DebugLevel = "debug"
	// InfoLevel is the default logging priority.
	InfoLevel = "info"
	// WarnLevel logs are more important than Info, but don't need individual
	// human review.
	WarnLevel = "warn"
	// ErrorLevel logs are high-priority. If an application is running smoothly,
	// it shouldn't generate any error-level logs.
	ErrorLevel = "error"
	// DPanicLevel logs are particularly important errors. In development the
	// logger panics after writing the message.
	DPanicLevel = "dpanic"
	// PanicLevel logs a message, then panics.
	PanicLevel = "panic"
	// FatalLevel logs a message, then calls os.Exit(1).
	FatalLevel
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field interface {
	Key() string
	Value() any
}

func Error

func Error(err error) Field

func NewField

func NewField(key string, value any) Field

type Level

type Level string

A Level is a logging priority. Higher levels are more important.

type Logger

type Logger interface {
	Debug(msg string, fields ...Field)
	Info(msg string, fields ...Field)
	Warn(msg string, fields ...Field)
	Error(msg string, fields ...Field)
	Dpanic(msg string, fields ...Field)
	Panic(msg string, fields ...Field)
	Fatal(msg string, fields ...Field)

	Flush()
}

func New

func New(options ...Option) Logger

type Option

type Option func(*options)

func WithDevelopment

func WithDevelopment() Option

WithDevelopment set the env is development, which will changes the behavior of DPanicLevel and takes stacktraces more liberally

func WithDisableCaller

func WithDisableCaller() Option

WithDisableCaller Disable output of caller information in the log

func WithDisableStackTrace

func WithDisableStackTrace() Option

WithDisableStackTrace disable the log to record a stack trace for all messages at or above panic level

func WithField

func WithField(key string, value any) Option

WithField add some field(s) to log

func WithFile

func WithFile(path string, errPath string) Option

WithFile write log in some files

func WithLevel

func WithLevel(level Level) Option

WithLevel set the default output level

Jump to

Keyboard shortcuts

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