mirror of
https://github.com/bluenviron/mediamtx.git
synced 2026-01-23 03:49:49 -08:00
Some checks are pending
code_lint / go (push) Waiting to run
code_lint / go_mod (push) Waiting to run
code_lint / docs (push) Waiting to run
code_lint / api_docs (push) Waiting to run
code_test / test_64 (push) Waiting to run
code_test / test_32 (push) Waiting to run
code_test / test_e2e (push) Waiting to run
Co-authored-by: aler9 <46489434+aler9@users.noreply.github.com>
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package logger
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"strconv"
|
|
"time"
|
|
|
|
"golang.org/x/term"
|
|
)
|
|
|
|
type destinationStdout struct {
|
|
structured bool
|
|
stdout io.Writer
|
|
useColor bool
|
|
buf bytes.Buffer
|
|
}
|
|
|
|
func newDestionationStdout(structured bool, stdout io.Writer) destination {
|
|
return &destinationStdout{
|
|
structured: structured,
|
|
stdout: stdout,
|
|
useColor: term.IsTerminal(int(os.Stdout.Fd())),
|
|
}
|
|
}
|
|
|
|
func (d *destinationStdout) log(t time.Time, level Level, format string, args ...any) {
|
|
d.buf.Reset()
|
|
|
|
if d.structured {
|
|
d.buf.WriteString(`{"timestamp":"`)
|
|
d.buf.WriteString(t.Format(time.RFC3339))
|
|
d.buf.WriteString(`","level":"`)
|
|
writeLevel(&d.buf, level, false)
|
|
d.buf.WriteString(`","message":`)
|
|
d.buf.WriteString(strconv.Quote(fmt.Sprintf(format, args...)))
|
|
d.buf.WriteString(`}`)
|
|
d.buf.WriteByte('\n')
|
|
} else {
|
|
writePlainTime(&d.buf, t, d.useColor)
|
|
writeLevel(&d.buf, level, d.useColor)
|
|
d.buf.WriteByte(' ')
|
|
fmt.Fprintf(&d.buf, format, args...)
|
|
d.buf.WriteByte('\n')
|
|
}
|
|
|
|
d.stdout.Write(d.buf.Bytes()) //nolint:errcheck
|
|
}
|
|
|
|
func (d *destinationStdout) close() {
|
|
}
|