Skip to content

rifflock/logrus_mail

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mail Hook for Logrus

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/zbindenren/logrus_mail

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/zbindenren/logrus_mail"
)

func main() {
  log       := logrus.New()
  // if you do not need authentication for your smtp host
  hook, err := logrus_mail.NewMailHook("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_mail.NewMailAuthHook("APPLICATION_NAME", "HOST", PORT, "FROM", "TO", "USERNAME", "PASSWORD)

If you want to send mails with gmail:

 hook, err := logrus_mail.NewMailAuthHook("testapp", "smtp.gmail.com", 587, "[email protected]", "[email protected]", "user.name", "password")

About

Mail hook for logrus

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%