sendgridrus

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

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

Go to latest
Published: May 20, 2019 License: BSD-3-Clause Imports: 7 Imported by: 0

README

sendgridrus - SendGrid hook into Logrus

sendgridrus is a package exposing a SendGrid hook into Logrus. If your machine doesn't have access to an SMTP port or you just want to use SendGrid, this is a viable option for logging.

By default, sendgridrus hooks will fire on all entries with levels Warning, Error, or Panic.

Installation

sendgridrus can be installed using go get:

go get github.com/jnschaeffer/sendgridrus

Usage

The simplest way to use sendgridrus is to add it to a Logrus Logger.

import (
	"github.com/Sirupsen/logrus"
	"github.com/jnschaeffer/sendgridrus"
)

func main() {
	log := logrus.New()
	hook := sendgridrus.NewHook("SENDGRID API KEY", "SERVICE NAME", "FROM ADDRESS", "TO ADDRESS")
	log.Hooks.Add(hook)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hook

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

Hook represents a Logrus hook to SendGrid. Users should have a valid API key from SendGrid before using this hook.

func NewHook

func NewHook(sgAPIKey, serviceName, fromAddr, toAddr string) *Hook

NewHook creates a new Logrus hook into SendGrid.

func (*Hook) Fire

func (h *Hook) Fire(e *logrus.Entry) error

Fire sends a message on SendGrid from the hook's From user to the hook's To user. Messages have a subject with the format "SERVICE_NAME[LEVEL]: MESSAGE". Each message body contains the message text, log entry time, and fields.

func (*Hook) Levels

func (h *Hook) Levels() []logrus.Level

Levels returns the levels for this hook. By default these are Warn, Error, and Panic. Use (*Hook).SetLevels to change the levels for this hook.

func (*Hook) SetLevels

func (h *Hook) SetLevels(levels []logrus.Level)

SetLevels sets the logging levels for this hook.

Jump to

Keyboard shortcuts

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