mirror of
https://github.com/bluenviron/mediamtx.git
synced 2026-01-25 21:09:15 -08:00
allow to customize syslog prefix (#4356)
Co-authored-by: Кадышев Вячеслав <v.kadyshev@dssl.ru>
This commit is contained in:
parent
06f723496d
commit
1069e131b0
7 changed files with 16 additions and 7 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 ||
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue