# How to write remote hostname to output file with logstash

**URL:** https://discuss.elastic.co/t/how-to-write-remote-hostname-to-output-file-with-logstash/308161
**Category:** Logstash
**Created:** [June 25, 2022, 11:34am UTC](https://discuss.elastic.co/t/how-to-write-remote-hostname-to-output-file-with-logstash/308161 "2022-06-25T11:34:34Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Yunus\_Dal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yunus_dal/32/106930_2.png) [@Yunus\_Dal](https://discuss.elastic.co/u/Yunus_Dal)
#### Post date: [June 25, 2022, 11:34am UTC](https://discuss.elastic.co/t/how-to-write-remote-hostname-to-output-file-with-logstash/308161/1 "2022-06-25T11:34:34Z")

</div>

Hi,

I have java application which is running at 2 instance and collect logs from these instances.

I want to create output log file so far as remote hostname.

my logstash config;

```auto
input {
  tcp {
    codec => json
    port => 12345
  }
}

output {
  file {
    codec => json_lines
    path => "/data/logs/%{[application]}-%{[hostname]}.log-%{+YYYY-MM-dd}"
  }
}

```

output file created like this;

-rw-r--r--. 1 logstash logstash 7.1K Jun 25 11:32 analytic-rt-%{[hostname]}.log-2022-06-25  
-rw-r--r--. 1 logstash logstash 5.1K Jun 25 11:32 alarm-%{[hostname]}.log-2022-06-25

I cant see my remote hostname here.

---

<div class="post-metadata">

### Author: ![sudhagar\_ramesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sudhagar_ramesh/32/105673_2.png) [@sudhagar\_ramesh](https://discuss.elastic.co/u/sudhagar_ramesh)
#### Post date: [June 25, 2022, 12:33pm UTC](https://discuss.elastic.co/t/how-to-write-remote-hostname-to-output-file-with-logstash/308161/2 "2022-06-25T12:33:25Z")

</div>

Hello @Yunus_Dal

Welcome to Elastic Community 🙂 !!!

Just mention the field name like **%{hostname}**. Hoping **hostname** would be your field name

` path => "/data/logs/%{[application]}-%{hostname}.log-%{+YYYY-MM-dd}"`

Keep Posted with updates how it goes !!! Thanks !!!

---

<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: [June 25, 2022, 2:03pm UTC](https://discuss.elastic.co/t/how-to-write-remote-hostname-to-output-file-with-logstash/308161/3 "2022-06-25T14:03:32Z")

</div>

Your output means that you do not have the field `hostname` in your document.

You need to use `%{[host]}` instead of `%{[hostname]}`, if you are using Logstash 8 or have the `pipeline.ecs_compatibility` enabled, you would need to use `%{[@metadata][input][tcp][source][name]}`.

You can check the metadata fields availables in [the documentation](https://www.elastic.co/guide/en/logstash/current/plugins-inputs-tcp.html#plugins-inputs-tcp-ecs_metadata).

---

<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: [July 23, 2022, 4:13pm UTC](https://discuss.elastic.co/t/how-to-write-remote-hostname-to-output-file-with-logstash/308161/5 "2022-07-23T16:13:15Z")

</div>

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