target_mail

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2025 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	DefaultMailHost       = ``
	DefaultMailUsername   = ``
	DefaultMailPassword   = ``
	DefaultMailSubject    = ``
	DefaultMailSender     = ``
	DefaultMailRecipients = []string{}
)

Functions

This section is empty.

Types

type MailTarget

type MailTarget struct {
	*log.Filter
	Host       string   // SMTP server address
	Username   string   // SMTP server login username
	Password   string   // SMTP server login password
	Subject    string   // the mail subject
	Sender     string   // the mail sender
	Recipients []string // the mail recipients
	BufferSize int      // the size of the message channel.
	// contains filtered or unexported fields
}

MailTarget sends log messages in emails via an SMTP server.

func NewMailTarget

func NewMailTarget() *MailTarget

NewMailTarget creates a MailTarget. The new MailTarget takes these default options: MaxLevel: LevelDebug, BufferSize: 1024. You must specify these fields: Host, Username, Subject, Sender, and Recipients.

Example
logger := log.NewLogger()

// creates a MailTarget which sends emails to admin@example.com
target := NewMailTarget()
target.Host = "smtp.example.com"
target.Username = "foo"
target.Password = "bar"
target.Subject = "log messages for foobar"
target.Sender = "admin@example.com"
target.Recipients = []string{"admin@example.com"}

logger.Targets = append(logger.Targets, target)

logger.Open()

// ... logger is ready to use ...
Output:

func (*MailTarget) Close

func (t *MailTarget) Close()

Close closes the mail target.

func (*MailTarget) Open

func (t *MailTarget) Open(errWriter io.Writer) error

Open prepares MailTarget for processing log messages.

func (*MailTarget) Process

func (t *MailTarget) Process(e *log.Entry)

Process puts filtered log messages into a channel for sending in emails.

Jump to

Keyboard shortcuts

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