logrus_mail

package module
v0.0.0-...-9ec03a2 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2020 License: MIT Imports: 9 Imported by: 21

README

Mail Hook for Logrus GoDoc Go Report Card

Warning

THIS REPO IS ARCHIVED AND NO LONGER MAINTAINED SINCE I DO NOT USE LOGRUS ANYMORE.

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, "user.name@gmail.com", "user.name@gmail.com", "user.name", "password")

If you get the following error:

Failed to fire hook: 534 5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbt7D
5.7.14 N0zOlIl3SKJo5pXolT2E87etIZvTL03NXXQI4vST_GvPFo5p5OPvn6XqnQNgJsneZytvRa
5.7.14 nWhV3Qy6cynKd7_s0KRGlGNKI25t15FH9v5ztyFZ80dnM-qXDqRvMr8_pGaYrHKfI9rRB2
5.7.14 3VJLfZAiBBBe0L3IKG6sy8QEFRLylxNLiTvighE2qAfcSnxAxz5kDs1fB0szYnlryuBN0B
5.7.14 43SATbFjeep4iMzAWvVJ9hoGwrqI> Please log in via your web browser and
5.7.14 then try again.
5.7.14  Learn more at
5.7.14  https://support.google.com/mail/answer/78754 t8sm37578500wjy.41 - gsmtp

Check the Setting Allow less secure apps in the gmail account settings.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MailAuthHook

type MailAuthHook struct {
	AppName  string
	Host     string
	Port     int
	From     *mail.Address
	To       *mail.Address
	Username string
	Password string
}

MailAuthHook to sends logs by email with authentication.

func NewMailAuthHook

func NewMailAuthHook(appname string, host string, port int, from string, to string, username string, password string) (*MailAuthHook, error)

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

func (*MailAuthHook) Fire

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

Fire is called when a log event is fired.

func (*MailAuthHook) Levels

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

Levels returns the available logging levels.

type MailHook

type MailHook struct {
	AppName string
	// contains filtered or unexported fields
}

MailHook to sends logs by email without authentication.

func NewMailHook

func NewMailHook(appname string, host string, port int, from string, to string) (*MailHook, error)

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

func (*MailHook) Fire

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

Fire is called when a log event is fired.

func (*MailHook) Levels

func (hook *MailHook) 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