penlogger

package module
v0.0.0-...-8a2b175 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2021 License: Apache-2.0 Imports: 14 Imported by: 10

Documentation

Overview

Package penlogger implements the penlog(7) specification.

Index

Constants

View Source
const (
	ColorNop    = ""
	ColorReset  = "\033[0m"
	ColorBold   = "\033[1m"
	ColorRed    = "\033[31m"
	ColorGreen  = "\033[32m"
	ColorYellow = "\033[33m"
	ColorBlue   = "\033[34m"
	ColorPurple = "\033[35m"
	ColorCyan   = "\033[36m"
	ColorWhite  = "\033[37m"
	ColorGray   = "\033[0;38;5;245m"
)

Variables

This section is empty.

Functions

func Colorize

func Colorize(color, s string) string

Types

type HRDialect

type HRDialect int
const (
	HRTiny HRDialect = iota
	HRNano
	HRFull
)

type HRFormatter

type HRFormatter struct {
	Timespec        string
	CompLen         int
	TypeLen         int
	LogFmt          string
	LogLevel        Prio
	ShowColors      bool
	ShowLines       bool
	ShowStacktraces bool
	ShowLevelPrefix bool
	ShowID          bool
	ShowTags        bool
	Dialect         HRDialect
}

func NewHRFormatter

func NewHRFormatter() *HRFormatter

func (*HRFormatter) Format

func (f *HRFormatter) Format(msg map[string]interface{}) (string, error)

type Logger

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

func NewLogger

func NewLogger(component string, w io.Writer) *Logger

func (*Logger) Log

func (l *Logger) Log(msg map[string]interface{})

Log is the lowest level logging primitive. Any fields can be added to the emitted logging message. The penlog fields id, timestamp, timezone, component, host, line, and stacktrace are added by the underlying logic. Besides this any field can be added. Be aware of the mandatory fields in the penlog(7) specification. There might be dragons.

func (*Logger) LogCritical

func (l *Logger) LogCritical(v ...interface{})

func (*Logger) LogCriticalTagged

func (l *Logger) LogCriticalTagged(tags []string, v ...interface{})

func (*Logger) LogCriticalTaggedf

func (l *Logger) LogCriticalTaggedf(tags []string, format string, v ...interface{})

func (*Logger) LogCriticalf

func (l *Logger) LogCriticalf(format string, v ...interface{})

func (*Logger) LogDebug

func (l *Logger) LogDebug(v ...interface{})

func (*Logger) LogDebugTagged

func (l *Logger) LogDebugTagged(tags []string, v ...interface{})

func (*Logger) LogDebugTaggedf

func (l *Logger) LogDebugTaggedf(tags []string, format string, v ...interface{})

func (*Logger) LogDebugf

func (l *Logger) LogDebugf(format string, v ...interface{})

func (*Logger) LogError

func (l *Logger) LogError(v ...interface{})

func (*Logger) LogErrorTagged

func (l *Logger) LogErrorTagged(tags []string, v ...interface{})

func (*Logger) LogErrorTaggedf

func (l *Logger) LogErrorTaggedf(tags []string, format string, v ...interface{})

func (*Logger) LogErrorf

func (l *Logger) LogErrorf(format string, v ...interface{})

func (*Logger) LogInfo

func (l *Logger) LogInfo(v ...interface{})

func (*Logger) LogInfoTagged

func (l *Logger) LogInfoTagged(tags []string, v ...interface{})

func (*Logger) LogInfoTaggedf

func (l *Logger) LogInfoTaggedf(tags []string, format string, v ...interface{})

func (*Logger) LogInfof

func (l *Logger) LogInfof(format string, v ...interface{})

func (*Logger) LogMessage

func (l *Logger) LogMessage(msgType string, prio Prio, tags []string, v ...interface{})

LogMessage is a higher level interface for emitting log messages. In contrast to Log it is not possible to emit invalid messages by accident. The following penlog fields are filled: data, type, priority tags. Tags might be nil.

func (*Logger) LogMessagef

func (l *Logger) LogMessagef(msgType string, prio Prio, tags []string, format string, v ...interface{})

LogMessagef is the same as LogMessage except that it takes a Printf like format string and the relevant arguments.

func (*Logger) LogNotice

func (l *Logger) LogNotice(v ...interface{})

func (*Logger) LogNoticef

func (l *Logger) LogNoticef(format string, v ...interface{})

func (*Logger) LogTrace

func (l *Logger) LogTrace(v ...interface{})

func (*Logger) LogTraceTagged

func (l *Logger) LogTraceTagged(tags []string, v ...interface{})

func (*Logger) LogTraceTaggedf

func (l *Logger) LogTraceTaggedf(tags []string, format string, v ...interface{})

func (*Logger) LogTracef

func (l *Logger) LogTracef(format string, v ...interface{})

func (*Logger) LogWarning

func (l *Logger) LogWarning(v ...interface{})

func (*Logger) LogWarningTagged

func (l *Logger) LogWarningTagged(tags []string, v ...interface{})

func (*Logger) LogWarningTaggedf

func (l *Logger) LogWarningTaggedf(tags []string, format string, v ...interface{})

func (*Logger) LogWarningf

func (l *Logger) LogWarningf(format string, v ...interface{})

func (*Logger) Print

func (l *Logger) Print(v ...interface{})

func (*Logger) Printf

func (l *Logger) Printf(format string, v ...interface{})

func (*Logger) SetColors

func (l *Logger) SetColors(enable bool)

func (*Logger) SetIncludeUUID

func (l *Logger) SetIncludeUUID(enabled bool)

func (*Logger) SetLevelPrefix

func (l *Logger) SetLevelPrefix(enable bool)

func (*Logger) SetLines

func (l *Logger) SetLines(enable bool)

func (*Logger) SetLogLevel

func (l *Logger) SetLogLevel(prio Prio)

func (*Logger) SetStacktrace

func (l *Logger) SetStacktrace(enable bool)

func (*Logger) Write

func (l *Logger) Write(p []byte) (int, error)

Write is the implemantation of the Go Writer interface. This method is very limited; it emits messages of type "message" at the priority info. The writer interface might be useful to pass a penlog logger to a library which supports a Writer for logging purposes.

type OutType

type OutType int
const (
	OutTypeHR OutType = iota
	OutTypeHRTiny
	OutTypeJSON
	OutTypeJSONPretty
	OutTypeSystemdJournal
)

type Prio

type Prio int
const (
	PrioEmergency Prio = iota
	PrioAlert
	PrioCritical
	PrioError
	PrioWarning
	PrioNotice
	PrioInfo
	PrioDebug
	PrioTrace
)

RFC5424 Section 6.2.1

Jump to

Keyboard shortcuts

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