I am running Logstash 5.2 on Windows7 and I have a rotating log use case, where I maintain a file batchlog.txt
everyday and I read this file into logstash and output to ES (daily indices)
My file input config:
input {
file {
codec => json
path => "..\batchlog.txt"
sincedb_path => "..\.sincedb_test"
}
}
Every night, I rotate this log file by renaming it with previous day's date. And I create a new log file with same name.
Example: I rename batchlog.txt
on 02-08-2017 00:00:00
to batchlog-02-07-2017.txt
and Then I create a new file batchlog.txt
and start writing logs to this file.
So, based on my configuration, I only read 1 file (batchlog.txt
) and that is what I need.
During this process of rotation, my sincedb
file is changing the offset of rotated file.
Example:
At 11:58 PM, the offset value of batchlog.txt
was 5536732 and after renaming the file, the offset changed to 108
State of sincedb at 11:58 PM:
384971208-64889-15073280 0 0 5536732
State of sincedb at 00:10 AM nextday:
384971208-64889-15073280 0 0 108 <-- This is the previous batchlog.txt; now renamed
384971208-1497637-3735552 0 0 20456 <-- This is the new batchlog.txt
This offset change is causing unexpected behavior during indexing as well. During rotation. some of the logs of previous day's file are being duplicated into current day's index.
Am I doing the procedure right? Does renaming the file causes this behavior of sincedb and duplication of logs? How do I actually rotate the files then?