Logstash sends all unprocessed leftovers into a separate .log file for archiving purposes
output{ file { path => "/var/log/logstash/archive-%{+YYYY.MM.dd}.log" } }
The problem is that logstash additionally offsets the date (at least I assume it does) by my timezone (Etc/GMT-5, +5:00), so instead of starting to write in the new file at midnight it only does so at 5 in the morning.
Is it possible to add manual offset by minus 5 hours or I have to add usage of ruby in the config file to receive local time and use it for the name instead?
So I do have to add block for ruby… Ah well, cheers
cramped both lines into one event.set, Logstash is seemingly unhappy with ruby having it’s own variables event.set('index_date', event.get('@timestamp').time.localtime.strftime('%Y.%m.%d')
What’s happening is that %{+YYYY.MM.dd} uses the event’s @timestamp, and that timestamp is in UTC by default. So your file rollover is based on UTC midnight, not your local time — that’s why it switches around 5 AM for you. You don’t need Ruby for this.
The cleaner fix is to make sure the event timestamp is converted to your local timezone before the file output runs. You can do that with the date filter by setting the timezone properly when parsing the timestamp, or by adjusting @timestamp to your local zone.
Another option (simpler if this is just for file naming) is to set Logstash’s JVM timezone to your local timezone instead of UTC. You can do that by adding:
-Duser.timezone=Etc/GMT-5
to your Logstash JVM options and restarting the service. That way, the date pattern in the filename will roll over at your local midnight instead of UTC. So no, you don’t need Ruby — just align Logstash’s timezone handling with your local time.
Just as information, this does not work, the @timestamp field in Logstash will always be in UTC, it doesn't matter if you change the timezone of the server or the process, it will always convert it to UTC.
In this case, the ruby approach is the way to create files with the date and/or time in local time.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.