zfswatcher: github.com/damicon/zfswatcher/notifier Index | Files

package notifier

import "github.com/damicon/zfswatcher/notifier"

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


Package Files

facility.go logger_callback.go logger_file.go logger_smtp.go logger_stdout.go logger_syslog.go msg.go notifier.go severity.go

type Msg Uses

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

A single message.

func (*Msg) String Uses

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 Uses

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

Strings returns the message in three separate strings.

func (*Msg) SyslogString Uses

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 Uses

func (m *Msg) TimeString() string

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

type MsgType Uses

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 Uses

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 Uses

func New() *Notifier

New starts a new logging subsystem as a goroutine.

func (*Notifier) AddLoggerCallback Uses

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 Uses

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 Uses

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

AddLoggerFile adds a file based logging output.

func (*Notifier) AddLoggerStdout Uses

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 Uses

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

AddLoggerSyslog adds a Unix syslog logging output.

func (*Notifier) Attach Uses

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 Uses

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 Uses

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 Uses

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

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

func (*Notifier) Printf Uses

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

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

func (*Notifier) Reopen Uses

func (n *Notifier) Reopen()

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

func (*Notifier) Send Uses

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

Send sends a message for logging.

type Severity Uses

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 Uses

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 Uses

func (s Severity) String() string

String implements fmt.Stringer interface.

type SyslogFacility Uses

type SyslogFacility uint32

Syslog message facility codes.

func (*SyslogFacility) Scan Uses

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.

Package notifier imports 9 packages (graph) and is imported by 2 packages. Updated 2016-11-10. Refresh now. Tools for package owners.