log

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogQueueSize       = 1024
	ShowCallerFileLine = true
)
View Source
const (
	LogLevelSilent = iota
	LogLevelError
	LogLevelInfo
	LogLevelAudit
	LogLevelDebug
	LogLevelTrace
)

Log levels for use with NewLogger.

Variables

This section is empty.

Functions

func Audit

func Audit(format string, args ...any)

func BlackholeLogf

func BlackholeLogf(format string, args ...any)

Function for use in Logger for discarding logged lines.

func Close

func Close()

func Critical

func Critical(format string, args ...any)

func Debug

func Debug(format string, args ...any)

func Error

func Error(format string, args ...any)

func Evaluate

func Evaluate(format string, args ...any)

func Info

func Info(format string, args ...any)

func SetGlobalLogger

func SetGlobalLogger(l *Logger)

func Stats

func Stats(format string, args ...any)

func Trace

func Trace(format string, args ...any)

func Transaction

func Transaction(format string, args ...any)

func Verbose

func Verbose(format string, args ...any)

func Warning

func Warning(format string, args ...any)

must be called after SetGlobalLogger()

Types

type AsyncLogWriter

type AsyncLogWriter struct {
	sync.Mutex

	DirPath string
	Name    string
	// contains filtered or unexported fields
}

func (*AsyncLogWriter) Close

func (lw *AsyncLogWriter) Close()

func (*AsyncLogWriter) Start

func (lw *AsyncLogWriter) Start()

func (*AsyncLogWriter) Write

func (lw *AsyncLogWriter) Write(buf []byte) (n int, err error)

async writer must be initiated first, implements atomic write

type Logger

type Logger struct {
	sync.Mutex

	Warning     func(format string, args ...any)
	Error       func(format string, args ...any)
	Critical    func(format string, args ...any)
	Evaluate    func(format string, args ...any)
	Info        func(format string, args ...any)
	Stats       func(format string, args ...any)
	Audit       func(format string, args ...any)
	Transaction func(format string, args ...any)
	Debug       func(format string, args ...any)
	Trace       func(format string, args ...any)
	Verbose     func(format string, args ...any)
	// contains filtered or unexported fields
}

A logger that implements async logging by default (logging without impact on real business logic). It also provides customizable logging functions. At default implementation, it is recommended to call Close() at program termination.

func NewLogger

func NewLogger(prepend string, level int, dir string, filename string) *Logger

NewLogger constructs a Logger that logs at the specified log l.logLevel and above. It decorates log lines with the log l.logLevel, date, time, and prepend.

func (*Logger) Close

func (l *Logger) Close()

func (*Logger) DateUpdateChan

func (l *Logger) DateUpdateChan() chan string

func (*Logger) NewSubLogger

func (l *Logger) NewSubLogger(prepend string, level int) *Logger

func (*Logger) SetLogLevel

func (l *Logger) SetLogLevel(level int)

func (*Logger) Writer

func (l *Logger) Writer() io.Writer

Jump to

Keyboard shortcuts

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