2023-05-04 18:16:41 +00:00
|
|
|
package logger
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io"
|
2023-07-11 18:08:00 +00:00
|
|
|
"time"
|
2023-05-04 18:16:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type destinationSysLog struct {
|
|
|
|
syslog io.WriteCloser
|
|
|
|
buf bytes.Buffer
|
|
|
|
}
|
|
|
|
|
|
|
|
func newDestinationSyslog() (destination, error) {
|
|
|
|
syslog, err := newSysLog("mediamtx")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &destinationSysLog{
|
|
|
|
syslog: syslog,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2023-07-11 18:08:00 +00:00
|
|
|
func (d *destinationSysLog) log(t time.Time, level Level, format string, args ...interface{}) {
|
2023-05-04 18:16:41 +00:00
|
|
|
d.buf.Reset()
|
2023-07-11 18:08:00 +00:00
|
|
|
writeTime(&d.buf, t, false)
|
2023-05-04 18:16:41 +00:00
|
|
|
writeLevel(&d.buf, level, false)
|
|
|
|
writeContent(&d.buf, format, args)
|
|
|
|
d.syslog.Write(d.buf.Bytes())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *destinationSysLog) close() {
|
|
|
|
d.syslog.Close()
|
|
|
|
}
|