log2

package
v0.240727.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2024 License: CC0-1.0 Imports: 9 Imported by: 0

Documentation

Overview

Package log2 solves these issues: - log level filtering, e.g. show debug messages in internal tests only - safe concurrent change of log level

Primary goal was to run parallel tests and log into t.Logf() safely, and TBH, would have been enough to pass around explicit stdlib *log.Logger. Well, log levels is just a cherry on top.

Index

Constants

View Source
const (
	// type specified here helped against accidentally passing flags as level
	Lmicroseconds     int = log.Lmicroseconds
	Lshortfile        int = log.Lshortfile
	LStdFlags         int = log.Ltime | Lshortfile
	LInteractiveFlags int = log.Ltime | Lshortfile | Lmicroseconds
	LServiceFlags     int = Lshortfile
	LTestFlags        int = Lshortfile | Lmicroseconds
)
View Source
const (
	LOG_EMERG = iota
	LOG_ALERT
	LOG_CRIT
	LOG_ERR
	LOG_WARNING
	LOG_NOTICE
	LOG_INFO
	LOG_DEBUG
)
View Source
const ContextKey = "run/log"

Variables

View Source
var ErrStr string

Functions

This section is empty.

Types

type ErrorFunc

type ErrorFunc func(error)

type FmtFunc

type FmtFunc func(format string, args ...interface{})

type FmtFuncWriter

type FmtFuncWriter struct{ FmtFunc }

func (FmtFuncWriter) Write

func (ffw FmtFuncWriter) Write(b []byte) (int, error)

type Level

type Level int32

type Log

type Log struct {
	// contains filtered or unexported fields
}

func ContextValueLogger

func ContextValueLogger(ctx context.Context) *Log

func NewFunc

func NewFunc(f FmtFunc, level Level) *Log

func NewStderr

func NewStderr(level Level) *Log

func NewTest

func NewTest(t testing.TB, level Level) *Log

func NewWriter

func NewWriter(w io.Writer, level Level) *Log

func (*Log) Clone

func (lg *Log) Clone(level Level) *Log

func (*Log) Debug

func (lg *Log) Debug(args ...interface{})

func (*Log) Debugf

func (lg *Log) Debugf(format string, args ...interface{})

func (*Log) Enabled

func (lg *Log) Enabled(level Level) bool

func (*Log) Err added in v0.220725.0

func (lg *Log) Err(args ...interface{})

func (*Log) Errf added in v0.220725.0

func (lg *Log) Errf(format string, args ...interface{})

func (*Log) Error

func (lg *Log) Error(args ...interface{})
func (lg *Log) Error(args ...interface{}) {
	lg.Log(LOG_ERR, "error: "+fmt.Sprint(args...))
	if lg == nil {
		return
	}
	if errfun := lg.loadErrorFunc(); errfun != nil {
		var e error
		if len(args) >= 1 {
			e, _ = args[0].(error)
		}
		if e != nil {
			args = args[1:]
			if len(args) > 0 { // Log.Error(err, arg1) please don't do this
				rest := fmt.Sprint(args...)
				e = errors.Annotate(e, rest)
			}
			errfun(e)
		}
	}
}

func (*Log) Errorf

func (lg *Log) Errorf(format string, args ...interface{})

func (*Log) Fatal

func (lg *Log) Fatal(args ...interface{})

func (*Log) Fatalf

func (lg *Log) Fatalf(format string, args ...interface{})

func (*Log) Info

func (lg *Log) Info(args ...interface{})

func (*Log) Infof

func (lg *Log) Infof(format string, args ...interface{})

func (*Log) Log

func (lg *Log) Log(level Level, s string)

func (*Log) LogToConsole added in v0.220725.0

func (l *Log) LogToConsole()

func (*Log) LogToSyslog added in v0.220725.0

func (l *Log) LogToSyslog(tag string)

func (*Log) Logf

func (lg *Log) Logf(level Level, format string, args ...interface{})

func (*Log) Notice added in v0.220725.0

func (lg *Log) Notice(args ...interface{})

func (*Log) NoticeF added in v0.220725.0

func (lg *Log) NoticeF(format string, args ...interface{})

func (*Log) Printf

func (lg *Log) Printf(format string, args ...interface{})

compatibility with eclipse.paho.mqtt

func (*Log) Println

func (lg *Log) Println(args ...interface{})

func (*Log) SetErrorFunc

func (lg *Log) SetErrorFunc(f ErrorFunc)

func (*Log) SetFlags

func (lg *Log) SetFlags(f int)

func (*Log) SetLevel

func (lg *Log) SetLevel(l Level)

func (*Log) SetOutput

func (lg *Log) SetOutput(w io.Writer)

func (*Log) SetPrefix

func (lg *Log) SetPrefix(prefix string)

func (*Log) Stdlib

func (lg *Log) Stdlib() *log.Logger

func (*Log) Warning added in v0.220725.0

func (lg *Log) Warning(args ...interface{})

func (*Log) WarningF added in v0.220725.0

func (lg *Log) WarningF(format string, args ...interface{})

Jump to

Keyboard shortcuts

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