diff --git a/apps/nsq_to_file/file_logger.go b/apps/nsq_to_file/file_logger.go index d80bb4c95..c074fc7ec 100644 --- a/apps/nsq_to_file/file_logger.go +++ b/apps/nsq_to_file/file_logger.go @@ -110,11 +110,11 @@ func (f *FileLogger) router() { f.updateFile() sync = true } - _, err := f.writer.Write(m.Body) + _, err := f.Write(m.Body) if err != nil { log.Fatalf("ERROR: writing message to disk - %s", err) } - _, err = f.writer.Write([]byte("\n")) + _, err = f.Write([]byte("\n")) if err != nil { log.Fatalf("ERROR: writing newline to disk - %s", err) } @@ -205,9 +205,10 @@ func (f *FileLogger) Close() { f.out = nil } -func (f *FileLogger) Write(p []byte) (n int, err error) { - f.filesize += int64(len(p)) - return f.out.Write(p) +func (f *FileLogger) Write(p []byte) (int, error) { + n, err := f.writer.Write(p) + f.filesize += int64(n) + return err } func (f *FileLogger) Sync() error { @@ -323,10 +324,10 @@ func (f *FileLogger) updateFile() { } if f.opts.GZIP { - f.gzipWriter, _ = gzip.NewWriterLevel(f, f.opts.GZIPLevel) + f.gzipWriter, _ = gzip.NewWriterLevel(f.out, f.opts.GZIPLevel) f.writer = f.gzipWriter } else { - f.writer = f + f.writer = f.out } }