package syslog

import "log/syslog"

syslog 包提供一个简单的系统日志服务的接口。 It can send messages to the syslog daemon using UNIX domain sockets, UDP or TCP.

Only one call to Dial is necessary. On write failures, the syslog client will attempt to reconnect to the server and write again.

The syslog package is frozen and is not accepting new features. Some external packages provide more functionality. See:

https://godoc.org/?q=syslog

doc.go syslog.go syslog_unix.go

func NewLogger

NewLogger creates a log.Logger whose output is written to the system log service with the specified priority. The logFlag argument is the flag set passed through to log.New to create the Logger.

type Priority

The Priority is a combination of the syslog facility and severity. For example, LOG_ALERT | LOG_FTP sends an alert severity message from the FTP facility. The default severity is LOG_EMERG; the default facility is LOG_KERN.

type Writer

A Writer is a connection to a syslog server.

func Dial

Dial establishes a connection to a log daemon by connecting to address raddr on the specified network. Each write to the returned writer sends a log message with the given facility, severity and tag. If network is empty, Dial will connect to the local syslog server. Otherwise, see the documentation for net.Dial for valid values of network and raddr.

Code:play 

sysLog, err := syslog.Dial("tcp", "localhost:1234",
    syslog.LOG_WARNING|syslog.LOG_DAEMON, "demotag")
if err != nil {
    log.Fatal(err)
}
fmt.Fprintf(sysLog, "This is a daemon warning with demotag.")
sysLog.Emerg("And this is a daemon emergency with demotag.")

func New

New establishes a new connection to the system log daemon. Each write to the returned writer sends a log message with the given priority and prefix.

func (*Writer) Alert

Alert logs a message with severity LOG_ALERT, ignoring the severity passed to New.

func (*Writer) Close

Close closes a connection to the syslog daemon.

func (*Writer) Crit

Crit logs a message with severity LOG_CRIT, ignoring the severity passed to New.

func (*Writer) Debug

Debug logs a message with severity LOG_DEBUG, ignoring the severity passed to New.

func (*Writer) Emerg

Emerg logs a message with severity LOG_EMERG, ignoring the severity passed to New.

func (*Writer) Err

Err logs a message with severity LOG_ERR, ignoring the severity passed to New.

func (*Writer) Info

Info logs a message with severity LOG_INFO, ignoring the severity passed to New.

func (*Writer) Notice

Notice logs a message with severity LOG_NOTICE, ignoring the severity passed to New.

func (*Writer) Warning

Warning logs a message with severity LOG_WARNING, ignoring the severity passed to New.

func (*Writer) Write

Write sends a log message to the syslog daemon.

Bugs

This package is not implemented on Windows. As the syslog package is frozen, Windows users are encouraged to use a package outside of the standard library. For background, see https://github.com/golang/go/blob/master/issue/1108.

This package is not implemented on Plan 9.

This package is not implemented on NaCl (Native Client).