logs

package
v0.0.0-...-9008a76 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCaller

func GetCaller() *runtime.Frame

GetCaller retrieves the name of the first non-logs calling function

Types

type CustomGraylogHook

type CustomGraylogHook struct {
	*graylog.GraylogHook
	// contains filtered or unexported fields
}

CustomGraylogHook adds a new layer over gemnasium Graylog hook to handle specific cases when trigerred.

func NewCustomGraylogHook

func NewCustomGraylogHook(addr, fieldPrefix string) *CustomGraylogHook

NewCustomGraylogHook creates a hook to be added to an instance of logger.

func (*CustomGraylogHook) Fire

func (g *CustomGraylogHook) Fire(entry *logrus.Entry) error

Fire is called when a log event is fired.

type LogMsg

type LogMsg interface {
	// Str adds a tag to the message of type string.
	Str(key, val string) LogMsg
	// I64 adds a tag to the message of type int64.
	I64(key string, val int64) LogMsg
	// F64 adds a tag to the message of type float64.
	F64(key string, val float64) LogMsg
	// Bool adds a tag to the message of type bool.
	Bool(key string, val bool) LogMsg

	// Send the message that has been constructed.
	Send()
}

LogMsg is a message entry that can be built and is not sent until is explicitly told to be sent.

type Logger

type Logger interface {
	// Trace logs a message with the trace level
	Trace(msg string)
	// Debug logs a message with the debug level
	Debug(msg string)
	// Info logs a message with the info level
	Info(msg string)
	// Warn logs a message with the warn level
	Warn(msg string)
	// Err logs a message with the error level
	Err(err error, msg string)
	// Fatal logs a message with the fatal level
	Fatal(msg string)
	// Panic logs a message with the fatal level
	Panic(msg string)

	// TraceMsg creates a LogMsg that inherit the logger
	// tags with a trace level.
	TraceMsg(msg string) LogMsg
	// DebugMsg creates a LogMsg that inherit the logger
	// tags with a debug level.
	DebugMsg(msg string) LogMsg
	// InfoMsg creates a LogMsg that inherit the logger
	// tags with a info level.
	InfoMsg(msg string) LogMsg
	// WarnMsg creates a LogMsg that inherit the logger
	// tags with a warn level.
	WarnMsg(msg string) LogMsg
	// ErrMsg creates a LogMsg that inherit the logger
	// tags with a error level.
	ErrMsg(err error, msg string) LogMsg
	// FatalMsg creates a LogMsg that inherit the logger
	// tags with a fatal level.
	FatalMsg(msg string) LogMsg
	// PanicMsg creates a LogMsg that inherit the logger
	// tags with a panic level.
	PanicMsg(msg string) LogMsg

	// Str adds a tag to the logger of type string
	Str(key, val string) Logger
	// I64 adds a tag to the logger of type int64
	I64(key string, val int64) Logger
	// F64 adds a tag to the logger of type float64
	F64(key string, val float64) Logger
	// Bool adds a tag to the logger of type bool
	Bool(key string, val bool) Logger

	// Labels sets labels for a logger in a batchl
	Labels(map[string]interface{}) Logger

	// Clone a logger, so from that point labels
	// will not be shared anymore.
	Clone() Logger
}

Logger defines the interface to log data. Most of the calls return the same Logger interface so we can easily chain calls, like l.Str("foo", "bar").I64("count", 3).Trace("blab").

type LoggerBuilderFn

type LoggerBuilderFn func() Logger

LoggerBuilderFn is the type required to instantiate a new Logger.

func NewLogrusBuilder

func NewLogrusBuilder(conf *LogrusConf) (LoggerBuilderFn, func(), error)

NewLogrusBuilder returns a function to create Logrus loggers

func NewMultiLoggerBuilder

func NewMultiLoggerBuilder(wrappedFns ...LoggerBuilderFn) LoggerBuilderFn

NewMultiLoggerBuilder returns a function to create MultiLogger loggers.

func NewNopLoggerBuilder

func NewNopLoggerBuilder() LoggerBuilderFn

NewNopLoggerBuilder returns a function to construct NopLogger.

func NewSentryBuilder

func NewSentryBuilder(conf *SentryConf) (LoggerBuilderFn, func(), error)

NewSentryBuilder returns a function to create Sentry loggers.

type Logrus

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

Logrus is the logger to work with logrus.

func NewLogrus

func NewLogrus(w io.Writer) *Logrus

NewLogrus creates a new Logrus logger

func (*Logrus) Bool

func (lr *Logrus) Bool(key string, val bool) Logger

Bool adds a tag to the logger of type bool

func (*Logrus) Clone

func (lr *Logrus) Clone() Logger

Clone clones a Logrus logger.

func (*Logrus) Debug

func (lr *Logrus) Debug(msg string)

Debug logs a message with the debug level

func (*Logrus) DebugMsg

func (lr *Logrus) DebugMsg(msg string) LogMsg

DebugMsg creates a LogMsg that inherit the logger tags with a debug level.

func (*Logrus) Err

func (lr *Logrus) Err(err error, msg string)

Err logs a message with the error level

func (*Logrus) ErrMsg

func (lr *Logrus) ErrMsg(err error, msg string) LogMsg

ErrMsg creates a LogMsg that inherit the logger tags with a error level.

func (*Logrus) F64

func (lr *Logrus) F64(key string, val float64) Logger

F64 adds a tag to the logger of type float64

func (*Logrus) Fatal

func (lr *Logrus) Fatal(msg string)

Fatal logs a message with the fatal level

func (*Logrus) FatalMsg

func (lr *Logrus) FatalMsg(msg string) LogMsg

FatalMsg creates a LogMsg that inherit the logger tags with a fatal level.

func (*Logrus) I64

func (lr *Logrus) I64(key string, val int64) Logger

I64 adds a tag to the logger of type int64

func (*Logrus) Info

func (lr *Logrus) Info(msg string)

Info logs a message with the info level

func (*Logrus) InfoMsg

func (lr *Logrus) InfoMsg(msg string) LogMsg

InfoMsg creates a LogMsg that inherit the logger tags with a info level.

func (*Logrus) Labels

func (lr *Logrus) Labels(labels map[string]interface{}) Logger

Labels sets labels for a logger in a batch

func (*Logrus) Panic

func (lr *Logrus) Panic(msg string)

Panic logs a message with the fatal level

func (*Logrus) PanicMsg

func (lr *Logrus) PanicMsg(msg string) LogMsg

PanicMsg creates a LogMsg that inherit the logger tags with a panic level.

func (*Logrus) Str

func (lr *Logrus) Str(key, val string) Logger

Str adds a tag to the logger of type string

func (*Logrus) Trace

func (lr *Logrus) Trace(msg string)

Trace logs a message with the trace level

func (*Logrus) TraceMsg

func (lr *Logrus) TraceMsg(msg string) LogMsg

TraceMsg creates a LogMsg that inherit the logger tags with a trace level.

func (*Logrus) Warn

func (lr *Logrus) Warn(msg string)

Warn logs a message with the warn level

func (*Logrus) WarnMsg

func (lr *Logrus) WarnMsg(msg string) LogMsg

WarnMsg creates a LogMsg that inherit the logger tags with a warn level.

type LogrusConf

type LogrusConf struct {
	// OutFileName is the file were we want to output the logs.
	OutFileName string

	// GraylogHost if not empty will report directly to graylog.
	GraylogHost string
	// GraylogFieldPrefix to add a prefix to all graylog logs.
	GraylogFieldPrefix string
}

LogrusConf contains the values to configure a Logrus parser.

type LogrusMsg

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

LogrusMsg is a message entry that can be built and is not sent until is explicitly told to be sent.

func (*LogrusMsg) Bool

func (lm *LogrusMsg) Bool(key string, val bool) LogMsg

Bool adds a tag to the message of type bool.

func (*LogrusMsg) F64

func (lm *LogrusMsg) F64(key string, val float64) LogMsg

F64 adds a tag to the message of type float64.

func (*LogrusMsg) I64

func (lm *LogrusMsg) I64(key string, val int64) LogMsg

I64 adds a tag to the message of type int64.

func (*LogrusMsg) Send

func (lm *LogrusMsg) Send()

Send the message that has been constructed.

func (*LogrusMsg) Str

func (lm *LogrusMsg) Str(key, val string) LogMsg

Str adds a tag to the message of type string.

type MultiLogMsg

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

MultiLogMsg is a LogMsg that sends log mesages to multiple other loggers.

func (*MultiLogMsg) Bool

func (lm *MultiLogMsg) Bool(key string, val bool) LogMsg

Bool adds a tag to the message of type bool.

func (*MultiLogMsg) F64

func (lm *MultiLogMsg) F64(key string, val float64) LogMsg

F64 adds a tag to the message of type float64.

func (*MultiLogMsg) I64

func (lm *MultiLogMsg) I64(key string, val int64) LogMsg

I64 adds a tag to the message of type int64.

func (*MultiLogMsg) Send

func (lm *MultiLogMsg) Send()

Send the message that has been constructed.

func (*MultiLogMsg) Str

func (lm *MultiLogMsg) Str(key, val string) LogMsg

Str adds a tag to the message of type string.

type MultiLogger

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

MultiLogger is a logger that can wrap several other loggers an send the logs those multiple other instances.

func NewMultiLogger

func NewMultiLogger(wrapped ...Logger) *MultiLogger

NewMultiLogger crates a new logger that will forward log messages to the list of wrapped loggers.

func (*MultiLogger) Bool

func (l *MultiLogger) Bool(key string, val bool) Logger

Bool adds a tag to the logger of type bool

func (*MultiLogger) Clone

func (l *MultiLogger) Clone() Logger

Clone a MultiLogger logger.

func (*MultiLogger) Debug

func (l *MultiLogger) Debug(msg string)

Debug logs a message with the debug level

func (*MultiLogger) DebugMsg

func (l *MultiLogger) DebugMsg(msg string) LogMsg

DebugMsg creates a LogMsg that inherit the logger tags with a debug level.

func (*MultiLogger) Err

func (l *MultiLogger) Err(err error, msg string)

Err logs a message with the error level

func (*MultiLogger) ErrMsg

func (l *MultiLogger) ErrMsg(err error, msg string) LogMsg

ErrMsg creates a LogMsg that inherit the logger tags with a error level.

func (*MultiLogger) F64

func (l *MultiLogger) F64(key string, val float64) Logger

F64 adds a tag to the logger of type float64

func (*MultiLogger) Fatal

func (l *MultiLogger) Fatal(msg string)

Fatal logs a message with the fatal level

func (*MultiLogger) FatalMsg

func (l *MultiLogger) FatalMsg(msg string) LogMsg

FatalMsg creates a LogMsg that inherit the logger tags with a fatal level.

func (*MultiLogger) I64

func (l *MultiLogger) I64(key string, val int64) Logger

I64 adds a tag to the logger of type int64

func (*MultiLogger) Info

func (l *MultiLogger) Info(msg string)

Info logs a message with the info level

func (*MultiLogger) InfoMsg

func (l *MultiLogger) InfoMsg(msg string) LogMsg

InfoMsg creates a LogMsg that inherit the logger tags with a info level.

func (*MultiLogger) Labels

func (l *MultiLogger) Labels(labels map[string]interface{}) Logger

Labels sets labels for a logger in a batch

func (*MultiLogger) Panic

func (l *MultiLogger) Panic(msg string)

Panic logs a message with the fatal level

func (*MultiLogger) PanicMsg

func (l *MultiLogger) PanicMsg(msg string) LogMsg

PanicMsg creates a LogMsg that inherit the logger tags with a panic level.

func (*MultiLogger) Str

func (l *MultiLogger) Str(key, val string) Logger

Str adds a tag to the logger of type string

func (*MultiLogger) Trace

func (l *MultiLogger) Trace(msg string)

Trace logs a message with the trace level

func (*MultiLogger) TraceMsg

func (l *MultiLogger) TraceMsg(msg string) LogMsg

TraceMsg creates a LogMsg that inherit the logger tags with a trace level.

func (*MultiLogger) Warn

func (l *MultiLogger) Warn(msg string)

Warn logs a message with the warn level

func (*MultiLogger) WarnMsg

func (l *MultiLogger) WarnMsg(msg string) LogMsg

WarnMsg creates a LogMsg that inherit the logger tags with a warn level.

type NopLogger

type NopLogger struct {
}

NopLogger is a logger that logs nothing.

func NewNopLogger

func NewNopLogger() *NopLogger

NewNopLogger is a function to construct a NopLogger logger.

func (*NopLogger) Bool

func (nl *NopLogger) Bool(key string, val bool) Logger

Bool adds a tag to the logger of type bool

func (*NopLogger) Clone

func (nl *NopLogger) Clone() Logger

Clone clones a NopLogger logger.

func (*NopLogger) Debug

func (nl *NopLogger) Debug(msg string)

Debug logs a message with the debug level

func (*NopLogger) DebugMsg

func (nl *NopLogger) DebugMsg(msg string) LogMsg

DebugMsg creates a LogMsg that inherit the logger tags with a debug level.

func (*NopLogger) Err

func (nl *NopLogger) Err(err error, msg string)

Err logs a message with the error level

func (*NopLogger) ErrMsg

func (nl *NopLogger) ErrMsg(err error, msg string) LogMsg

ErrMsg creates a LogMsg that inherit the logger tags with a error level.

func (*NopLogger) F64

func (nl *NopLogger) F64(key string, val float64) Logger

F64 adds a tag to the logger of type float64

func (*NopLogger) Fatal

func (nl *NopLogger) Fatal(msg string)

Fatal logs a message with the fatal level

func (*NopLogger) FatalMsg

func (nl *NopLogger) FatalMsg(msg string) LogMsg

FatalMsg creates a LogMsg that inherit the logger tags with a fatal level.

func (*NopLogger) I64

func (nl *NopLogger) I64(key string, val int64) Logger

I64 adds a tag to the logger of type int64

func (*NopLogger) Info

func (nl *NopLogger) Info(msg string)

Info logs a message with the info level

func (*NopLogger) InfoMsg

func (nl *NopLogger) InfoMsg(msg string) LogMsg

InfoMsg creates a LogMsg that inherit the logger tags with a info level.

func (*NopLogger) Labels

func (nl *NopLogger) Labels(labels map[string]interface{}) Logger

Labels sets labels for a logger in a batchl

func (*NopLogger) Panic

func (nl *NopLogger) Panic(msg string)

Panic logs a message with the fatal level

func (*NopLogger) PanicMsg

func (nl *NopLogger) PanicMsg(msg string) LogMsg

PanicMsg creates a LogMsg that inherit the logger tags with a panic level.

func (*NopLogger) Str

func (nl *NopLogger) Str(key, val string) Logger

Str adds a tag to the logger of type string

func (*NopLogger) Trace

func (nl *NopLogger) Trace(msg string)

Trace logs a message with the trace level

func (*NopLogger) TraceMsg

func (nl *NopLogger) TraceMsg(msg string) LogMsg

TraceMsg creates a LogMsg that inherit the logger tags with a trace level.

func (*NopLogger) Warn

func (nl *NopLogger) Warn(msg string)

Warn logs a message with the warn level

func (*NopLogger) WarnMsg

func (nl *NopLogger) WarnMsg(msg string) LogMsg

WarnMsg creates a LogMsg that inherit the logger tags with a warn level.

type NopLoggerMsg

type NopLoggerMsg struct {
}

NopLoggerMsg is a log message that will send nothing.

func (*NopLoggerMsg) Bool

func (lm *NopLoggerMsg) Bool(key string, val bool) LogMsg

Bool adds a tag to the message of type bool.

func (*NopLoggerMsg) F64

func (lm *NopLoggerMsg) F64(key string, val float64) LogMsg

F64 adds a tag to the message of type float64.

func (*NopLoggerMsg) I64

func (lm *NopLoggerMsg) I64(key string, val int64) LogMsg

I64 adds a tag to the message of type int64.

func (*NopLoggerMsg) Send

func (lm *NopLoggerMsg) Send()

Send the message that has been constructed.

func (*NopLoggerMsg) Str

func (lm *NopLoggerMsg) Str(key, val string) LogMsg

Str adds a tag to the message of type string.

type SentryConf

type SentryConf struct {
	Dsn              string
	AttachStacktrace bool
	SampleRate       float64
	Release          string
	Environment      string
	FlushTimeoutSecs int
	LevelThreshold   string // the mininimum level required to be sent
	AllowedTags      []string
}

SentryConf contains the values to initialize a Sentry logger.

func NewSentryConf

func NewSentryConf() *SentryConf

NewSentryConf creates a basic SentryConf

type SentryLogger

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

SentryLogger implements a logger that sends messages to Sentry.

func (*SentryLogger) Bool

func (l *SentryLogger) Bool(key string, val bool) Logger

Bool adds a tag to the logger of type bool

func (*SentryLogger) Clone

func (l *SentryLogger) Clone() Logger

Clone clones a Sentry logger.

func (*SentryLogger) Debug

func (l *SentryLogger) Debug(msg string)

Debug logs a message with the debug level

func (*SentryLogger) DebugMsg

func (l *SentryLogger) DebugMsg(msg string) LogMsg

DebugMsg creates a LogMsg that inherit the logger tags with a debug level.

func (*SentryLogger) Err

func (l *SentryLogger) Err(err error, msg string)

Err logs a message with the error level

func (*SentryLogger) ErrMsg

func (l *SentryLogger) ErrMsg(err error, msg string) LogMsg

ErrMsg creates a LogMsg that inherit the logger tags with a error level.

func (*SentryLogger) F64

func (l *SentryLogger) F64(key string, val float64) Logger

F64 adds a tag to the logger of type float64

func (*SentryLogger) Fatal

func (l *SentryLogger) Fatal(msg string)

Fatal logs a message with the fatal level

func (*SentryLogger) FatalMsg

func (l *SentryLogger) FatalMsg(msg string) LogMsg

FatalMsg creates a LogMsg that inherit the logger tags with a fatal level.

func (*SentryLogger) I64

func (l *SentryLogger) I64(key string, val int64) Logger

I64 adds a tag to the logger of type int64

func (*SentryLogger) Info

func (l *SentryLogger) Info(msg string)

Info logs a message with the info level

func (*SentryLogger) InfoMsg

func (l *SentryLogger) InfoMsg(msg string) LogMsg

InfoMsg creates a LogMsg that inherit the logger tags with a info level.

func (*SentryLogger) Labels

func (l *SentryLogger) Labels(labels map[string]interface{}) Logger

Labels sets labels for a logger in a batch

func (*SentryLogger) Panic

func (l *SentryLogger) Panic(msg string)

Panic logs a message with the fatal level

func (*SentryLogger) PanicMsg

func (l *SentryLogger) PanicMsg(msg string) LogMsg

PanicMsg creates a LogMsg that inherit the logger tags with a panic level.

func (*SentryLogger) Req

func (l *SentryLogger) Req(req *http.Request) Logger

Req prepares a log to include http request information.

func (*SentryLogger) Str

func (l *SentryLogger) Str(key, val string) Logger

Str adds a tag to the logger of type string

func (*SentryLogger) Trace

func (l *SentryLogger) Trace(msg string)

Trace logs a message with the trace level

func (*SentryLogger) TraceMsg

func (l *SentryLogger) TraceMsg(msg string) LogMsg

TraceMsg creates a LogMsg that inherit the logger tags with a trace level.

func (*SentryLogger) Warn

func (l *SentryLogger) Warn(msg string)

Warn logs a message with the warn level

func (*SentryLogger) WarnMsg

func (l *SentryLogger) WarnMsg(msg string) LogMsg

WarnMsg creates a LogMsg that inherit the logger tags with a warn level.

type SentryLoggerMsg

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

SentryLoggerMsg implements a LogMessage that can be sent to Sentry.

func (*SentryLoggerMsg) Bool

func (m *SentryLoggerMsg) Bool(key string, val bool) LogMsg

Bool adds a tag to the message of type bool.

func (*SentryLoggerMsg) F64

func (m *SentryLoggerMsg) F64(key string, val float64) LogMsg

F64 adds a tag to the message of type float64.

func (*SentryLoggerMsg) I64

func (m *SentryLoggerMsg) I64(key string, val int64) LogMsg

I64 adds a tag to the message of type int64.

func (*SentryLoggerMsg) Send

func (m *SentryLoggerMsg) Send()

Send the message that has been constructed.

func (*SentryLoggerMsg) Str

func (m *SentryLoggerMsg) Str(key, val string) LogMsg

Str adds a tag to the message of type string.

Jump to

Keyboard shortcuts

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