Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultFormatter(timestamp time.Time, p Priority, hostname, tag string, content []byte) []byte
- func DefaultFramer(in []byte) [][]byte
- func NewLogger(p Priority, logFlag int) (*log.Logger, error)
- func RFC3164Formatter(timestamp time.Time, p Priority, hostname, tag string, content []byte) []byte
- func RFC5424Formatter(timestamp time.Time, p Priority, hostname, tag string, content []byte) []byte
- func RFC5425MessageLengthFramer(in []byte) [][]byte
- func UnixFormatter(timestamp time.Time, p Priority, _, tag string, content []byte) []byte
- type DialFunc
- type Formatter
- type Framer
- type Priority
- type Writer
- func Dial(network, raddr string, priority Priority, tag string) (*Writer, error)
- func DialWithCustomDialer(network, raddr string, priority Priority, tag string, customDial DialFunc) (*Writer, error)
- func DialWithTLSCert(network, raddr string, priority Priority, tag string, serverCert []byte) (*Writer, error)
- func DialWithTLSCertPath(network, raddr string, priority Priority, tag, certPath string) (*Writer, error)
- func DialWithTLSConfig(network, raddr string, priority Priority, tag string, tlsConfig *tls.Config) (*Writer, error)
- func New(priority Priority, tag string) (w *Writer, err error)
- func (w *Writer) Alert(m string) (err error)
- func (w *Writer) Close() error
- func (w *Writer) Crit(m string) (err error)
- func (w *Writer) Debug(m string) (err error)
- func (w *Writer) Emerg(m string) (err error)
- func (w *Writer) Err(m string) (err error)
- func (w *Writer) Info(m string) (err error)
- func (w *Writer) Notice(m string) (err error)
- func (w *Writer) SetFormatter(f Formatter)
- func (w *Writer) SetFramer(f Framer)
- func (w *Writer) SetHostname(hostname string)
- func (w *Writer) Warning(m string) (err error)
- func (w *Writer) Write(b []byte) (int, error)
- func (w *Writer) WriteWithPriority(p Priority, b []byte) (int, error)
- func (w *Writer) WriteWithTimestamp(timestamp time.Time, b []byte) (int, error)
- func (w *Writer) WriteWithTimestampAndPriority(timestamp time.Time, p Priority, b []byte) (int, error)
Constants ¶
const FacilityMask = 0xf8
const SeverityMask = 0x07
Variables ¶
var ErrNilDialFunc = errors.New("srslog: nil DialFunc passed to DialWithCustomDialer")
ErrNilDialFunc is returned from DialWithCustomDialer when a nil DialFunc is passed, avoiding a nil pointer deference panic.
Functions ¶
func DefaultFormatter ¶
DefaultFormatter is the original format supported by the Go syslog package, and is a non-compliant amalgamation of 3164 and 5424 that is intended to maximize compatibility.
func DefaultFramer ¶
DefaultFramer does nothing, since there is no framing to apply. This is the original behavior of the Go syslog package, and is also typically used for UDP syslog.
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.
func RFC3164Formatter ¶
RFC3164Formatter provides an RFC 3164 compliant message.
func RFC5424Formatter ¶
RFC5424Formatter provides an RFC 5424 compliant message.
func RFC5425MessageLengthFramer ¶
RFC5425MessageLengthFramer prepends the message length to the front of the provided message, as defined in RFC 5425.
Types ¶
type DialFunc ¶
DialFunc is the function signature to be used for a custom dialer callback with DialWithCustomDialer
type Formatter ¶
Formatter is a type of function that takes the constituent parts of a syslog message and returns a formatted string. A different Formatter is defined for each different syslog protocol we support.
type Framer ¶
Framer is a type of function that takes an input string (typically an already-formatted syslog message) and applies "message framing" to it. We have different framers because different versions of the syslog protocol and its transport requirements define different framing behavior.
type Priority ¶
type Priority int
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.
const ( // From /usr/include/sys/syslog.h. // These are the same up to LOG_FTP on Linux, BSD, and OS X. LOG_KERN Priority = iota << 3 LOG_USER LOG_MAIL LOG_DAEMON LOG_AUTH LOG_SYSLOG LOG_LPR LOG_NEWS LOG_UUCP LOG_CRON LOG_AUTHPRIV LOG_FTP LOG_LOCAL0 LOG_LOCAL1 LOG_LOCAL2 LOG_LOCAL3 LOG_LOCAL4 LOG_LOCAL5 LOG_LOCAL6 LOG_LOCAL7 )
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
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.
func DialWithCustomDialer ¶
func DialWithCustomDialer(network, raddr string, priority Priority, tag string, customDial DialFunc) (*Writer, error)
DialWithCustomDialer establishes a connection by calling customDial. Each write to the returned Writer sends a log message with the given facility, severity and tag. Network must be "custom" in order for this package to use customDial. While network and raddr will be passed to customDial, it is allowed for customDial to ignore them. If customDial is nil, this function returns ErrNilDialFunc.
func DialWithTLSCert ¶
func DialWithTLSCert(network, raddr string, priority Priority, tag string, serverCert []byte) (*Writer, error)
DialWithTLSCert establishes a secure connection to a log daemon by connecting to address raddr on the specified network. It uses serverCert to load a TLS certificate and configure the secure connection.
func DialWithTLSCertPath ¶
func DialWithTLSCertPath(network, raddr string, priority Priority, tag, certPath string) (*Writer, error)
DialWithTLSCertPath establishes a secure connection to a log daemon by connecting to address raddr on the specified network. It uses certPath to load TLS certificates and configure the secure connection.
func DialWithTLSConfig ¶
func DialWithTLSConfig(network, raddr string, priority Priority, tag string, tlsConfig *tls.Config) (*Writer, error)
DialWithTLSConfig establishes a secure connection to a log daemon by connecting to address raddr on the specified network. It uses tlsConfig to configure the secure connection.
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; this overrides the default priority passed to `srslog.New` and the `srslog.Dial*` functions.
func (*Writer) Crit ¶
Crit logs a message with severity LOG_CRIT; this overrides the default priority passed to `srslog.New` and the `srslog.Dial*` functions.
func (*Writer) Debug ¶
Debug logs a message with severity LOG_DEBUG; this overrides the default priority passed to `srslog.New` and the `srslog.Dial*` functions.
func (*Writer) Emerg ¶
Emerg logs a message with severity LOG_EMERG; this overrides the default priority passed to `srslog.New` and the `srslog.Dial*` functions.
func (*Writer) Err ¶
Err logs a message with severity LOG_ERR; this overrides the default priority passed to `srslog.New` and the `srslog.Dial*` functions.
func (*Writer) Info ¶
Info logs a message with severity LOG_INFO; this overrides the default priority passed to `srslog.New` and the `srslog.Dial*` functions.
func (*Writer) Notice ¶
Notice logs a message with severity LOG_NOTICE; this overrides the default priority passed to `srslog.New` and the `srslog.Dial*` functions.
func (*Writer) SetFormatter ¶
SetFormatter changes the formatter function for subsequent messages.
func (*Writer) SetHostname ¶
SetHostname changes the hostname for syslog messages if needed.
func (*Writer) Warning ¶
Warning logs a message with severity LOG_WARNING; this overrides the default priority passed to `srslog.New` and the `srslog.Dial*` functions.
func (*Writer) Write ¶
Write sends a log message to the syslog daemon using the default priority passed into `srslog.New` or the `srslog.Dial*` functions.
func (*Writer) WriteWithPriority ¶
WriteWithPriority sends a log message with a custom priority.
func (*Writer) WriteWithTimestamp ¶
WriteWithTimestamp sends a log message with a custom timestamp.