version: 1.10

package syslog

import "log/syslog"

Overview

Package syslog provides a simple interface to the system log service. 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:

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

Index

Examples

Package files

doc.go syslog.go syslog_unix.go

func NewLogger

  1. func NewLogger(p Priority, logFlag int) (log.Logger, error)
NewLogger creates a log.Logger whose output is written to the system log service with the specified priority, a combination of the syslog facility and severity. The logFlag argument is the flag set passed through to log.New to create the Logger.

type Priority

  1. type Priority int
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.
  1. const (
  2.  
  3. // From /usr/include/sys/syslog.h.
  4. // These are the same on Linux, BSD, and OS X.
  5. LOG_EMERG Priority = iota
  6. LOG_ALERT
  7. LOG_CRIT
  8. LOG_ERR
  9. LOG_WARNING
  10. LOG_NOTICE
  11. LOG_INFO
  12. LOG_DEBUG
  13. )
  1. const (
  2.  
  3. // From /usr/include/sys/syslog.h.
  4. // These are the same up to LOG_FTP on Linux, BSD, and OS X.
  5. LOG_KERN Priority = iota << 3
  6. LOG_USER
  7. LOG_MAIL
  8. LOG_DAEMON
  9. LOG_AUTH
  10. LOG_SYSLOG
  11. LOG_LPR
  12. LOG_NEWS
  13. LOG_UUCP
  14. LOG_CRON
  15. LOG_AUTHPRIV
  16. LOG_FTP
  17.  
  18. LOG_LOCAL0
  19. LOG_LOCAL1
  20. LOG_LOCAL2
  21. LOG_LOCAL3
  22. LOG_LOCAL4
  23. LOG_LOCAL5
  24. LOG_LOCAL6
  25. LOG_LOCAL7
  26. )

type Writer

  1. type Writer struct {
  2. // contains filtered or unexported fields
  3. }
A Writer is a connection to a syslog server.

func Dial

  1. func Dial(network, raddr string, priority Priority, tag string) (Writer, error)
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 facility and severity (from priority) and tag. If tag is empty, the os.Args[0] is used. 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. Example: 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

  1. func New(priority Priority, tag string) (Writer, error)
New establishes a new connection to the system log daemon. Each write to the returned writer sends a log message with the given priority (a combination of the syslog facility and severity) and prefix tag. If tag is empty, the os.Args[0] is used.

func (Writer) Alert

  1. func (w Writer) Alert(m string) error
Alert logs a message with severity LOG_ALERT, ignoring the severity passed to New.

func (Writer) Close

  1. func (w Writer) Close() error
Close closes a connection to the syslog daemon.

func (Writer) Crit

  1. func (w Writer) Crit(m string) error
Crit logs a message with severity LOG_CRIT, ignoring the severity passed to New.

func (Writer) Debug

  1. func (w Writer) Debug(m string) error
Debug logs a message with severity LOG_DEBUG, ignoring the severity passed to New.

func (Writer) Emerg

  1. func (w Writer) Emerg(m string) error
Emerg logs a message with severity LOG_EMERG, ignoring the severity passed to New.

func (Writer) Err

  1. func (w Writer) Err(m string) error
Err logs a message with severity LOG_ERR, ignoring the severity passed to New.

func (Writer) Info

  1. func (w Writer) Info(m string) error
Info logs a message with severity LOG_INFO, ignoring the severity passed to New.

func (Writer) Notice

  1. func (w Writer) Notice(m string) error
Notice logs a message with severity LOG_NOTICE, ignoring the severity passed to New.

func (Writer) Warning

  1. func (w Writer) Warning(m string) error
Warning logs a message with severity LOG_WARNING, ignoring the severity passed to New.

func (Writer) Write

  1. func (w *Writer) Write(b []byte) (int, error)
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://golang.org/issue/1108.
  • This package is not implemented on Plan 9.
  • This package is not implemented on NaCl (Native Client).