# How to change logstash default timezone

**URL:** https://discuss.elastic.co/t/how-to-change-logstash-default-timezone/157304
**Category:** Logstash
**Created:** [November 19, 2018, 9:00am UTC](https://discuss.elastic.co/t/how-to-change-logstash-default-timezone/157304 "2018-11-19T09:00:10Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Manoj\_Hettiarachchi](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@Manoj\_Hettiarachchi](https://discuss.elastic.co/u/Manoj_Hettiarachchi)
#### Post date: [November 19, 2018, 9:00am UTC](https://discuss.elastic.co/t/how-to-change-logstash-default-timezone/157304/1 "2018-11-19T09:00:10Z")

</div>

Hello,

In my system, I use filebeat and logstash. The data written to the log files are sent to logstash via filebeat. Some fields in the logs are filtered and saved in csv format using logstash.

Problem:

When saving data in CSV files I need to save data belongs to each day in sperate files. So my "output" is as follows.

```
output {
  csv {
     path => "/var/csv_reports/%{+YYYY}-%{+MM}-%{+dd}/transaction-report.csv"
     fields => ["timestamp","tid","api","user","application","app_id", "body"]
  }
}

```

The file is shifting process happens in UTC time. So the generated files contain data belongs to 2 days.  
How can I change the default timezone of logstash to my timezone ( +5:30).

Your help is much appreciated.

Thanks,

---

<div class="post-metadata">

### Author: ![asp](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@asp](https://discuss.elastic.co/u/asp)
#### Post date: [November 19, 2018, 9:35am UTC](https://discuss.elastic.co/t/how-to-change-logstash-default-timezone/157304/2 "2018-11-19T09:35:44Z")

</div>

Hi,

don't know how to change it globally, but you can define the time zone used in your logs.  
To do so, you need to use the date filter plugin:

```
date 
{
	match => ['LogTime', 'dd.MM.YYYY HH:mm:ss']
	timezone => "Europe/Berlin"
	
	# remove fields no longer needed
	remove_field => ['LogTime']
}

```

In the example above my date field is stored as "logTime".  
Since I am not specifying a target, logtime is automatically stored in @timestamp.

So log time is Berlin time. Logstash converts it to UTC.  
Kibana is converting UTC to browser's timestamp on loading the visualization. Internally elastic is storing the timestamp in utc.

Regards, Andreas

---

<div class="post-metadata">

### Author: ![Manoj\_Hettiarachchi](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@Manoj\_Hettiarachchi](https://discuss.elastic.co/u/Manoj_Hettiarachchi)
#### Post date: [November 19, 2018, 11:04am UTC](https://discuss.elastic.co/t/how-to-change-logstash-default-timezone/157304/3 "2018-11-19T11:04:21Z")

</div>

Hello @asp

I have added the "date" field to my filter {} area. But no success.  
Still, the directory name is created according to UTC time zone.

Thanks,

---

<div class="post-metadata">

### Author: ![Manoj\_Hettiarachchi](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@Manoj\_Hettiarachchi](https://discuss.elastic.co/u/Manoj_Hettiarachchi)
#### Post date: [November 19, 2018, 11:47am UTC](https://discuss.elastic.co/t/how-to-change-logstash-default-timezone/157304/4 "2018-11-19T11:47:24Z")

</div>

Hello again

I have found a solution here: [https://stackoverflow.com/questions/29302444/convert-timestamp-timezone-in-logstash-for-output-index-name](https://stackoverflow.com/questions/29302444/convert-timestamp-timezone-in-logstash-for-output-index-name)

so my new logstash config is as fallows

```
filter{
..........
ruby {
        code => "event.set('index_day', event.get('[@timestamp]').time.localtime.strftime('%Y%m%d'))"
    }
}

output {
  csv {
     path => "/var/csv_reports/%{index_day}/transaction-report.csv"
     fields => ["timestamp","tid","api","publisher","user","consumerKey","application","app_id"]
  }
}

```

Now the directory name can is created with the timestamp in my log lines.  
This solved my issue.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [December 17, 2018, 11:47am UTC](https://discuss.elastic.co/t/how-to-change-logstash-default-timezone/157304/5 "2018-12-17T11:47:28Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
