logs

package
v0.0.0-...-96c172f Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2024 License: MIT Imports: 14 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 Logger

type Logger interface {
	attrs.Attributable

	// Debug logs a message with the debug level
	// the attributes passed as parameters are used only
	// for the sent meessage.
	Debug(msg string, attrs map[string]interface{})
	// Info logs a message with the info level
	// the attributes passed as parameters are used only
	// for the sent meessage.
	Info(msg string, attrs map[string]interface{})
	// Err logs a message with the error level
	// the attributes passed as parameters are used only
	// for the sent meessage.
	Err(err error, msg string, attrs map[string]interface{})
	// Warn logs a message with the warn level
	// the attributes passed as parameters are used only
	// for the sent meessage.
	Warn(msg string, attrs map[string]interface{})
	// Fatal logs a message with the fatal level
	// the attributes passed as parameters are used only
	// for the sent meessage.
	Fatal(msg string, attrs map[string]interface{})
	// Panic logs a message with the panic level
	// the attributes passed as parameters are used only
	// for the sent meessage.
	Panic(msg string, attrs map[string]interface{})

	// Clone a logger, so from that attributes
	// 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 (l *Logrus) Bool(key string, val bool)

Bool adds a tag to the logger of type bool

func (*Logrus) Clone

func (l *Logrus) Clone() Logger

Clone clones a Logrus logger.

func (*Logrus) Debug

func (l *Logrus) Debug(msg string, attrMap map[string]interface{})

Debug logs a message with the debug level

func (*Logrus) Err

func (l *Logrus) Err(err error, msg string, attrMap map[string]interface{})

Err logs a message with the error level

func (*Logrus) F64

func (l *Logrus) F64(key string, val float64)

F64 adds a tag to the logger of type float64

func (*Logrus) Fatal

func (l *Logrus) Fatal(msg string, attrMap map[string]interface{})

Fatal logs a message with the fatal level

func (*Logrus) I64

func (l *Logrus) I64(key string, val int64)

I64 adds a tag to the logger of type int64

func (*Logrus) Info

func (l *Logrus) Info(msg string, attrMap map[string]interface{})

Info logs a message with the info level

func (*Logrus) Panic

func (l *Logrus) Panic(msg string, attrMap map[string]interface{})

Panic logs a message with the fatal level

func (*Logrus) SetAttrs

func (l *Logrus) SetAttrs(attrMap map[string]interface{})

SetAttrs sets labels for a logger in a batch

func (*Logrus) Str

func (l *Logrus) Str(key, val string)

Str adds a tag to the logger of type string

func (*Logrus) Warn

func (l *Logrus) Warn(msg string, attrMap map[string]interface{})

Warn logs a message with the 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 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)

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, attrMap map[string]interface{})

Debug logs a message with the debug level

func (*MultiLogger) Err

func (l *MultiLogger) Err(err error, msg string, attrMap map[string]interface{})

Err logs a message with the error level

func (*MultiLogger) F64

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

F64 adds a tag to the logger of type float64

func (*MultiLogger) Fatal

func (l *MultiLogger) Fatal(msg string, attrMap map[string]interface{})

Fatal logs a message with the fatal level

func (*MultiLogger) I64

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

I64 adds a tag to the logger of type int64

func (*MultiLogger) Info

func (l *MultiLogger) Info(msg string, attrMap map[string]interface{})

Info logs a message with the info level

func (*MultiLogger) Panic

func (l *MultiLogger) Panic(msg string, attrMap map[string]interface{})

Panic logs a message with the fatal level

func (*MultiLogger) SetAttrs

func (l *MultiLogger) SetAttrs(attrMap map[string]interface{})

Labels sets labels for a logger in a batch

func (*MultiLogger) Str

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

Str adds a tag to the logger of type string

func (*MultiLogger) Warn

func (l *MultiLogger) Warn(msg string, attrMap map[string]interface{})

Warn logs a message with the 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)

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, attrMap map[string]interface{})

Debug logs a message with the debug level

func (*NopLogger) Err

func (nl *NopLogger) Err(err error, msg string, attrMap map[string]interface{})

Err logs a message with the error level

func (*NopLogger) F64

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

F64 adds a tag to the logger of type float64

func (*NopLogger) Fatal

func (nl *NopLogger) Fatal(msg string, attrMap map[string]interface{})

Fatal logs a message with the fatal level

func (*NopLogger) I64

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

I64 adds a tag to the logger of type int64

func (*NopLogger) Info

func (nl *NopLogger) Info(msg string, attrMap map[string]interface{})

Info logs a message with the info level

func (*NopLogger) Panic

func (nl *NopLogger) Panic(msg string, attrMap map[string]interface{})

Panic logs a message with the fatal level

func (*NopLogger) SetAttrs

func (nl *NopLogger) SetAttrs(attrMap map[string]interface{})

Labels sets labels for a logger in a batch

func (*NopLogger) Str

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

Str adds a tag to the logger of type string

func (*NopLogger) Warn

func (nl *NopLogger) Warn(msg string, attrMap map[string]interface{})

Warn logs a message with the warn level

type NopLoggerMsg

type NopLoggerMsg struct {
}

NopLoggerMsg is a log message that will send nothing.

type SentryConf

type SentryConf struct {
	Dsn              string  `json:"dsn"`
	AttachStacktrace bool    `json:"attach_stacktrace"`
	SampleRate       float64 `json:"sample_rate"`
	Release          string  `json:"release"`
	Environment      string  `json:"environment"`
	FlushTimeoutSecs int     `json:"flush_timeout_secs`
	LevelThreshold   string  `json:"level_threshold"` // 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)

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, attrMap map[string]interface{})

Debug logs a message with the debug level

func (*SentryLogger) Err

func (l *SentryLogger) Err(err error, msg string, attrMap map[string]interface{})

Err logs a message with the error level

func (*SentryLogger) F64

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

F64 adds a tag to the logger of type float64

func (*SentryLogger) Fatal

func (l *SentryLogger) Fatal(msg string, attrMap map[string]interface{})

Fatal logs a message with the fatal level

func (*SentryLogger) I64

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

I64 adds a tag to the logger of type int64

func (*SentryLogger) Info

func (l *SentryLogger) Info(msg string, attrMap map[string]interface{})

Info logs a message with the info level

func (*SentryLogger) Panic

func (l *SentryLogger) Panic(msg string, attrMap map[string]interface{})

Panic logs a message with the fatal level

func (*SentryLogger) Req

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

Req prepares a log to include http request information.

func (*SentryLogger) SetAttrs

func (l *SentryLogger) SetAttrs(attrMap map[string]interface{})

Labels sets labels for a logger in a batch

func (*SentryLogger) Str

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

Str adds a tag to the logger of type string

func (*SentryLogger) Warn

func (l *SentryLogger) Warn(msg string, attrMap map[string]interface{})

Warn logs a message with the 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)

Bool adds a tag to the message of type bool.

func (*SentryLoggerMsg) F64

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

F64 adds a tag to the message of type float64.

func (*SentryLoggerMsg) I64

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

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) SetAttrs

func (m *SentryLoggerMsg) SetAttrs(attrMap map[string]interface{})

func (*SentryLoggerMsg) Str

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

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