mirror of
https://github.com/bluenviron/mediamtx.git
synced 2026-01-23 03:49:49 -08:00
Some checks are pending
code_lint / go (push) Waiting to run
code_lint / go_mod (push) Waiting to run
code_lint / docs (push) Waiting to run
code_lint / api_docs (push) Waiting to run
code_test / test_64 (push) Waiting to run
code_test / test_32 (push) Waiting to run
code_test / test_e2e (push) Waiting to run
When writing log entries to syslog, pass the level (WARN, INFO, etc) directly to syslog. Avoid writing level and date. This provides a better integration and allows to use syslog search tools.
47 lines
885 B
Go
47 lines
885 B
Go
//go:build !darwin && !windows
|
|
|
|
package logger
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"log/syslog"
|
|
"time"
|
|
)
|
|
|
|
type destinationSysLog struct {
|
|
syslog *syslog.Writer
|
|
buf bytes.Buffer
|
|
}
|
|
|
|
func newDestinationSyslog(prefix string) (destination, error) {
|
|
syslog, err := syslog.New(syslog.LOG_DAEMON, prefix)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &destinationSysLog{
|
|
syslog: syslog,
|
|
}, nil
|
|
}
|
|
|
|
func (d *destinationSysLog) log(_ time.Time, level Level, format string, args ...any) {
|
|
d.buf.Reset()
|
|
|
|
fmt.Fprintf(&d.buf, format, args...)
|
|
|
|
switch level {
|
|
case Debug:
|
|
d.syslog.Debug(d.buf.String()) //nolint:errcheck
|
|
case Info:
|
|
d.syslog.Info(d.buf.String()) //nolint:errcheck
|
|
case Warn:
|
|
d.syslog.Warning(d.buf.String()) //nolint:errcheck
|
|
case Error:
|
|
d.syslog.Err(d.buf.String()) //nolint:errcheck
|
|
}
|
|
}
|
|
|
|
func (d *destinationSysLog) close() {
|
|
d.syslog.Close() //nolint:errcheck
|
|
}
|