notifier

package
v0.0.0-...-50e5382 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2018 License: GPL-3.0 Imports: 9 Imported by: 5

Documentation

Overview

Notifier - Go logging package (syslog, file and e-mail)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Msg

type Msg struct {
	Time     time.Time
	MsgType  MsgType
	Severity Severity
	Text     string
}

A single message.

func (*Msg) String

func (m *Msg) String() string

String implements the fmt.Stringer interface. It returns the message as a single string in human readable format.

func (*Msg) Strings

func (m *Msg) Strings() (date_time string, severity string, text string)

Strings returns the message in three separate strings.

func (*Msg) SyslogString

func (m *Msg) SyslogString(facility SyslogFacility, tag string) string

SyslogString returns the message in a format suitable for sending to BSD style syslogd.

func (*Msg) TimeString

func (m *Msg) TimeString() string

TimeString is like String() but omits the date from the output.

type MsgType

type MsgType int

A type of a message.

const (
	MSGTYPE_MESSAGE    MsgType = iota // normal log message
	MSGTYPE_ATTACHMENT                // additional verbose information
	MSGTYPE_FLUSH                     // send messages to delayed destinations (e-mail)
	MSGTYPE_REOPEN                    // re-open output file after log rotation etc
)

type Notifier

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

Notifier is a logging subsystem instance which is running as a goroutine and may have several different logging destinations.

func New

func New() *Notifier

New starts a new logging subsystem as a goroutine.

func (*Notifier) AddLoggerCallback

func (n *Notifier) AddLoggerCallback(s Severity, f func(*Msg)) error

AddLoggerCallback adds a log output which just calls back the given function whenever there is a message to be logged.

func (*Notifier) AddLoggerEmailSMTP

func (n *Notifier) AddLoggerEmailSMTP(s Severity, server, user, pass, from, to, subject string, throttle time.Duration) error

AddLoggerEmailSMTP adds an e-mail logging output. The e-mails are sent with ESMTP/SMTP whenever Flush() is called.

func (*Notifier) AddLoggerFile

func (n *Notifier) AddLoggerFile(s Severity, file string) error

AddLoggerFile adds a file based logging output.

func (*Notifier) AddLoggerStdout

func (n *Notifier) AddLoggerStdout(s Severity) error

AddLoggerStdout adds a logger which outputs to the standard output. This can be useful for running a program in debugging mode.

func (*Notifier) AddLoggerSyslog

func (n *Notifier) AddLoggerSyslog(s Severity, address string, facility SyslogFacility) error

AddLoggerSyslog adds a Unix syslog logging output.

func (*Notifier) Attach

func (n *Notifier) Attach(s Severity, t string) error

Attach sends an attachment for logging. Attachments are usually some additional multi-line output which provide further insight into a problem. Examples: stack trace in case of panic, parser input in case of a parse error. Some logging destinations such as syslog do not support logging attachments. For others attachments can be enabled or disabled when setting up the logging destination.

func (*Notifier) Close

func (n *Notifier) Close() chan bool

Close log outputs. Causes the outputs to be flushed and stops the goroutines gracefully. Returns a channel which is closed when the logging subsystem has shut down. The caller may choose to wait until it is closed in case something takes a long time (such as sendind an e-mail message).

func (*Notifier) Flush

func (n *Notifier) Flush()

Flush all buffered logging output. This should be called when the program finishes "one round". Causes for example e-mails to be sent instead of waiting for more log lines.

func (*Notifier) Print

func (n *Notifier) Print(s Severity, v ...interface{})

Print is normal fmt.Print which sends a log message.

func (*Notifier) Printf

func (n *Notifier) Printf(s Severity, format string, v ...interface{})

Printf is normal fmt.Printf which sends a log message.

func (*Notifier) Reopen

func (n *Notifier) Reopen()

Reopen log outputs. Should be called whenever log files have been rotated.

func (*Notifier) Send

func (n *Notifier) Send(s Severity, t string) error

Send sends a message for logging.

type Severity

type Severity uint32

Message severity levels, matches with syslog severity levels.

const (
	EMERG   Severity = 0 // this is unfortunate
	ALERT   Severity = 1
	CRIT    Severity = 2
	ERR     Severity = 3
	WARNING Severity = 4
	NOTICE  Severity = 5
	INFO    Severity = 6
	DEBUG   Severity = 7

	SEVERITY_NONE Severity = 8 // discard these messages
)

func (*Severity) Scan

func (s *Severity) Scan(state fmt.ScanState, verb rune) error

Scan implements fmt.Scanner interface. This makes it possible to use fmt.Sscan*() functions to parse syslog facility codes. Also "gcfg" package can parse them in configuration files.

func (Severity) String

func (s Severity) String() string

String implements fmt.Stringer interface.

type SyslogFacility

type SyslogFacility uint32

Syslog message facility codes.

func (*SyslogFacility) Scan

func (f *SyslogFacility) Scan(state fmt.ScanState, verb rune) error

Implement fmt.Scanner interface. This makes it possible to use fmt.Sscan*() functions to parse syslog facility codes directly. Also "gcfg" package can parse them in configuration files.

Jump to

Keyboard shortcuts

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