2020-10-13 22:02:55 +00:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package syslog
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
native "log/syslog"
|
|
|
|
)
|
|
|
|
|
|
|
|
type syslog struct {
|
|
|
|
inner *native.Writer
|
|
|
|
}
|
|
|
|
|
2020-11-05 11:30:25 +00:00
|
|
|
// New allocates a io.WriteCloser that writes to the system log.
|
2020-10-13 22:02:55 +00:00
|
|
|
func New(prefix string) (io.WriteCloser, error) {
|
|
|
|
inner, err := native.New(native.LOG_INFO|native.LOG_DAEMON, prefix)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &syslog{
|
|
|
|
inner: inner,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-11-05 11:30:25 +00:00
|
|
|
// Close implements io.WriteCloser.
|
2020-10-13 22:02:55 +00:00
|
|
|
func (ls *syslog) Close() error {
|
|
|
|
return ls.inner.Close()
|
|
|
|
}
|
|
|
|
|
2020-11-05 11:30:25 +00:00
|
|
|
// Write implements io.WriteCloser.
|
2020-10-13 22:02:55 +00:00
|
|
|
func (ls *syslog) Write(p []byte) (int, error) {
|
|
|
|
return ls.inner.Write(p)
|
|
|
|
}
|