mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-10-26 09:10:27 +08:00
Some checks reported warnings
lint / code (push) Has been cancelled
lint / mod-tidy (push) Has been cancelled
lint / apidocs (push) Has been cancelled
test / test64 (push) Has been cancelled
test / test32 (push) Has been cancelled
test / test_highlevel (push) Has been cancelled
36 lines
658 B
Go
36 lines
658 B
Go
package logger
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
type destinationFile struct {
|
|
file *os.File
|
|
buf bytes.Buffer
|
|
}
|
|
|
|
func newDestinationFile(filePath string) (destination, error) {
|
|
f, err := os.OpenFile(filePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &destinationFile{
|
|
file: f,
|
|
}, nil
|
|
}
|
|
|
|
func (d *destinationFile) log(t time.Time, level Level, format string, args ...interface{}) {
|
|
d.buf.Reset()
|
|
writeTime(&d.buf, t, false)
|
|
writeLevel(&d.buf, level, false)
|
|
writeContent(&d.buf, format, args)
|
|
d.file.Write(d.buf.Bytes()) //nolint:errcheck
|
|
}
|
|
|
|
func (d *destinationFile) close() {
|
|
d.file.Close()
|
|
}
|