Movatterモバイル変換


[0]ホーム

URL:


syslog

packagestandard library
go1.25.2Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2025 License:BSD-3-ClauseImports:8Imported by:9,438

Details

Repository

cs.opensource.google/go/go

Links

Documentation

Overview

Package syslog provides a simple interface to the system logservice. It can send messages to the syslog daemon using UNIXdomain sockets, UDP or TCP.

Only one call to Dial is necessary. On write failures,the syslog client will attempt to reconnect to the serverand 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

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

funcNewLogger

func NewLogger(pPriority, logFlagint) (*log.Logger,error)

NewLogger creates alog.Logger whose output is written to thesystem log service with the specified priority, a combination ofthe syslog facility and severity. The logFlag argument is the flagset passed through tolog.New to create the Logger.

Types

typePriority

type Priorityint

The Priority is a combination of the syslog facility andseverity. For example,LOG_ALERT |LOG_FTP sends an alert severitymessage from the FTP facility. The default severity isLOG_EMERG;the default facility isLOG_KERN.

const (// From /usr/include/sys/syslog.h.// These are the same on Linux, BSD, and OS X.LOG_EMERGPriority =iotaLOG_ALERTLOG_CRITLOG_ERRLOG_WARNINGLOG_NOTICELOG_INFOLOG_DEBUG)
const (// From /usr/include/sys/syslog.h.// These are the same up to LOG_FTP on Linux, BSD, and OS X.LOG_KERNPriority =iota << 3LOG_USERLOG_MAILLOG_DAEMONLOG_AUTHLOG_SYSLOGLOG_LPRLOG_NEWSLOG_UUCPLOG_CRONLOG_AUTHPRIVLOG_FTPLOG_LOCAL0LOG_LOCAL1LOG_LOCAL2LOG_LOCAL3LOG_LOCAL4LOG_LOCAL5LOG_LOCAL6LOG_LOCAL7)

typeWriter

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

A Writer is a connection to a syslog server.

funcDial

func Dial(network, raddrstring, priorityPriority, tagstring) (*Writer,error)

Dial establishes a connection to a log daemon by connecting toaddress raddr on the specified network. Each write to the returnedwriter sends a log message with the facility and severity(from priority) and tag. If tag is empty, theos.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 valuesof network and raddr.

Example
package mainimport ("fmt""log""log/syslog")func main() {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.")}

funcNew

func New(priorityPriority, tagstring) (*Writer,error)

New establishes a new connection to the system log daemon. Eachwrite to the returned writer sends a log message with the givenpriority (a combination of the syslog facility and severity) andprefix tag. If tag is empty, theos.Args[0] is used.

func (*Writer)Alert

func (w *Writer) Alert(mstring)error

Alert logs a message with severityLOG_ALERT, ignoring the severitypassed to New.

func (*Writer)Close

func (w *Writer) Close()error

Close closes a connection to the syslog daemon.

func (*Writer)Crit

func (w *Writer) Crit(mstring)error

Crit logs a message with severityLOG_CRIT, ignoring the severitypassed to New.

func (*Writer)Debug

func (w *Writer) Debug(mstring)error

Debug logs a message with severityLOG_DEBUG, ignoring the severitypassed to New.

func (*Writer)Emerg

func (w *Writer) Emerg(mstring)error

Emerg logs a message with severityLOG_EMERG, ignoring the severitypassed to New.

func (*Writer)Err

func (w *Writer) Err(mstring)error

Err logs a message with severityLOG_ERR, ignoring the severitypassed to New.

func (*Writer)Info

func (w *Writer) Info(mstring)error

Info logs a message with severityLOG_INFO, ignoring the severitypassed to New.

func (*Writer)Notice

func (w *Writer) Notice(mstring)error

Notice logs a message with severityLOG_NOTICE, ignoring theseverity passed to New.

func (*Writer)Warning

func (w *Writer) Warning(mstring)error

Warning logs a message with severityLOG_WARNING, ignoring theseverity passed to New.

func (*Writer)Write

func (w *Writer) Write(b []byte) (int,error)

Write sends a log message to the syslog daemon.

Notes

Bugs

  • This package is not implemented on Windows. As thesyslog package is frozen, Windows users are encouraged touse a package outside of the standard library. For background,seehttps://golang.org/issue/1108.

  • This package is not implemented on Plan 9.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp