mirror of
https://github.com/bluenviron/mediamtx.git
synced 2025-12-20 02:00:05 -08:00
Merge 16f4c9d3d0 into 9e82b5233d
This commit is contained in:
commit
f5a757be1f
6 changed files with 49 additions and 4 deletions
|
|
@ -73,6 +73,8 @@ components:
|
|||
type: array
|
||||
items:
|
||||
type: string
|
||||
structuredLog:
|
||||
type: boolean
|
||||
logFile:
|
||||
type: string
|
||||
sysLogPrefix:
|
||||
|
|
|
|||
|
|
@ -152,6 +152,7 @@ type Conf struct {
|
|||
// General
|
||||
LogLevel LogLevel `json:"logLevel"`
|
||||
LogDestinations LogDestinations `json:"logDestinations"`
|
||||
StructuredLog bool `json:"structuredLog"`
|
||||
LogFile string `json:"logFile"`
|
||||
SysLogPrefix string `json:"sysLogPrefix"`
|
||||
ReadTimeout Duration `json:"readTimeout"`
|
||||
|
|
@ -318,6 +319,7 @@ func (conf *Conf) setDefaults() {
|
|||
// General
|
||||
conf.LogLevel = LogLevel(logger.Info)
|
||||
conf.LogDestinations = LogDestinations{logger.DestinationStdout}
|
||||
conf.StructuredLog = false
|
||||
conf.LogFile = "mediamtx.log"
|
||||
conf.SysLogPrefix = "mediamtx"
|
||||
conf.ReadTimeout = 10 * Duration(time.Second)
|
||||
|
|
|
|||
|
|
@ -157,7 +157,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}, "", "", false)
|
||||
|
||||
confPaths := append([]string(nil), defaultConfPaths...)
|
||||
if runtime.GOOS != "windows" {
|
||||
|
|
@ -268,6 +268,7 @@ func (p *Core) createResources(initial bool) error {
|
|||
p.conf.LogDestinations,
|
||||
p.conf.LogFile,
|
||||
p.conf.SysLogPrefix,
|
||||
p.conf.StructuredLog,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -691,7 +692,8 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) {
|
|||
newConf.LogLevel != p.conf.LogLevel ||
|
||||
!reflect.DeepEqual(newConf.LogDestinations, p.conf.LogDestinations) ||
|
||||
newConf.LogFile != p.conf.LogFile ||
|
||||
newConf.SysLogPrefix != p.conf.SysLogPrefix
|
||||
newConf.SysLogPrefix != p.conf.SysLogPrefix ||
|
||||
newConf.StructuredLog != p.conf.StructuredLog
|
||||
|
||||
closeAuthManager := newConf == nil ||
|
||||
newConf.AuthMethod != p.conf.AuthMethod ||
|
||||
|
|
|
|||
33
internal/logger/destination_stdout_structured.go
Normal file
33
internal/logger/destination_stdout_structured.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package logger
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type destinationStdoutStructured struct {
|
||||
buf bytes.Buffer
|
||||
}
|
||||
|
||||
func newDestionationStdoutStructured() destination {
|
||||
return &destinationStdoutStructured{}
|
||||
}
|
||||
|
||||
func (d *destinationStdoutStructured) log(t time.Time, level Level, format string, args ...any) {
|
||||
d.buf.Reset()
|
||||
d.buf.WriteString(`{"ts":"`)
|
||||
writeTime(&d.buf, t, false)
|
||||
d.buf.WriteString(`","level":"`)
|
||||
writeLevel(&d.buf, level, false)
|
||||
d.buf.WriteString(`","msg":"`)
|
||||
d.buf.WriteString(strconv.Quote(fmt.Sprintf(format, args...)))
|
||||
d.buf.WriteString(`"}`)
|
||||
d.buf.WriteByte('\n')
|
||||
os.Stdout.Write(d.buf.Bytes()) //nolint:errcheck
|
||||
}
|
||||
|
||||
func (d *destinationStdoutStructured) close() {
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@ type Logger struct {
|
|||
}
|
||||
|
||||
// New allocates a log handler.
|
||||
func New(level Level, destinations []Destination, filePath string, sysLogPrefix string) (*Logger, error) {
|
||||
func New(level Level, destinations []Destination, filePath string, sysLogPrefix string, structuredLog bool) (*Logger, error) {
|
||||
lh := &Logger{
|
||||
level: level,
|
||||
}
|
||||
|
|
@ -27,7 +27,11 @@ func New(level Level, destinations []Destination, filePath string, sysLogPrefix
|
|||
for _, destType := range destinations {
|
||||
switch destType {
|
||||
case DestinationStdout:
|
||||
lh.destinations = append(lh.destinations, newDestionationStdout())
|
||||
if structuredLog {
|
||||
lh.destinations = append(lh.destinations, newDestionationStdoutStructured())
|
||||
} else {
|
||||
lh.destinations = append(lh.destinations, newDestionationStdout())
|
||||
}
|
||||
|
||||
case DestinationFile:
|
||||
dest, err := newDestinationFile(filePath)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@
|
|||
logLevel: info
|
||||
# Destinations of log messages; available values are "stdout", "file" and "syslog".
|
||||
logDestinations: [stdout]
|
||||
# If "stdout" in logDestination, use json for logs.
|
||||
structuredLog: no
|
||||
# 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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue