logger

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package logger basic and simple logger for application, it base the go embed `log` package. it's able to control output by log level, level order `all<debug<info<warn<error<none`.

Index

Examples

Constants

View Source
const (
	LevelAll   = "all"
	LevelError = "error"
	LevelWarn  = "warn"
	LevelInfo  = "info"
	LevelDebug = "debug"
	LevelNone  = "none"
)

string level values.

View Source
const (
	DriverStdout = "stdout"
	DriverFile   = "file"
	DriverBuffer = "buffer"
)

DriverStdout logging driver support builtin

Variables

View Source
var DefaultConfig = Config{
	Level:  "warn",
	Driver: DriverStdout,
}

Functions

func Prefix added in v1.1.1

func Prefix(level Level) string

func ShortCover added in v1.1.2

func ShortCover(short string) (lvlStr string)

ShortCover short level string cover to matched level string. rule:

`a/A -> all`
`e/E -> error`
`w/W -> warning`
`i/I -> info`
`d/D -> debug`
`n/N -> none`

Types

type Config

type Config struct {
	Log   *log.Logger `yaml:"-" json:"-"`
	Level string
	// driver list: stdout, file, buffer
	Driver string
	// when Driver is file it will be work
	OutputDir string
}

Config builder logging configure.

type Level

type Level int8
const (
	LogAll Level = iota
	LogDebug
	LogInfo
	LogWarn
	LogError
	LogNone
)

logging Level constant

func CoverLevel added in v1.1.2

func CoverLevel(lvl string, defLevel Level) Level

CoverLevel cover input string level into `Level` Deprecated: replace by the func `ToLevel`

func ToLevel added in v1.2.0

func ToLevel(lvl string, args ...Level) (Level, error)

ToLevel turn string to level

type Logger

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

func NewLogger

func NewLogger(cfgs ...Config) *Logger

NewLogger build a simple logger user it.

Example
lg := NewLogger(Config{Level: "error"})
lg.Debugf("it's a debug level message")
lg.Warnf("it's a warn level message")
lg.Errorf("it's a error level message")
Output:

10:19:38 [ERROR] it's a error level message

func (*Logger) Buffer added in v1.1.1

func (l *Logger) Buffer() *bytes.Buffer

func (*Logger) DebugFunc added in v1.1.1

func (l *Logger) DebugFunc(callback func() string)

func (*Logger) Debugf

func (l *Logger) Debugf(message string, args ...any)

func (*Logger) ErrorFunc added in v1.1.1

func (l *Logger) ErrorFunc(callback func() string)

func (*Logger) Errorf

func (l *Logger) Errorf(message string, args ...any)

func (*Logger) Format

func (l *Logger) Format(prefix, message string, args ...any)

func (*Logger) InfoFunc added in v1.1.1

func (l *Logger) InfoFunc(callback func() string)

func (*Logger) Infof

func (l *Logger) Infof(message string, args ...any)

func (*Logger) Log

func (l *Logger) Log() *log.Logger

Log get embed go lib log when you need the instance.

func (*Logger) WarnFunc added in v1.1.1

func (l *Logger) WarnFunc(callback func() string)

func (*Logger) Warnf

func (l *Logger) Warnf(message string, args ...any)

Directories

Path Synopsis
Package lgr An instance of library `logger`, used for direct output from the command line, etc
Package lgr An instance of library `logger`, used for direct output from the command line, etc

Jump to

Keyboard shortcuts

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