Files
rtsp-simple-server/internal/logger/destination_file.go
Alessandro Ros 659f19f8bb
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
enable errcheck (#2201)
2023-08-13 16:38:23 +02:00

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()
}