sentrywriter

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2020 License: MIT Imports: 5 Imported by: 1

README

sentrywriter

Package to send logs to sentry

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogLevel

type LogLevel struct {
	MatchingString string
	SentryLevel    sentry.Level
}

LogLevel is used to match the log level that you're using and then map it into a Sentry log level. For example, you may be logging at level "error", which corresponds to sentry.LevelError, so that would correspond to:

levelError := LogLevel{"error", sentry.LevelError}

See https://godoc.org/github.com/getsentry/sentry-go#Level for the possible Sentry log levels.

type SentryClient

type SentryClient interface {
	CaptureMessage(message string, hint *sentry.EventHint, scope sentry.EventModifier) *sentry.EventID
	Flush(timeout time.Duration) bool
}

SentryClient is an interface which represents the sentry-go package client.

type SentryWriter

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

SentryWriter implements the io.Writer interface. It is a wrapper over the sentry-go client and sends the supplied logs of the specified log level to Sentry. It assumes that the logs are json encoded. Writes are asynchronous, so remember to call Flush before exiting the program.

func New

func New() *SentryWriter

New returns a pointer to the SentryWriter, with the specified log levels set. The SentryWriter will write logs which match any of the supplied logs to Sentry. The default field that is checked for the log level is "level".

func (*SentryWriter) Flush

func (s *SentryWriter) Flush(timeout time.Duration) bool

Flush initiates the Flush method of the underlying Sentry client. Call this before exiting your program. The provided timeout is the maximum length of time to block until all the logs have been sent to Sentry. It returns false if the timeout is reached, which may signify that not all messages were sent to Sentry.

func (*SentryWriter) SetDSN

func (s *SentryWriter) SetDSN(DSN string) (*SentryWriter, error)

SetDSN sets the DSN for the Sentry client.

func (*SentryWriter) WithClient

func (s *SentryWriter) WithClient(client SentryClient) *SentryWriter

WithClient allows you to substitute the client that is being used, rather than the default client from the sentry-go package.

func (*SentryWriter) WithLevelFieldName

func (s *SentryWriter) WithLevelFieldName(name string) *SentryWriter

WithLevelFieldName allows you to change the log level field name from the default of "level" to whatever you are using.

func (*SentryWriter) WithLogLevel

func (s *SentryWriter) WithLogLevel(level LogLevel) *SentryWriter

WithLogLevel adds a LogLevel that triggers an event to be sent to Sentry.

func (*SentryWriter) WithUserID

func (s *SentryWriter) WithUserID(userID string) *SentryWriter

WithUserID sets a user ID that will be reported alongside each Sentry event. This is helpful for code that runs on client machines.

func (*SentryWriter) Write

func (s *SentryWriter) Write(log []byte) (int, error)

Write is the implementation of the io.Writer interface. It checks if the log is at one of the preset log levels and if so it writes it to Sentry.

Directories

Path Synopsis
example module

Jump to

Keyboard shortcuts

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