# Logstash output is not generating file with current date when timestamp field not available

**URL:** <https://discuss.elastic.co/t/logstash-output-is-not-generating-file-with-current-date-when-timestamp-field-not-available/301752>\
**Category:** Logstash\
**Created:** [April 6, 2022, 12:21pm UTC](https://discuss.elastic.co/t/logstash-output-is-not-generating-file-with-current-date-when-timestamp-field-not-available/301752 "2022-04-06T12:21:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sagarpatel](https://avatars.discourse-cdn.com/v4/letter/s/ebca7d/32.png) [@sagarpatel](https://discuss.elastic.co/u/sagarpatel)\
**Post date:** [April 6, 2022, 12:21pm UTC](https://discuss.elastic.co/t/logstash-output-is-not-generating-file-with-current-date-when-timestamp-field-not-available/301752/1 "2022-04-06T12:21:50Z")

</div>

Hi,

I am trying to create output file using logstash file output plugin but when `@timestamp` field is not available then it is not genearting file with current date.

**Below is working example** where i have added `date` filter and generated `@timestamp` field. this will generate successfully file name as `test-2022-04-06.log`

```json
input {
  http_poller {
    urls => {
      login => {
        method => post
        url => "URL"
        headers => {
          "Content-Type" => "application/x-www-form-urlencoded"
        }
        body => "username=uname&password=pwd"
     }
    }
    request_timeout => 120
    schedule => { "every" => "30s"}
    codec => "json"
	cookies => false
  }
}

filter {
  ruby {
    code => "event.set('now_ms', Time.now.to_i * 1000)"
  }

  prune {
    whitelist_names => ["now_ms", "access_token"]
  }
  
   mutate {
    convert => {
      "now_ms" => "integer"
    }
  }

  date {
    match => ["now_ms", "UNIX_MS"]
	target => "@timestamp"
  }

  prune {
    whitelist_names => ["@timestamp","now_ms", "access_token"]
  }
}

output {
  file {
	path => "test-%{+YYYY-MM-dd}.log"
  }
}

```

As using `http_poller`, I am not expecting `@timestamp` field in response. So if i removed `date` filter then it will not generate file name with date and it looks like `test-.log`

**Not working Example**

```json
input {
  http_poller {
    urls => {
      login => {
        method => post
        url => "URL"
        headers => {
          "Content-Type" => "application/x-www-form-urlencoded"
        }
        body => "username=uname&password=pwd"
     }
    }
    request_timeout => 120
    schedule => { "every" => "30s"}
    codec => "json"
	cookies => false
  }
}

filter {
  ruby {
    code => "event.set('now_ms', Time.now.to_i * 1000)"
  }

  prune {
    whitelist_names => ["now_ms", "access_token"]
  }
  
}

output {
  file {
	path => "test-%{+YYYY-MM-dd}.log"
  }
}

```

**Question:**

is `@timestamp` field is required for generating file name with current date ? or am i missing something here.

---

<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:** [April 6, 2022, 12:36pm UTC](https://discuss.elastic.co/t/logstash-output-is-not-generating-file-with-current-date-when-timestamp-field-not-available/301752/2 "2022-04-06T12:36:23Z")

</div>

Yes, you will need the `@timestamp` field in your event, the values of the `%{+YYYY-MM-dd}` are extracted from the `@timestamp` field.

If your original event does not have a date field that you can parse into the `@timestamp` field, logstash will generate a `@timestamp` field when the event enters the filter section and this field will be used for the values of `YYYY-MM-dd`.

You should edit your `prune` filter and allow the `@timestamp` field if you want to create date based files.

---

<div class="post-metadata">

**Author:** ![sagarpatel](https://avatars.discourse-cdn.com/v4/letter/s/ebca7d/32.png) [@sagarpatel](https://discuss.elastic.co/u/sagarpatel)\
**Post date:** [April 6, 2022, 1:03pm UTC](https://discuss.elastic.co/t/logstash-output-is-not-generating-file-with-current-date-when-timestamp-field-not-available/301752/3 "2022-04-06T13:03:04Z")

</div>

@leandrojmp Thanks for quick reply and help. it is working fine after adding `@timestamp` field in `prune`. I have removed date filter as well.

---

<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:** [May 4, 2022, 1:03pm UTC](https://discuss.elastic.co/t/logstash-output-is-not-generating-file-with-current-date-when-timestamp-field-not-available/301752/4 "2022-05-04T13:03:36Z")

</div>

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