# Timezone in UTC causes wrong filename

**URL:** https://discuss.elastic.co/t/timezone-in-utc-causes-wrong-filename/261480
**Category:** Logstash
**Created:** [January 19, 2021, 12:37am UTC](https://discuss.elastic.co/t/timezone-in-utc-causes-wrong-filename/261480 "2021-01-19T00:37:23Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![yodog](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yodog/32/4822_2.png) [@yodog](https://discuss.elastic.co/u/yodog)
#### Post date: [January 19, 2021, 12:37am UTC](https://discuss.elastic.co/t/timezone-in-utc-causes-wrong-filename/261480/1 "2021-01-19T00:37:23Z")

</div>

i have a logserver with logstash only. no elasticsearch nor kibana.

all other servers are using filebeat to send log to the logserver.

logstash writes to `/var/log/logstash/appname.txt.%{+YYYY-MM-dd}` after some processing is done (filters).

the problem is that my timezone is `-3` (brazil) but the filenames are in `UTC`.

how can i make sure the logs are writen in the correct file?

```auto
output {
    file {
        codec => line { format => '%{@timestamp} %{message}'}
        path => '/var/log/logstash/debug.txt.%{+YYYY-MM-dd}'
    }
}

```

---

<div class="post-metadata">

### Author: ![AClerk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aclerk/32/55297_2.png) [@AClerk](https://discuss.elastic.co/u/AClerk)
#### Post date: [January 19, 2021, 12:43am UTC](https://discuss.elastic.co/t/timezone-in-utc-causes-wrong-filename/261480/2 "2021-01-19T00:43:17Z")

</div>

Have you searched?

> [@How to change logstash default timezone](https://discuss.elastic.co/t/how-to-change-logstash-default-timezone/157304):
>
> 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"…

> [@Time in IST for log-rotation - Logstash](https://discuss.elastic.co/t/time-in-ist-for-log-rotation-logstash/211612):
>
> I have configured file-beat on all the App servers and Logstash in a centralized server for the log rotation. The config file in Log rotation is input { beats { port =\> 5044 } } filter{ mutate { remove\_field =\> ["agent","input","host","architecture","containerized","mac","os","@version","log","ecs","offset"] } } output { file { path =\> "/log/sync/ims-v1/%{+dd-MM-yyyy}/%{+HH}-ims.log" } } -- In OUTPUT: Logstash to create a file/directory depending on an hourly basis for the logs: b…

[And many more](https://www.google.com/search?q=logstash+path+timezone&rlz=1C1EJFC_enAU891AU891&oq=logstash+path+timezone&aqs=chrome..69i57.13334j1j4&sourceid=chrome&ie=UTF-8)...

---

<div class="post-metadata">

### Author: ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)
#### Post date: [January 19, 2021, 2:17am UTC](https://discuss.elastic.co/t/timezone-in-utc-causes-wrong-filename/261480/3 "2021-01-19T02:17:06Z")

</div>

To do this using the `@timestamp` field is not possible, you will need to use a ruby filter to create auxiliary fields with the values that you want in the output, one field should have the pattern `YYYY-MM-dd` in your timezone, and the other field should have the `@timestamp` converted to your timezone.

Using one of the examples that @AClerk shared, you will need something like this.

```auto
filter {
    # this ruby filter sets the field [@metadata][index] as YYYY-MM-dd in your timezone
    ruby {
        code => "event.set('[@metadata][index]', event.get('[@timestamp]').time.localtime.strftime('%Y-%m-%d'))"
    }
    # this ruby filter sets the field [@metadata][timestamp] as YYYY-mm-dd HH:MM:ss.SSS
    ruby {
        code => "event.set('[@metadata][timestamp]', event.get('[@timestamp]').time.localtime.strftime('%Y-%m-%d %H:%M:%S.%L'))"
    }
    
}
output {
    file {
        codec => line { format => '%{[@metadata][timestamp]} %{message}'}
        path => "/var/log/logstash/debug.txt.%{[@metadata][index]}"
    }
}

```

This way you will create two auxiliary fields with the values you need in your timezone, the `@timestamp` field is always in UTC.

---

<div class="post-metadata">

### Author: ![yodog](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yodog/32/4822_2.png) [@yodog](https://discuss.elastic.co/u/yodog)
#### Post date: [January 19, 2021, 10:23am UTC](https://discuss.elastic.co/t/timezone-in-utc-causes-wrong-filename/261480/4 "2021-01-19T10:23:23Z")

</div>

perfect. thanks.

---

<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: [February 16, 2021, 10:23am UTC](https://discuss.elastic.co/t/timezone-in-utc-causes-wrong-filename/261480/5 "2021-02-16T10:23:33Z")

</div>

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