Code Monkey home page Code Monkey logo

logrus_email's Introduction

Mail Hook for Logrus GoDoc Go Report Card

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/Philoinc/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/Philoinc/logrus"
  "github.com/Philoinc/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")

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.

logrus_email's People

Contributors

rifflock avatar tfrivold avatar yanmhlv avatar zbindenren avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.