log

package
v4.0.0-...-5981c31 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: BSD-2-Clause, BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_DEPTH = 3

	DefaultID = `gw@1`
)

Variables

View Source
var (
	ErrNotOpen      = errors.New("Logger is not open")
	ErrInvalidLevel = errors.New("Log level is invalid")
)

Functions

func CallLoc

func CallLoc(callDepth int) (s string)

func GenRFCMessage

func GenRFCMessage(ts time.Time, prio rfc5424.Priority, hostname, appname, msgid, msg string, sds ...rfc5424.SDParam) ([]byte, error)

Per RFC5424 https://www.rfc-editor.org/rfc/rfc5424.html#section-6.2.7

There are maximum lengths for some of the fields below:

AppName: 48
ProcID: 128
MsgID: 32
Hostname: 255

func KV

func KV(name string, value interface{}) (r rfc5424.SDParam)

func KVErr

func KVErr(err error) rfc5424.SDParam

func PrintOSInfo

func PrintOSInfo(wtr io.Writer)

Types

type KVLogger

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

func NewLoggerWithKV

func NewLoggerWithKV(l *Logger, sds ...rfc5424.SDParam) *KVLogger

func (*KVLogger) AddKV

func (kvl *KVLogger) AddKV(sds ...rfc5424.SDParam)

AddKVs allows for adding additional KVs to the KV logger

func (KVLogger) Appname

func (m KVLogger) Appname() string

func (*KVLogger) Critical

func (kvl *KVLogger) Critical(msg string, sds ...rfc5424.SDParam) error

Critical writes a CRITICALinfo level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

func (*KVLogger) Debug

func (kvl *KVLogger) Debug(msg string, sds ...rfc5424.SDParam) error

Debug writes a DEBUG level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

func (*KVLogger) Error

func (kvl *KVLogger) Error(msg string, sds ...rfc5424.SDParam) error

Error writes an ERROR level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

func (*KVLogger) GetKV

func (kvl *KVLogger) GetKV() []rfc5424.SDParam

GetKV returns the structured data elements

func (*KVLogger) GetKVMap

func (kvl *KVLogger) GetKVMap() map[string]string

GetKVMap returns the structured data elements as a map[string]string

func (KVLogger) Hostname

func (m KVLogger) Hostname() string

func (*KVLogger) Info

func (kvl *KVLogger) Info(msg string, sds ...rfc5424.SDParam) error

Infof writes an INFO level log to the underlying writer using a format string, if the logging level is higher than DEBUG no action is taken

func (KVLogger) SetAppname

func (m KVLogger) SetAppname(appname string) error

func (KVLogger) SetHostname

func (m KVLogger) SetHostname(hostname string) error

func (*KVLogger) Warn

func (kvl *KVLogger) Warn(msg string, sds ...rfc5424.SDParam) error

Warn writes an WARN level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

type Level

type Level int
const (
	OFF      Level = 0
	DEBUG    Level = 1
	INFO     Level = 2
	WARN     Level = 3
	ERROR    Level = 4
	CRITICAL Level = 5
	FATAL    Level = 6
)

func LevelFromString

func LevelFromString(s string) (l Level, err error)

func (Level) String

func (l Level) String() string

func (Level) Valid

func (l Level) Valid() bool

type LevelRelay

type LevelRelay interface {
	WriteLog(Level, time.Time, string, string) error
	Close() error
}

type Logger

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

func New

func New(wtr io.WriteCloser) (l *Logger)

New creates a new logger with the given writer at log level INFO

func NewDiscardLogger

func NewDiscardLogger() *Logger

func NewFile

func NewFile(f string) (*Logger, error)

NewFile creates a new logger with the first writer being a file The file is created if it does not exist, and is opened in append mode it is safe to use NewFile on existing logs

func NewLevelRelay

func NewLevelRelay(lr LevelRelay) (l *Logger)

NewLevelRelay creates a new logger with just a level relay

func NewStderrLogger

func NewStderrLogger(fileOverride string) (*Logger, error)

func NewStderrLoggerEx

func NewStderrLoggerEx(fileOverride string, cb StderrCallback) (*Logger, error)

func (*Logger) AddLevelRelay

func (l *Logger) AddLevelRelay(r LevelRelay) error

AddLevelRelay will add a new relay which will get all log entries as they are handled.

func (*Logger) AddRelay

func (l *Logger) AddRelay(r Relay) error

AddRelay will add a new relay which will get all log entries as they are handled.

func (*Logger) AddWriter

func (l *Logger) AddWriter(wtr io.WriteCloser) error

AddWriter will add a new writer which will get all the log lines as they are handled.

func (*Logger) Appname

func (m *Logger) Appname() string

func (*Logger) Close

func (l *Logger) Close() (err error)

Close closes the logger and all currently associated writers writers that have been deleted are NOT closed

func (*Logger) Critical

func (l *Logger) Critical(msg string, sds ...rfc5424.SDParam) error

Critical writes a CRITICALinfo level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

func (*Logger) CriticalWithDepth

func (l *Logger) CriticalWithDepth(d int, msg string, sds ...rfc5424.SDParam) error

CriticalfWithDepth writes a CRITICALinfo level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

func (*Logger) Criticalf

func (l *Logger) Criticalf(f string, args ...interface{}) error

Critical writes a CRITICALinfo level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

func (*Logger) CriticalfWithDepthf

func (l *Logger) CriticalfWithDepthf(d int, f string, args ...interface{}) error

CriticalfWithDepth writes a CRITICALinfo level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

func (*Logger) Debug

func (l *Logger) Debug(msg string, sds ...rfc5424.SDParam) error

Debug writes a DEBUG level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

func (*Logger) DebugWithDepth

func (l *Logger) DebugWithDepth(d int, msg string, sds ...rfc5424.SDParam) error

DebugWithDepth writes a DEBUG level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

func (*Logger) Debugf

func (l *Logger) Debugf(f string, args ...interface{}) error

Debug writes a DEBUG level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

func (*Logger) DebugfWithDepth

func (l *Logger) DebugfWithDepth(d int, f string, args ...interface{}) error

DebugfWithDepth writes a DEBUG level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

func (*Logger) DeleteRelay

func (l *Logger) DeleteRelay(rl Relay) error

DeleteRelay removes a relay from the logger.

func (*Logger) DeleteWriter

func (l *Logger) DeleteWriter(wtr io.Writer) error

DeleteWriter removes a writer from the logger, it will not be closed on logging Close

func (*Logger) EnableRawMode

func (l *Logger) EnableRawMode()

func (*Logger) Error

func (l *Logger) Error(msg string, sds ...rfc5424.SDParam) error

Error writes an ERROR level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

func (*Logger) ErrorWithDepth

func (l *Logger) ErrorWithDepth(d int, msg string, sds ...rfc5424.SDParam) error

ErrorfWithDepth writes an ERROR level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

func (*Logger) Errorf

func (l *Logger) Errorf(f string, args ...interface{}) error

Error writes an ERROR level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

func (*Logger) ErrorfWithDepth

func (l *Logger) ErrorfWithDepth(d int, f string, args ...interface{}) error

ErrorfWithDepth writes an ERROR level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, sds ...rfc5424.SDParam)

Fatal writes a log, closes the logger, and issues an os.Exit(-1)

func (*Logger) FatalCode

func (l *Logger) FatalCode(code int, msg string, sds ...rfc5424.SDParam)

FatalCode is identical to a log.Fatal, except it allows for controlling the exit code

func (*Logger) Fatalf

func (l *Logger) Fatalf(f string, args ...interface{})

Fatal writes a log, closes the logger, and issues an os.Exit(-1)

func (*Logger) FatalfCode

func (l *Logger) FatalfCode(code int, f string, args ...interface{})

FatalCode is identical to a log.Fatal, except it allows for controlling the exit code

func (*Logger) GetLevel

func (l *Logger) GetLevel() Level

GetLevel returns the current logging level

func (*Logger) Hostname

func (m *Logger) Hostname() string

func (*Logger) Info

func (l *Logger) Info(msg string, sds ...rfc5424.SDParam) error

Infof writes an INFO level log to the underlying writer using a format string, if the logging level is higher than DEBUG no action is taken

func (*Logger) InfoWithDepth

func (l *Logger) InfoWithDepth(d int, msg string, sds ...rfc5424.SDParam) error

InfofWithDepth writes an INFO level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

func (*Logger) Infof

func (l *Logger) Infof(f string, args ...interface{}) error

Infof writes an INFO level log to the underlying writer using a format string, if the logging level is higher than DEBUG no action is taken

func (*Logger) InfofWithDepth

func (l *Logger) InfofWithDepth(d int, f string, args ...interface{}) error

InfofWithDepth writes an INFO level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

func (*Logger) RawMode

func (l *Logger) RawMode() bool

func (*Logger) SetAppname

func (m *Logger) SetAppname(appname string) error

func (*Logger) SetHostname

func (m *Logger) SetHostname(hostname string) error

func (*Logger) SetLevel

func (l *Logger) SetLevel(lvl Level) error

SetLevel sets the log level, Off disables logging and any logging call that is less than the level current level are not logged

func (*Logger) SetLevelString

func (l *Logger) SetLevelString(s string) error

SetLevelString sets the log level using a string, this is a helper function so that you can just hand the config file value directly in

func (*Logger) Warn

func (l *Logger) Warn(msg string, sds ...rfc5424.SDParam) error

Warn writes an WARN level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

func (*Logger) WarnWithDepth

func (l *Logger) WarnWithDepth(d int, msg string, sds ...rfc5424.SDParam) error

WarnfWithDepth writes an WARN level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

func (*Logger) Warnf

func (l *Logger) Warnf(f string, args ...interface{}) error

Warn writes an WARN level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

func (*Logger) WarnfWithDepth

func (l *Logger) WarnfWithDepth(d int, f string, args ...interface{}) error

WarnfWithDepth writes an WARN level log to the underlying writer, if the logging level is higher than DEBUG no action is taken

func (*Logger) Write

func (l *Logger) Write(b []byte) (n int, err error)

implement writer interface so it can be handed to a standard loger

type Relay

type Relay interface {
	WriteLog(time.Time, []byte) error
}

type StderrCallback

type StderrCallback func(io.Writer)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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