diff --git a/apps/nsq_to_file/file_logger.go b/apps/nsq_to_file/file_logger.go index bc9571ad1..4fe77b009 100644 --- a/apps/nsq_to_file/file_logger.go +++ b/apps/nsq_to_file/file_logger.go @@ -229,13 +229,19 @@ func (f *FileLogger) Write(p []byte) (int, error) { } func (f *FileLogger) Sync() error { + var err error if f.gzipWriter != nil { - err := f.gzipWriter.Flush() + err = f.gzipWriter.Close() if err != nil { return err } + err = f.out.Sync() + f.gzipWriter, _ = gzip.NewWriterLevel(f.out, f.opts.GZIPLevel) + f.writer = f.gzipWriter + } else { + err = f.out.Sync() } - return f.out.Sync() + return err } func (f *FileLogger) currentFilename() string {