zlogsentry

package module
v0.0.0-...-daca175 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

README

zerolog-sentry

Build Status

Example
package main

import (
	"errors"
	"io"
	stdlog "log"
	"os"

	"github.com/labd/zerolog-sentry"
	"github.com/rs/zerolog"
	"github.com/getsentry/sentry-go"
)

func main() {
	scope := sentry.NewScope()
	client, _ := sentry.NewClient(sentry.ClientOptions{
		// Either set your DSN here or set the SENTRY_DSN environment variable.
		Dsn: "...",
		// Enable printing of SDK debug messages.
		// Useful when getting started or trying to figure something out.
		Environment: "local",
		Debug:   true,
	})
	hub = sentry.NewHub(client, scope)

	w, err := zlogsentry.New(hub)
	if err != nil {
		stdlog.Fatal(err)
	}

	defer w.Close()

	logger := zerolog.New(io.MultiWriter(w, os.Stdout)).With().Timestamp().Logger()
	logger.Error().Err(errors.New("dial timeout")).Msg("test message")
}

Documentation

Overview

Package zlogsentry provides a zerolog writer which sends selected events to sentry.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SpecialFieldType

type SpecialFieldType int
const (
	SpecialFieldTag SpecialFieldType = iota
	SpecialFieldUserID
)

type Writer

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

func New

func New(hub *sentry.Hub, opts ...WriterOption) (*Writer, error)

func NewWithName

func NewWithName(hub *sentry.Hub, name string, opts ...WriterOption) (*Writer, error)

func (*Writer) Close

func (w *Writer) Close() error

func (*Writer) Write

func (w *Writer) Write(data []byte) (int, error)

type WriterOption

type WriterOption func(*config)

func WithLevels

func WithLevels(levels ...zerolog.Level) WriterOption

WithLevels configures zerolog levels that have to be sent to Sentry. Default levels are error, fatal, panic

func WithSpecialFieldType

func WithSpecialFieldType(key string, typ SpecialFieldType) WriterOption

Jump to

Keyboard shortcuts

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