Documentation
¶
Overview ¶
Package lol (log of location) is a simple logging library that prints a high precision unix timestamp and the source location of a log print to make tracing errors simpler. Includes a set of logging levels and the ability to filter out higher log levels for a more quiet output.
Index ¶
- Constants
- Variables
- func GetLoc(skip int) (output string)
- func GetLogLevel(level string) (i int)
- func GetNLoc(n int) (output string)
- func JoinStrings(a ...any) (s string)
- func New(writer io.Writer, skip int) (l *Log, c *Check, errorf *Errorf)
- func NoSprint(a ...any) string
- func SetLogLevel(level string)
- func SetLoggers(level int)
- func TimeStamper() (s string)
- type C
- type Check
- type Chk
- type Entry
- type Err
- type Errorf
- type F
- type LevelPrinter
- type LevelSpec
- type Ln
- type Log
- type Logger
- type S
Constants ¶
const ( Off = iota Fatal Error Warn Info Debug Trace )
Variables ¶
var ( // Writer can be swapped out for any io.*Writer* that you want to use instead of stdout. Writer io.Writer = os.Stderr // LevelSpecs specifies the id, string name and color-printing function LevelSpecs = []LevelSpec{ {Off, "", NoSprint}, {Fatal, "FTL", color.New(color.BgRed, color.FgHiWhite).Sprint}, {Error, "ERR", color.New(color.FgHiRed).Sprint}, {Warn, "WRN", color.New(color.FgHiYellow).Sprint}, {Info, "INF", color.New(color.FgHiGreen).Sprint}, {Debug, "DBG", color.New(color.FgHiBlue).Sprint}, {Trace, "TRC", color.New(color.FgHiMagenta).Sprint}, } NoTimeStamp atomic.Bool ShortLoc atomic.Bool )
var Level atomic.Int32
Level is the level that the logger is printing at.
var LevelNames = []string{
"off",
"fatal",
"error",
"warn",
"info",
"debug",
"trace",
}
var Main = &Logger{}
Main is the main logger.
var Tracer = getTracer()
Functions ¶
func GetLogLevel ¶
GetLogLevel returns the log level number of a string log level.
func JoinStrings ¶
JoinStrings joins together anything into a set of strings with space separating the items.
Types ¶
type C ¶
type C func(closure func() string)
C accepts a function so that the extra computation can be avoided if it is not being viewed
type Check ¶
type Check struct {
F, E, W, I, D, T Chk
}
Check is the set of log levels for a Check operation (prints an error if the error is not nil).
type Err ¶
Err is a pass-through function that uses fmt.Errorf to construct an error and returns the error after printing it to the log
type Errorf ¶
type Errorf struct {
F, E, W, I, D, T Err
}
Errorf prints an error that is also returned as an error, so the error is logged at the site.
type F ¶
type F func(format string, a ...interface{})
F prints like fmt.Println surrounded []byte log details
type LevelPrinter ¶
LevelPrinter is the set of log printers on each log level.
func GetNullPrinter ¶
func GetNullPrinter() LevelPrinter
GetNullPrinter is a logger that doesn't log.
func GetPrinter ¶
func GetPrinter(l int32, writer io.Writer, skip int) LevelPrinter
GetPrinter returns a full logger that writes to the provided io.Writer.
type Log ¶
type Log struct {
F, E, W, I, D, T LevelPrinter
}
Log is a set of log printers for the various Level items.