logging

package
v0.8.7 Latest Latest
Warning

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

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

Documentation

Overview

Package logging is intended mostly as a set of helper functions around configuring and using a common logger to provide structured, leveled logging.

Index

Constants

View Source
const (

	// LogLevelEmergency represents messages at Emergency level. System is
	// unusable; a panic condition. This level is mapped to logrus.PanicLevel
	// and syslog.LOG_EMERG. logrus calls panic.
	LogLevelEmergency string = "emergency"

	// LogLevelPanic represents messages at Emergency level. System is
	// unusable; a panic condition. This level is mapped to logrus.PanicLevel
	// and syslog.LOG_EMERG. logrus calls panic.
	LogLevelPanic string = "panic"

	// LogLevelAlert represents a condition that should be corrected
	// immediately, such as a corrupted system database. This level is mapped
	// to logrus.FatalLevel and syslog.LOG_ALERT. logrus calls os.Exit(1)
	LogLevelAlert string = "alert"

	// LogLevelFatal is used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	// This level is mapped to logrus.FatalLevel and syslog.LOG_ALERT. logrus
	// calls os.Exit(1)
	LogLevelFatal string = "fatal"

	// LogLevelCritical is for critical conditions, such as hard device
	// errors. This level is mapepd to logrus.FatalLevel and syslog.LOG_CRIT.
	// logrus calls os.Exit(1)
	LogLevelCritical string = "critical"

	// LogLevelError is for errors that should definitely be noted. Commonly
	// used for hooks to send errors to an error tracking service. This level
	// maps to logrus.ErrorLevel and syslog.LOG_ERR.
	LogLevelError string = "error"

	// LogLevelWarn is for non-critical entries that deserve eyes. This level
	// maps to logrus.WarnLevel and syslog.LOG_WARNING.
	LogLevelWarn string = "warn"

	// LogLevelNotice is for normal but significant conditions; conditions
	// that are not error conditions, but that may require special handling.
	// This level maps to logrus.WarnLevel and syslog.LOG_NOTICE.
	LogLevelNotice string = "notice"

	// LogLevelInfo is for general application operational entries. This level
	// maps to logrus.InfoLevel and syslog.LOG_INFO.
	LogLevelInfo string = "info"

	// LogLevelDebug is for debug-level messages and is usually on enabled
	// when debugging. Very verbose logging. This level is mapped to
	// logrus.DebugLevel and syslog.LOG_DEBUG.
	LogLevelDebug string = "debug"

	// LogLevelTrace is for finer-grained informational events than debug.
	// This level maps to logrus.TraceLevel and syslog.LOG_DEBUG.
	LogLevelTrace string = "trace"
)

Log levels

View Source
const (

	// LogFormatText represents the logrus text formatter.
	LogFormatText string = "text"

	// LogFormatJSON represents the logrus JSON formatter.
	LogFormatJSON string = "json"
)

Log formats used by logrus

View Source
const (

	// ConsoleOutputStdout represents os.Stdout
	ConsoleOutputStdout string = "stdout"

	// ConsoleOutputStderr represents os.Stderr
	ConsoleOutputStderr string = "stderr"
)

Variables

This section is empty.

Functions

func EnableSyslogLogging

func EnableSyslogLogging(logger *logrus.Logger, logBuffer *LogBuffer, logLevel string) error

EnableSyslogLogging attempts to enable local syslog logging for non-Windows systems. For Windows systems the attempt is skipped.

func GetLineNumber

func GetLineNumber() int

GetLineNumber is a wrapper around runtime.Caller to return only the current line number from the point this function was called. TODO: Find a better location for this utility function

func SetLoggerConsoleOutput

func SetLoggerConsoleOutput(logger *logrus.Logger, consoleOutput string) error

SetLoggerConsoleOutput configures the chosen console output to one of stdout or stderr.

func SetLoggerFormatter

func SetLoggerFormatter(logger *logrus.Logger, format string) error

SetLoggerFormatter sets a user-specified logging format for the provided logger object.

func SetLoggerLevel

func SetLoggerLevel(logger *logrus.Logger, logLevel string) error

SetLoggerLevel applies the requested logger level to filter out messages with a lower level than the one configured.

func SetLoggerLogFile

func SetLoggerLogFile(logger *logrus.Logger, logFilePath string) (*os.File, error)

SetLoggerLogFile configures a log file as the destination for all log messages. NOTE: If successfully set, console output is muted.

Types

type LogBuffer

type LogBuffer []LogRecord

LogBuffer represents a slice of LogRecord objects

var Buffer LogBuffer

Buffer is a package global instance of LogBuffer intended to ease log message collection for later emission when all required logger settings have been applied.

FIXME: Moved here from Config package What is the best approach to handling this instead of using a package global?

func (*LogBuffer) Add

func (lb *LogBuffer) Add(r LogRecord)

Add passed LogRecord type to slice of LogRecord objects

func (*LogBuffer) Flush

func (lb *LogBuffer) Flush(logger *logrus.Logger) error

Flush LogRecord entries after applying user-provided logging settings

type LogRecord

type LogRecord struct {
	Level   logrus.Level
	Message string
	Fields  logrus.Fields
}

LogRecord holds logrus.Field values along with additional metadata that can be used later to complete the log message submission process.

Jump to

Keyboard shortcuts

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