slog

package
v0.5.16 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: MIT Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

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

func Error

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

func Fatal

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

func Info

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

func SetDefaultLog

func SetDefaultLog(logger BoxLogger)

SetDefaultLog will create logger by tag

func Warn

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

Types

type BoxLogger

type BoxLogger interface {
	// Init initialises options
	Init(options ...Option) error
	// Options the Logger options
	Options() *Options
	// Log writes a log entry
	Log(level Level, v ...interface{})
	// Logf writes a formatted log entry
	Logf(level Level, format string, v ...interface{})
	// Named will create child logger with prefix
	Named(string) BoxLogger
	// Children will return a children with new option !
	Children(...Option) BoxLogger

	Debug(string, ...interface{})
	Info(string, ...interface{})
	Warn(string, ...interface{})
	Error(string, ...interface{})
	Fatal(string, ...interface{})
}

func Children

func Children(opts ...Option) BoxLogger

type Level

type Level int8
const (
	LogDebug Level = iota - 1
	LogInfo
	LogWarn
	LogError //error print trace back if config
	LogFatal //fatal print trace back and panic if develop!
)

func GetLevel

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

func (l Level) Enabled(lvl Level) bool

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

func (Level) String

func (l Level) String() string

type Option

type Option func(*Options)

func SetOption

func SetOption(k, v interface{}) Option

func WithAppName

func WithAppName(name string) Option

func WithCallerSkipCount

func WithCallerSkipCount(c int) Option

WithCallerSkipCount set frame count to skip

func WithLevel

func WithLevel(level Level) Option

WithLevel set default level for the logger

func WithOutput

func WithOutput(out []string) Option

WithOutput set default output writer for the logger

type Options

type Options struct {
	// AppName is application nickname
	AppName string
	//LevelStr is human-readable level config
	LevelStr string `yaml:"level"`
	// The logging level the logger should log at. default is `InfoLevel`
	LogLevel Level
	//Outs logging out way, like console file or other
	Outs []string `yaml:"mode"`
	//LogFile is log file name
	LogFile string `yaml:"outfile"`
	//Style will determine the format of log, like json or console line !
	Style string `yaml:"style"`
	//TimeFormat format time with layout like 2006-01-02 15:04:05
	TimeFormat string `yaml:"time_format"`
	// Caller skip frame count for file:line info
	CallerSkipCount int `yaml:"caller_skip_count"`
	// TraceLevel will add stack trace, must greater than info. default close
	TraceLevel string `yaml:"trace_level"`
	//TimeSplit will split log by time
	TimeSplit string `yaml:"time_split"`
	//SizeSplit will split log by size
	SizeSplit int64 `yaml:"size_split"`
	// Alternative options
	Context context.Context
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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