logmgr

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: GPL-3.0 Imports: 10 Imported by: 0

README

logmgr

logmgr is a simple library to combine logrus and Sentry for Go applications making use of the Gin HTTP framework.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger interface {
	logrus.Ext1FieldLogger

	// Extend returns a Logger with an extended name path.
	Extend(name string) Logger
	// WithUser includes the given user id in the logger context.
	WithUser(userID string) Logger
	// WithGin includes the given gin request context in the logger context.
	WithGin(c *gin.Context) Logger
	// Recovery returns a gin handler function that will recover and log panics.
	Recovery() gin.HandlerFunc
	// RecoveryWith returns a gin handler function that will recover with a specific behavior
	// while also logging panics.
	RecoveryWith(handler gin.HandlerFunc) gin.HandlerFunc
}

Logger extends a logrus logger by providing path-like names.

func NewPlainLogger added in v1.0.2

func NewPlainLogger(name string, level logrus.Level) Logger

NewPlainLogger creates a Logger without a SentryManager.

type LoggerMaker

type LoggerMaker interface {
	NewLogger(name string) Logger
}

type NopLogger added in v1.2.0

type NopLogger struct {
	*logrus.Entry
}

NopLogger is a logger which does nothing.

func NewNopLogger added in v1.2.0

func NewNopLogger() *NopLogger

NewNopLogger creates a new NopLogger instance.

func (*NopLogger) Extend added in v1.2.0

func (n *NopLogger) Extend(string) Logger

func (*NopLogger) NewLogger added in v1.2.0

func (n *NopLogger) NewLogger(string) Logger

func (*NopLogger) Recovery added in v1.2.0

func (n *NopLogger) Recovery() gin.HandlerFunc

func (*NopLogger) RecoveryWith added in v1.2.2

func (n *NopLogger) RecoveryWith(handler gin.HandlerFunc) gin.HandlerFunc

func (*NopLogger) WithGin added in v1.2.0

func (n *NopLogger) WithGin(*gin.Context) Logger

func (*NopLogger) WithUser added in v1.2.0

func (n *NopLogger) WithUser(string) Logger

type SentryConfig

type SentryConfig struct {
	// DSN to connect with Sentry
	DSN string

	// Environment passed to Sentry
	Environment string

	// Release passed to Sentry
	Release string

	// Log level strings to report messages to Sentry
	LogLevels []string
}

type SentryManager

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

SentryManager is a struct that issues loggers tied back to a central sentry.Hub instance.

func NewSentryManager

func NewSentryManager(config *SentryConfig, logLevel string) (*SentryManager, error)

NewSentryManager creates a SentryManager with a logLevel output minimum.

func (*SentryManager) Fire

func (m *SentryManager) Fire(lEntry *logrus.Entry) error

Fire implements the logrus.Hook interface. Log entries will be logged to Sentry.

func (*SentryManager) Levels

func (m *SentryManager) Levels() []logrus.Level

Levels implements the logrus.Hook interface.

func (*SentryManager) NewLogger

func (m *SentryManager) NewLogger(name string) Logger

NewLogger returns a Logger with the given name, linked to this SentryManager object

func (*SentryManager) WithRequestContext

func (m *SentryManager) WithRequestContext(ctx *gin.Context)

WithRequestContext issues a new sentry.Hub and sets the Hub's current request to req. To be used in gin.Use as middleware.

Jump to

Keyboard shortcuts

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