logger

package
v0.0.0-...-a7b145a Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2022 License: BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FmtEmptySeparate represents empty format string.
	FmtEmptySeparate = ""
)

Variables

View Source
var LevelNameMapping = map[Level]string{
	DebugLevel: "DEBUG",
	InfoLevel:  "INFO",
	WarnLevel:  "WARN",
	ErrorLevel: "ERROR",
	PanicLevel: "PANIC",
	FatalLevel: "FATAL",
}

LevelNameMapping is a mapping from log level to level name.

Functions

func Debug

func Debug(args ...interface{})

std logger.

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 New

func New(opts ...Option) *logger

New crate a logger object.

func Panic

func Panic(args ...interface{})

func Panicf

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

func SetOptions

func SetOptions(opts ...Option)

func StdLogger

func StdLogger() *logger

func Warn

func Warn(args ...interface{})

func Warnf

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

func Writer

func Writer() io.Writer

Types

type Color

type Color string

Colors.

type Entry

type Entry struct {
	Buffer *bytes.Buffer
	Map    map[string]interface{}
	Level  Level
	Time   time.Time
	File   string
	Line   int
	Func   string
	Format string
	Args   []interface{}
	// contains filtered or unexported fields
}

Entry is a log entry, format log and write log to output.

type Formatter

type Formatter interface {
	// Maybe in async goroutine
	// Please write the result to buffer
	Format(entry *Entry) error
}

type JsonFormatter

type JsonFormatter struct {
	IgnoreBasicFields bool
}

JsonFormatter implemented Formatter.

func (*JsonFormatter) Format

func (f *JsonFormatter) Format(e *Entry) error

Format format log to json.

type Level

type Level uint8

Level is the log level.

const (
	// DebugLevel only use when dev.
	DebugLevel Level = iota

	// InfoLevel log some useful info.
	InfoLevel

	// WarnLevel is more important than InfoLevel.
	WarnLevel

	// ErrorLevel indicate that the program had an error occurred.
	ErrorLevel

	// PanicLevel log is print when a panic occurred.
	PanicLevel

	// FatalLevel log is print when program can not run anymore.
	FatalLevel
)

func (Level) Color

func (l Level) Color() Color

type Option

type Option func(*options)

func WithDisableCaller

func WithDisableCaller(disableCaller bool) Option

WithDisableCaller sets log disable caller. if caller is true, then the log location will not be printed.

func WithDisableColor

func WithDisableColor(disableColor bool) Option

WithDisableColor sets log color. if disableColor is true, then the log color will not be printed.

func WithEnableAbsPath

func WithEnableAbsPath(enableAbsPath bool) Option

func WithEnableFunc

func WithEnableFunc(enableFunc bool) Option

func WithFormatter

func WithFormatter(formatter Formatter) Option

WithFormatter sets log formatter.

func WithLevel

func WithLevel(level Level) Option

WithLevel sets log level.

func WithOutput

func WithOutput(output io.Writer) Option

WithOutput set log output.

func WithStdLevel

func WithStdLevel(level Level) Option

WithStdLevel sets log std level.

type TextFormatter

type TextFormatter struct {
	IgnoreBasicFields bool
}

TextFormatter implemented Formatter interface.

func (*TextFormatter) Format

func (f *TextFormatter) Format(e *Entry) error

Format format log to text.

Jump to

Keyboard shortcuts

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