logrus_gomail

package module
v0.0.0-...-67a24ea Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2016 License: MIT Imports: 4 Imported by: 0

README

In some deployments, you'll want to report errors by email. If you add this hook, an email will send for the following levels:

  • Error
  • Fatal
  • Panic

The subject is of the form APPLICATION_NAME - LEVEL and the body contains the timestamp and the message.

Installation

Install the package with go:

go get github.com/dpatel06/logrus_gomail

Usage

For APPLICATION_NAME, substitute a short string that will identify your application or service in the logs.

import (
  "log/syslog"
  "github.com/Sirupsen/logrus"
  "github.com/dpatel06/logrus_gomail"
)

func main() {
  log       := logrus.New()
  // if you do not need authentication for your smtp host
  hook, err := logrus_gomail.NewGoMailAuthHook("APPLICATION_NAME", "HOST", PORT, "FROM", "TO")

  if err == nil {
    log.Hooks.Add(hook)
  }
}

Example with authentication:

  // if you need authentication for your smtp host
  hook, err := logrus_gomail.NewGoMailAuthHook("APPLICATION_NAME", "HOST", PORT, "FROM", "TO", "USERNAME", "PASSWORD")

If you want to send mails with gmail:

 hook, err := logrus_gomail.NewGoMailAuthHook("testapp", "smtp.gmail.com", 587, "user.name@gmail.com", "user.name@gmail.com", "user.name", "password")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GoMailAuthHook

type GoMailAuthHook struct {
	AppName  string
	Host     string
	Port     int
	From     *mail.Address
	To       *mail.Address
	Username string
	Password string
	// contains filtered or unexported fields
}

MailAuthHook to sends logs by email with authentication.

func NewGoMailAuthHook

func NewGoMailAuthHook(appname string, host string, port int, from string, to string, username string, password string) (*GoMailAuthHook, error)

NewMailAuthHook creates a hook to be added to an instance of logger.

func (*GoMailAuthHook) Fire

func (hook *GoMailAuthHook) Fire(entry *logrus.Entry) error

Fire is called when a log event is fired.

func (*GoMailAuthHook) Levels

func (hook *GoMailAuthHook) Levels() []logrus.Level

Levels returns the available logging levels.

func (*GoMailAuthHook) SetLevels

func (hook *GoMailAuthHook) SetLevels(levels []logrus.Level)

Levels returns the available logging levels.

Jump to

Keyboard shortcuts

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