logging

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Levels = []string{"TRACE", "DEBUG", "INFO", "WARN", "ERR"}

Levels are the log levels we respond too.

View Source
var LogLevel = ""

LogLevel is the log level of all logs in this package it is set by the Setup() function and is shared with all other setup variations (i.e. SetupLocal())

Functions

func DisableLogging added in v0.5.0

func DisableLogging()

func Setup

func Setup(config *Config) error

Setup takes as an arugment a configuration and then uses it to configure the global logger. After setup logging.Global() can be used to access the global logger

func WithContext added in v0.4.0

func WithContext(ctx context.Context, logger Logger, args ...interface{}) context.Context

WithContext stores a Logger and any provided arguments into the provided context to access this logger, use the FromContext function

Types

type Config

type Config struct {
	// Level is the log level to use.
	Level string

	// Syslog and SyslogFacility is the syslog configuration options.
	Syslog         bool
	SyslogFacility string

	// SyslogName is the progname as it will appear in syslog output (if enabled).
	SyslogName string

	// Writer is the output where logs should go. If syslog is enabled, data will
	// be written to writer in addition to syslog.
	Writer io.Writer
}

Config is the configuration for this log setup.

type Level added in v0.7.0

type Level = hclog.Level

Alias the hclog levels so that the hclog package doesn't need to be exposed for `logger.Log(...)` calls.

const (
	NoLevel Level = hclog.NoLevel
	Trace   Level = hclog.Trace
	Debug   Level = hclog.Debug
	Info    Level = hclog.Info
	Warn    Level = hclog.Warn
	Error   Level = hclog.Error
	Off     Level = hclog.Off
)

type Logger added in v0.4.0

type Logger hclog.Logger

Logger is a type alias for hclog.Logger

func FromContext added in v0.4.0

func FromContext(ctx context.Context) Logger

FromContext returns the Logger contained with the context. If no Logger is found in the context, this function returns the Global Logger

func Global added in v0.4.0

func Global() Logger

Global returns the hclog.Default() global logger as type Logger

func NewNullLogger added in v0.4.0

func NewNullLogger() Logger

NewNullLogger returns the hclog.NewNullLogger() null logger as type Logger

func NewTestLogger added in v0.6.0

func NewTestLogger(logLevel string, output io.Writer) Logger

NewTestLogger configures a new logger using a provided logLevel and output and returns the new hclog.Logger as type Logger

func SetupLocal added in v0.3.0

func SetupLocal(writer io.Writer, systemName string, subsystemName string, values ...interface{}) (Logger, error)

SetupLocal returns a new log.Logger which logs to a provided io.Writer The logger will filter logs based on the global log level

type SyslogWrapper

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

SyslogWrapper is used to cleanup log messages before writing them to a Syslogger. Implements the io.Writer interface.

func (*SyslogWrapper) Write

func (s *SyslogWrapper) Write(p []byte) (int, error)

Write is used to implement io.Writer.

Jump to

Keyboard shortcuts

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