logging: Correctly track number of written bytes

Currently this assumes that a short write will never happen. While these
are improbable in a case where rotation being off a few bytes would
matter, this now correctly tracks the number of written bytes.
This commit is contained in:
Danielle Lancashire
2019-10-10 14:02:14 +02:00
parent 277a252ea4
commit 567ad88165

View File

@@ -121,7 +121,7 @@ func (l *logFile) pruneFiles() error {
}
// Write is used to implement io.Writer
func (l *logFile) Write(b []byte) (n int, err error) {
func (l *logFile) Write(b []byte) (int, error) {
// Filter out log entries that do not match log level criteria
if !l.logFilter.Check(b) {
return 0, nil
@@ -139,6 +139,8 @@ func (l *logFile) Write(b []byte) (n int, err error) {
if err := l.rotate(); err != nil {
return 0, err
}
l.BytesWritten += int64(len(b))
return l.FileInfo.Write(b)
n, err := l.FileInfo.Write(b)
l.BytesWritten += int64(n)
return n, err
}