mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user