email

package
v4.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2016 License: MIT Imports: 9 Imported by: 1

Documentation

Overview

Package email allows for log messages to be sent via email.

Example

simple email

package main

import (
    "github.com/go-playground/log"
    "github.com/go-playground/log/handlers/email"
)

func main() {

    email := email.New("smtp.gmail.com", 587, "username", "password", "from@email.com", []string{"to@email.com"})
    email.SetFilenameDisplay(log.Llongfile)

    log.RegisterHandler(email, log.WarnLevel, log.AlertLevel, log.PanicLevel)

    log.WithFields(log.F("error", "something went wrong")).StackTrace().Alert("ALERT!")
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Email

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

Email is an instance of the email logger

func New

func New(host string, port int, username string, password string, from string, to []string) *Email

New returns a new instance of the email logger

func (*Email) From

func (email *Email) From() string

From returns the Email's From address

func (*Email) Run

func (email *Email) Run() chan<- *log.Entry

Run starts the logger consuming on the returned channed

func (*Email) SetBuffersAndWorkers

func (email *Email) SetBuffersAndWorkers(size uint, workers uint)

SetBuffersAndWorkers sets the channels buffer size and number of concurrent workers. These settings should be thought about together, hence setting both in the same function.

func (*Email) SetEmailTemplate

func (email *Email) SetEmailTemplate(htmlTemplate string)

SetEmailTemplate sets Email's html template to be used for email body

func (*Email) SetFilenameDisplay

func (email *Email) SetFilenameDisplay(fd log.FilenameDisplay)

SetFilenameDisplay tells Email the filename, when present, how to display

func (*Email) SetFormatFunc

func (email *Email) SetFormatFunc(fn FormatFunc)

SetFormatFunc sets FormatFunc each worker will call to get a Formatter func

func (*Email) SetKeepAliveTimout

func (email *Email) SetKeepAliveTimout(keepAlive time.Duration)

SetKeepAliveTimout tells Email how long to keep the smtp connection open when no messsages are being sent; it will automatically reconnect on next message that is received.

func (*Email) SetTimestampFormat

func (email *Email) SetTimestampFormat(format string)

SetTimestampFormat sets Email's timestamp output format Default is : "2006-01-02T15:04:05.000000000Z07:00"

func (*Email) Template

func (email *Email) Template() *template.Template

Template returns the Email's template

func (*Email) To

func (email *Email) To() []string

To returns the Email's To address

type FormatFunc

type FormatFunc func(email *Email) Formatter

FormatFunc is the function that the workers use to create a new Formatter per worker allowing reusable go routine safe variable to be used within your Formatter function.

type Formatter

type Formatter func(e *log.Entry) *gomail.Message

Formatter is the function used to format the Email entry

Jump to

Keyboard shortcuts

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