logger

package
v0.0.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: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func V added in v0.0.6

func V(lvl Level, log Logger) bool

Returns true if the given level is at or lower the current logger level.

Types

type Config added in v0.0.6

type Config struct {
	Target     string //日志输出目标。一般是console或者file
	LogFile    string //日志输出文件
	MaxSize    int    //日志文件最大尺寸
	MaxBackups int    //最大备份数
	MaxAge     int    //最大停留
	Level      int
}

type Level added in v0.0.6

type Level int8
const (
	// TraceLevel level. Designates finer-grained informational events than the Debug.
	TraceLevel Level = iota - 2
	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
	DebugLevel
	// InfoLevel is the default logging priority.
	// General operational entries about what's going on inside the application.
	InfoLevel
	// WarnLevel level. Non-critical entries that deserve eyes.
	WarnLevel
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	ErrorLevel
	// FatalLevel level. Logs and then calls `logger.Exit(1)`. highest level of severity.
	FatalLevel
)

func GetLevel added in v0.0.6

func GetLevel(levelStr string) (Level, error)

GetLevel converts a level string into a logger Level value. returns an error if the input string does not match known values.

func (Level) Enabled added in v0.0.6

func (l Level) Enabled(lvl Level) bool

Enabled returns true if the given level is at or above this level.

func (Level) String added in v0.0.6

func (l Level) String() string

type Logger added in v0.0.3

type Logger interface {
	Log(level Level, v ...interface{})
	// Logf writes a formatted log entry
	Logf(level Level, format string, v ...interface{})

	Debugf(format string, v ...interface{})
	Fatalf(format string, v ...interface{})
	Infof(format string, v ...interface{})

	// String returns the name of logger
	String() string

	Options() Options
}
var DefaultLogger Logger = NewLogger()

func NewLogger added in v0.0.6

func NewLogger(opts ...Option) Logger

NewLogger builds a new logger based on options.

type Option added in v0.0.6

type Option func(*Options)

func SetOption added in v0.0.6

func SetOption(k, v interface{}) Option

func WithCallerSkipCount added in v0.0.6

func WithCallerSkipCount(c int) Option

WithCallerSkipCount set frame count to skip.

func WithFields added in v0.0.6

func WithFields(fields map[string]interface{}) Option

WithFields set default fields for the logger.

func WithLevel added in v0.0.6

func WithLevel(level Level) Option

WithLevel set default level for the logger.

func WithOutput added in v0.0.6

func WithOutput(out io.Writer) Option

WithOutput set default output writer for the logger.

type Options added in v0.0.6

type Options struct {
	// It's common to set this to a file, or leave it default which is `os.Stderr`
	Out io.Writer
	// Alternative options
	Context context.Context
	// fields to always be logged
	Fields map[string]interface{}
	// Caller skip frame count for file:line info
	CallerSkipCount int
	// The logging level the logger should log at. default is `InfoLevel`
	Level Level
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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