mirror of
https://github.com/bluenviron/mediamtx
synced 2025-02-27 09:00:36 +00:00
re-add time to log entries saved to file (#67)
This commit is contained in:
parent
51e441a1cf
commit
175a93b1f1
20
main.go
20
main.go
@ -26,6 +26,12 @@ const (
|
|||||||
logDestinationFile
|
logDestinationFile
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type logWriter func([]byte) (int, error)
|
||||||
|
|
||||||
|
func (f logWriter) Write(p []byte) (int, error) {
|
||||||
|
return f(p)
|
||||||
|
}
|
||||||
|
|
||||||
type program struct {
|
type program struct {
|
||||||
conf *conf
|
conf *conf
|
||||||
logFile *os.File
|
logFile *os.File
|
||||||
@ -106,6 +112,8 @@ func newProgram(args []string, stdin io.Reader) (*program, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.SetOutput(logWriter(p.logOutput))
|
||||||
|
|
||||||
p.log("rtsp-simple-server %s", Version)
|
p.log("rtsp-simple-server %s", Version)
|
||||||
|
|
||||||
if conf.Metrics {
|
if conf.Metrics {
|
||||||
@ -156,16 +164,20 @@ func (p *program) log(format string, args ...interface{}) {
|
|||||||
countPublisher := atomic.LoadInt64(&p.countPublisher)
|
countPublisher := atomic.LoadInt64(&p.countPublisher)
|
||||||
countReader := atomic.LoadInt64(&p.countReader)
|
countReader := atomic.LoadInt64(&p.countReader)
|
||||||
|
|
||||||
line := fmt.Sprintf("[%d/%d/%d] "+format, append([]interface{}{countClient,
|
log.Printf(fmt.Sprintf("[%d/%d/%d] "+format, append([]interface{}{countClient,
|
||||||
countPublisher, countReader}, args...)...)
|
countPublisher, countReader}, args...)...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *program) logOutput(line []byte) (int, error) {
|
||||||
if _, ok := p.conf.logDestinationsParsed[logDestinationStdout]; ok {
|
if _, ok := p.conf.logDestinationsParsed[logDestinationStdout]; ok {
|
||||||
log.Println(line)
|
print(string(line))
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := p.conf.logDestinationsParsed[logDestinationFile]; ok {
|
if _, ok := p.conf.logDestinationsParsed[logDestinationFile]; ok {
|
||||||
p.logFile.WriteString(line + "\n")
|
p.logFile.Write(line)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return len(line), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *program) run() {
|
func (p *program) run() {
|
||||||
|
Loading…
Reference in New Issue
Block a user