From f77fd8af5765e68f035b0eafa52b4c03b8d4d06d Mon Sep 17 00:00:00 2001 From: Shuai Lin Date: Sun, 25 Jul 2021 23:39:07 +0800 Subject: [PATCH 1/2] Fixed --output-file-size-limit --- output_file.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/output_file.go b/output_file.go index b87827e..7564247 100644 --- a/output_file.go +++ b/output_file.go @@ -66,12 +66,12 @@ type FileOutput struct { currentName string file *os.File QueueLength int - chunkSize int writer io.Writer requestPerFile bool currentID []byte payloadType []byte closed bool + currentFileSize int totalFileSize size.Size config *FileOutputConfig @@ -174,7 +174,7 @@ func (o *FileOutput) filename() string { if o.currentName == "" || ((o.config.QueueLimit > 0 && o.QueueLength >= o.config.QueueLimit) || - (o.config.SizeLimit > 0 && o.chunkSize >= int(o.config.SizeLimit))) { + (o.config.SizeLimit > 0 && o.currentFileSize >= int(o.config.SizeLimit))) { nextChunk = true } @@ -195,6 +195,7 @@ func (o *FileOutput) filename() string { if nextChunk { fileIndex++ + o.currentFileSize = 0 } } @@ -253,6 +254,7 @@ func (o *FileOutput) PluginWrite(msg *Message) (n int, err error) { n += nn o.totalFileSize += size.Size(n) + o.currentFileSize += n o.QueueLength++ if Settings.OutputFileConfig.OutputFileMaxSize > 0 && o.totalFileSize >= Settings.OutputFileConfig.OutputFileMaxSize { @@ -281,7 +283,7 @@ func (o *FileOutput) flush() { } if stat, err := o.file.Stat(); err == nil { - o.chunkSize = int(stat.Size()) + o.currentFileSize = int(stat.Size()) } else { Debug(0, "[OUTPUT-HTTP] error accessing file size", err) } From debc3b4384e360b03ab43a48a24f3477ed6bd81b Mon Sep 17 00:00:00 2001 From: Shuai Lin Date: Sun, 25 Jul 2021 23:39:21 +0800 Subject: [PATCH 2/2] Applied gofmt --- output_file.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/output_file.go b/output_file.go index 7564247..6be27e9 100644 --- a/output_file.go +++ b/output_file.go @@ -62,17 +62,17 @@ type FileOutputConfig struct { // FileOutput output plugin type FileOutput struct { sync.RWMutex - pathTemplate string - currentName string - file *os.File - QueueLength int - writer io.Writer - requestPerFile bool - currentID []byte - payloadType []byte - closed bool - currentFileSize int - totalFileSize size.Size + pathTemplate string + currentName string + file *os.File + QueueLength int + writer io.Writer + requestPerFile bool + currentID []byte + payloadType []byte + closed bool + currentFileSize int + totalFileSize size.Size config *FileOutputConfig }