diff --git a/apidocs/openapi.yaml b/apidocs/openapi.yaml index f51b48f8..984c14b0 100644 --- a/apidocs/openapi.yaml +++ b/apidocs/openapi.yaml @@ -57,6 +57,8 @@ components: type: string logFile: type: string + sysLogPrefix: + type: string readTimeout: type: string writeTimeout: diff --git a/internal/conf/conf.go b/internal/conf/conf.go index 78f2a784..d3a0e747 100644 --- a/internal/conf/conf.go +++ b/internal/conf/conf.go @@ -161,6 +161,7 @@ type Conf struct { LogLevel LogLevel `json:"logLevel"` LogDestinations LogDestinations `json:"logDestinations"` LogFile string `json:"logFile"` + SysLogPrefix string `json:"sysLogPrefix"` ReadTimeout Duration `json:"readTimeout"` WriteTimeout Duration `json:"writeTimeout"` ReadBufferCount *int `json:"readBufferCount,omitempty"` // deprecated @@ -311,6 +312,7 @@ func (conf *Conf) setDefaults() { conf.LogLevel = LogLevel(logger.Info) conf.LogDestinations = LogDestinations{logger.DestinationStdout} conf.LogFile = "mediamtx.log" + conf.SysLogPrefix = "mediamtx" conf.ReadTimeout = 10 * Duration(time.Second) conf.WriteTimeout = 10 * Duration(time.Second) conf.WriteQueueSize = 512 diff --git a/internal/core/core.go b/internal/core/core.go index 6ba7a449..0a168c71 100644 --- a/internal/core/core.go +++ b/internal/core/core.go @@ -127,7 +127,7 @@ func New(args []string) (*Core, bool) { done: make(chan struct{}), } - tempLogger, _ := logger.New(logger.Warn, []logger.Destination{logger.DestinationStdout}, "") + tempLogger, _ := logger.New(logger.Warn, []logger.Destination{logger.DestinationStdout}, "", "") p.conf, p.confPath, err = conf.Load(cli.Confpath, defaultConfPaths, tempLogger) if err != nil { @@ -229,6 +229,7 @@ func (p *Core) createResources(initial bool) error { logger.Level(p.conf.LogLevel), p.conf.LogDestinations, p.conf.LogFile, + p.conf.SysLogPrefix, ) if err != nil { return err @@ -649,7 +650,8 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) { closeLogger := newConf == nil || newConf.LogLevel != p.conf.LogLevel || !reflect.DeepEqual(newConf.LogDestinations, p.conf.LogDestinations) || - newConf.LogFile != p.conf.LogFile + newConf.LogFile != p.conf.LogFile || + newConf.SysLogPrefix != p.conf.SysLogPrefix closeAuthManager := newConf == nil || newConf.AuthMethod != p.conf.AuthMethod || diff --git a/internal/core/core_test.go b/internal/core/core_test.go index 15c061ae..b882b725 100644 --- a/internal/core/core_test.go +++ b/internal/core/core_test.go @@ -34,7 +34,8 @@ func TestCoreErrors(t *testing.T) { { "logger", "logDestinations: [file]\n" + - "logFile: /nonexisting/nonexist\n", + "logFile: /nonexisting/nonexist\n" + + "sysLogPrefix: /mediamtx\n", }, { "metrics", diff --git a/internal/logger/destination_syslog.go b/internal/logger/destination_syslog.go index 1798b1a9..3c7ce3f4 100644 --- a/internal/logger/destination_syslog.go +++ b/internal/logger/destination_syslog.go @@ -11,8 +11,8 @@ type destinationSysLog struct { buf bytes.Buffer } -func newDestinationSyslog() (destination, error) { - syslog, err := newSysLog("mediamtx") +func newDestinationSyslog(prefix string) (destination, error) { + syslog, err := newSysLog(prefix) if err != nil { return nil, err } diff --git a/internal/logger/logger.go b/internal/logger/logger.go index 1ff43d7d..fbf45aa0 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -19,7 +19,7 @@ type Logger struct { } // New allocates a log handler. -func New(level Level, destinations []Destination, filePath string) (*Logger, error) { +func New(level Level, destinations []Destination, filePath string, sysLogPrefix string) (*Logger, error) { lh := &Logger{ level: level, } @@ -38,7 +38,7 @@ func New(level Level, destinations []Destination, filePath string) (*Logger, err lh.destinations = append(lh.destinations, dest) case DestinationSyslog: - dest, err := newDestinationSyslog() + dest, err := newDestinationSyslog(sysLogPrefix) if err != nil { lh.Close() return nil, err diff --git a/mediamtx.yml b/mediamtx.yml index 8cecd707..1a1748c3 100644 --- a/mediamtx.yml +++ b/mediamtx.yml @@ -12,6 +12,8 @@ logLevel: info logDestinations: [stdout] # If "file" is in logDestinations, this is the file which will receive the logs. logFile: mediamtx.log +# If "syslog" is in logDestinations, use prefix for logs. +sysLogPrefix: mediamtx # Timeout of read operations. readTimeout: 10s