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 b67215d4f8
commit 5cedf6d024
No known key found for this signature in database
GPG Key ID: 8D65584EF3DDF91B
1 changed files with 5 additions and 3 deletions

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
}