log

package module
v0.0.0-...-2513a1b Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: Unlicense Imports: 12 Imported by: 0

README

log

Logger and metadata embedding tools for easy trace logs

Documentation

Overview

Package log is a logging subsystem that provides code optional location tracing and semi-automated subsystem registration and output control.

Index

Constants

View Source
const (
	// URL is the git URL for the repository.
	URL = "git.indra-labs.org/dev/log"
	// GitRef is the gitref, as in refs/heads/branchname.
	GitRef = "refs/heads/main"
	// ParentGitCommit is the commit hash of the parent HEAD.
	ParentGitCommit = "d3de549b38757515404d942687afcae7a160f2a8"
	// BuildTime stores the time when the current binary was built.
	BuildTime = "2023-09-11T07:27:33+01:00"
	// SemVer lists the (latest) git tag on the release.
	SemVer = "v0.0.4"
	// Major is the major number from the tag.
	Major = 0
	// Minor is the minor number from the tag.
	Minor = 0
	// Patch is the patch version number from the tag.
	Patch = 4
)

Variables

View Source
var (
	// LevelSpecs specifies the id, string name and color-printing function
	LevelSpecs = map[LogLevel]LevelSpec{
		Off:   gLS(Off, 0, 0, 0),
		Fatal: gLS(Fatal, 255, 0, 0),
		Error: gLS(Error, 255, 128, 0),
		Check: gLS(Check, 255, 255, 0),
		Warn:  gLS(Warn, 255, 255, 0),
		Info:  gLS(Info, 0, 255, 0),
		Debug: gLS(Debug, 0, 128, 255),
		Trace: gLS(Trace, 128, 0, 255),
	}
	// LocTimeStampFormat is a custom time format that provides millisecond precision.
	LocTimeStampFormat = "2006-01-02T15:04:05.000000"
	// LvlStr is a map that provides the uniform width strings that are printed
	// to identify the LogLevel of a log entry.
	LvlStr = LevelMap{
		Off:   "off",
		Fatal: "fatal",
		Error: "error",
		Warn:  "warn",
		Info:  "info",
		Check: "check",
		Debug: "debug",
		Trace: "trace",
	}

	// App is the name of the application. Change this at the beginning of
	// an application main.
	App     atomic.String
	Longest atomic.Uint32
)
View Source
var CI = "false"
View Source
var MaxLen = 0

Functions

func Add

func Add() (subsystem string)

Add adds a subsystem to the list of known subsystems and returns the string.

func GetAllSubsystems

func GetAllSubsystems() (o []string)

func GetLevelName

func GetLevelName(ll LogLevel) string

func GetLoc

func GetLoc(skip int, subsystem string) (output string)

GetLoc calls runtime.Caller and formats as expected by source code editors for terminal hyperlinks

Regular expressions and the substitution texts to make these clickable in Tilix and other RE hyperlink configurable terminal emulators:

This matches the shortened paths generated in this command and printed at the very beginning of the line as this logger prints:

^((([\/a-zA-Z@0-9-_.]+/)+([a-zA-Z@0-9-_.]+)):([0-9]+))
/usr/local/bin/goland --line $5 $GOPATH/src/github.com/p9c/matrjoska/$2

I have used a shell variable there but tilix doesn't expand them, so put your GOPATH in manually, and obviously change the repo subpath.

func SetLogFilePath

func SetLogFilePath(p string) (err error)

func SetLogLevel

func SetLogLevel(l LogLevel)

func SetTimeStampFormat

func SetTimeStampFormat(format string)

SetTimeStampFormat sets a custom timeStampFormat for the logger

func StartLogToFile

func StartLogToFile() (err error)

func StopLogToFile

func StopLogToFile() (err error)

func Version

func Version() string

Version returns a pretty printed version information string.

Types

type Chk

type Chk func(e error) bool

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

type LevelMap

type LevelMap map[LogLevel]string

func (LevelMap) String

func (l LevelMap) String() (s string)

type LevelPrinter

type LevelPrinter struct {
	Ln Println
	// F prints like fmt.Println surrounded by log details
	F Printf
	// S uses spew.dump to show the content of a variable
	S Prints
	// C accepts a function so that the extra computation can be avoided if
	// it is not being viewed
	C Printc
	// Chk is a shortcut for printing if there is an error, or returning
	// true
	Chk Chk
}

LevelPrinter defines a set of terminal printing primitives that output with extra data, time, level, and code location

type LevelSpec

type LevelSpec struct {
	Name      string
	Colorizer func(format string, a ...interface{}) string
}

LevelSpec is a key pair of log level and the text colorizer used for it.

type LogLevel

type LogLevel int32

LogLevel is a code representing a scale of importance and context for log entries.

const (
	Off LogLevel = iota
	Fatal
	Error
	Check
	Warn
	Info
	Debug
	Trace
)

The LogLevel settings used in proc

func GetLevelByString

func GetLevelByString(lvl string, def LogLevel) (ll LogLevel)

func GetLogLevel

func GetLogLevel() (l LogLevel)

type Logger

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

Logger is a set of log printers for the various LogLevel items.

func GetLogger

func GetLogger(maxLen int) (l *Logger)

GetLogger returns a set of LevelPrinter with their subsystem preloaded

type Printc

type Printc func(closure func() string)

Printc accepts a function so that the extra computation can be avoided if it is not being viewed

type Printf

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

Printf prints like fmt.Println surrounded by log details

type Println

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

Println prints lists of interfaces with spaces in between

type Prints

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

Prints prints a spew.Sdump for an interface slice

Directories

Path Synopsis
cmd
bumper
Bumper is a tool for creating version information to be placed at the repository root of a project.
Bumper is a tool for creating version information to be placed at the repository root of a project.

Jump to

Keyboard shortcuts

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