mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-10-05 15:46:58 +08:00
allow to customize syslog prefix (#4356)
Co-authored-by: Кадышев Вячеслав <v.kadyshev@dssl.ru>
This commit is contained in:

committed by
GitHub

parent
06f723496d
commit
1069e131b0
@@ -57,6 +57,8 @@ components:
|
|||||||
type: string
|
type: string
|
||||||
logFile:
|
logFile:
|
||||||
type: string
|
type: string
|
||||||
|
sysLogPrefix:
|
||||||
|
type: string
|
||||||
readTimeout:
|
readTimeout:
|
||||||
type: string
|
type: string
|
||||||
writeTimeout:
|
writeTimeout:
|
||||||
|
@@ -161,6 +161,7 @@ type Conf struct {
|
|||||||
LogLevel LogLevel `json:"logLevel"`
|
LogLevel LogLevel `json:"logLevel"`
|
||||||
LogDestinations LogDestinations `json:"logDestinations"`
|
LogDestinations LogDestinations `json:"logDestinations"`
|
||||||
LogFile string `json:"logFile"`
|
LogFile string `json:"logFile"`
|
||||||
|
SysLogPrefix string `json:"sysLogPrefix"`
|
||||||
ReadTimeout Duration `json:"readTimeout"`
|
ReadTimeout Duration `json:"readTimeout"`
|
||||||
WriteTimeout Duration `json:"writeTimeout"`
|
WriteTimeout Duration `json:"writeTimeout"`
|
||||||
ReadBufferCount *int `json:"readBufferCount,omitempty"` // deprecated
|
ReadBufferCount *int `json:"readBufferCount,omitempty"` // deprecated
|
||||||
@@ -311,6 +312,7 @@ func (conf *Conf) setDefaults() {
|
|||||||
conf.LogLevel = LogLevel(logger.Info)
|
conf.LogLevel = LogLevel(logger.Info)
|
||||||
conf.LogDestinations = LogDestinations{logger.DestinationStdout}
|
conf.LogDestinations = LogDestinations{logger.DestinationStdout}
|
||||||
conf.LogFile = "mediamtx.log"
|
conf.LogFile = "mediamtx.log"
|
||||||
|
conf.SysLogPrefix = "mediamtx"
|
||||||
conf.ReadTimeout = 10 * Duration(time.Second)
|
conf.ReadTimeout = 10 * Duration(time.Second)
|
||||||
conf.WriteTimeout = 10 * Duration(time.Second)
|
conf.WriteTimeout = 10 * Duration(time.Second)
|
||||||
conf.WriteQueueSize = 512
|
conf.WriteQueueSize = 512
|
||||||
|
@@ -127,7 +127,7 @@ func New(args []string) (*Core, bool) {
|
|||||||
done: make(chan struct{}),
|
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)
|
p.conf, p.confPath, err = conf.Load(cli.Confpath, defaultConfPaths, tempLogger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -229,6 +229,7 @@ func (p *Core) createResources(initial bool) error {
|
|||||||
logger.Level(p.conf.LogLevel),
|
logger.Level(p.conf.LogLevel),
|
||||||
p.conf.LogDestinations,
|
p.conf.LogDestinations,
|
||||||
p.conf.LogFile,
|
p.conf.LogFile,
|
||||||
|
p.conf.SysLogPrefix,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -649,7 +650,8 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) {
|
|||||||
closeLogger := newConf == nil ||
|
closeLogger := newConf == nil ||
|
||||||
newConf.LogLevel != p.conf.LogLevel ||
|
newConf.LogLevel != p.conf.LogLevel ||
|
||||||
!reflect.DeepEqual(newConf.LogDestinations, p.conf.LogDestinations) ||
|
!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 ||
|
closeAuthManager := newConf == nil ||
|
||||||
newConf.AuthMethod != p.conf.AuthMethod ||
|
newConf.AuthMethod != p.conf.AuthMethod ||
|
||||||
|
@@ -34,7 +34,8 @@ func TestCoreErrors(t *testing.T) {
|
|||||||
{
|
{
|
||||||
"logger",
|
"logger",
|
||||||
"logDestinations: [file]\n" +
|
"logDestinations: [file]\n" +
|
||||||
"logFile: /nonexisting/nonexist\n",
|
"logFile: /nonexisting/nonexist\n" +
|
||||||
|
"sysLogPrefix: /mediamtx\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"metrics",
|
"metrics",
|
||||||
|
@@ -11,8 +11,8 @@ type destinationSysLog struct {
|
|||||||
buf bytes.Buffer
|
buf bytes.Buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDestinationSyslog() (destination, error) {
|
func newDestinationSyslog(prefix string) (destination, error) {
|
||||||
syslog, err := newSysLog("mediamtx")
|
syslog, err := newSysLog(prefix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,7 @@ type Logger struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New allocates a log handler.
|
// 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{
|
lh := &Logger{
|
||||||
level: level,
|
level: level,
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,7 @@ func New(level Level, destinations []Destination, filePath string) (*Logger, err
|
|||||||
lh.destinations = append(lh.destinations, dest)
|
lh.destinations = append(lh.destinations, dest)
|
||||||
|
|
||||||
case DestinationSyslog:
|
case DestinationSyslog:
|
||||||
dest, err := newDestinationSyslog()
|
dest, err := newDestinationSyslog(sysLogPrefix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lh.Close()
|
lh.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@@ -12,6 +12,8 @@ logLevel: info
|
|||||||
logDestinations: [stdout]
|
logDestinations: [stdout]
|
||||||
# If "file" is in logDestinations, this is the file which will receive the logs.
|
# If "file" is in logDestinations, this is the file which will receive the logs.
|
||||||
logFile: mediamtx.log
|
logFile: mediamtx.log
|
||||||
|
# If "syslog" is in logDestinations, use prefix for logs.
|
||||||
|
sysLogPrefix: mediamtx
|
||||||
|
|
||||||
# Timeout of read operations.
|
# Timeout of read operations.
|
||||||
readTimeout: 10s
|
readTimeout: 10s
|
||||||
|
Reference in New Issue
Block a user