lol

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2024 License: CC0-1.0 Imports: 9 Imported by: 1

README

lol

location of log

This is a very simple, but practical library for logging in applications. Its main feature is printing source code locations to make debugging easier.

Documentation

Index

Constants

View Source
const (
	Off = iota
	Fatal
	Error
	Warn
	Info
	Debug
	Trace
)

Variables

View Source
var LevelNames = []string{
	"off",
	"fatal",
	"error",
	"warn",
	"info",
	"debug",
	"trace",
}
View Source
var (

	// 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},
	}
)
View Source
var Main = &Logger{}

Functions

func BreakTo80 added in v1.0.3

func BreakTo80(s string) (out string)

func GetLoc

func GetLoc(skip int) (output string)

func JoinStrings

func JoinStrings(a ...any) (s string)

func New

func New(writer io.Writer) (l *Log, c *Check, errorf *Errorf)

func NoSprint

func NoSprint(a ...any) string

func SetLogLevel

func SetLogLevel(level string)

func SetLoggers

func SetLoggers(level int)

func Timestamper

func Timestamper() (s string)

Timestamper e

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
}

type Chk

type Chk func(e error) bool

Chk is a shortcut for printing if there is an error, or returning true

type Entry

type Entry struct {
	Time         time.Time
	Level        string
	Package      string
	CodeLocation string
	Text         string
}

Entry is a log entry to be printed as json to the log file

type Err

type Err func(format string, a ...interface{}) error

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
}

type F

type F func(format string, a ...interface{})

F prints like fmt.Println surrounded by log details

type LevelPrinter

type LevelPrinter struct {
	Ln
	F
	S
	C
	Chk
	Err
}

func GetNullPrinter

func GetNullPrinter() LevelPrinter

func GetPrinter

func GetPrinter(l int32, writer io.Writer) LevelPrinter

type LevelSpec

type LevelSpec struct {
	ID        int
	Name      string
	Colorizer func(a ...interface{}) string
}

type Ln

type Ln func(a ...interface{})

Ln prints lists of interfaces with spaces in between

type Log

type Log struct {
	F, E, W, I, D, T LevelPrinter
}

Log is a set of log printers for the various Level items.

type Logger

type Logger struct {
	*Log
	*Check
	*Errorf
}

type S

type S func(a ...interface{})

S prints a spew.Sdump for an enveloper slice

Jump to

Keyboard shortcuts

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