log

package
v3.8.31 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: BSD-2-Clause, BSD-2-Clause Imports: 14 Imported by: 5

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 added in v3.8.4

func CallLoc(callDepth int) (s string)

func GenRFCMessage added in v3.8.4

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 added in v3.8.4

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

func KVErr added in v3.8.4

func KVErr(err error) rfc5424.SDParam

func PrintOSInfo added in v3.8.6

func PrintOSInfo(wtr io.Writer)

Types

type KVLogger added in v3.8.5

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

func NewLoggerWithKV added in v3.8.5

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

func (*KVLogger) AddKV added in v3.8.5

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

AddKVs allows for adding additional KVs to the KV logger

func (KVLogger) Appname added in v3.8.5

func (m KVLogger) Appname() string

func (*KVLogger) Critical added in v3.8.5

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 added in v3.8.5

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 added in v3.8.5

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 added in v3.8.23

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

GetKV returns the structured data elements

func (*KVLogger) GetKVMap added in v3.8.23

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

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

func (KVLogger) Hostname added in v3.8.5

func (m KVLogger) Hostname() string

func (*KVLogger) Info added in v3.8.5

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 added in v3.8.5

func (m KVLogger) SetAppname(appname string) error

func (KVLogger) SetHostname added in v3.8.5

func (m KVLogger) SetHostname(hostname string) error

func (*KVLogger) Warn added in v3.8.5

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 added in v3.8.10

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 added in v3.8.26

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 added in v3.8.10

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 added in v3.8.0

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 added in v3.8.0

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 added in v3.8.4

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 added in v3.8.4

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 added in v3.8.4

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 added in v3.8.4

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 added in v3.8.0

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 added in v3.8.0

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 added in v3.8.4

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 added in v3.8.4

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 added in v3.8.4

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

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

func (*Logger) FatalfCode added in v3.8.4

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 added in v3.8.0

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 added in v3.8.4

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 added in v3.8.4

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 added in v3.8.0

func (l *Logger) RawMode() bool

func (*Logger) SetAppname added in v3.8.0

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

func (*Logger) SetHostname added in v3.8.0

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 added in v3.8.4

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 added in v3.8.4

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 added in v3.8.0

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