# Add Logstash host name to JSON formatted logstream

**URL:** https://discuss.elastic.co/t/add-logstash-host-name-to-json-formatted-logstream/140567
**Category:** Logstash
**Created:** [July 18, 2018, 1:29pm UTC](https://discuss.elastic.co/t/add-logstash-host-name-to-json-formatted-logstream/140567 "2018-07-18T13:29:58Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [July 24, 2018, 9:31am UTC](https://discuss.elastic.co/t/add-logstash-host-name-to-json-formatted-logstream/140567/4 "2018-07-24T09:31:20Z")

</div>

You can use a json filter to parse that JSON string, but if that's not the hostname you're interested in perhaps it doesn't matter.

> I glanced at the logstash hostname link, and that makes sense, my only concern is does it make that socket call for every event is processed?

Yes, but I'd expect it to be a cheap operation. Otherwise you should be able to fetch the hostname once when the filter initializes and reuse that value for each event. Something like this might work:

```plaintext
ruby {
  init => "
    require 'socket'
    @@hostname = Socket.gethostname
  "
  code => "event.set('host', @@hostname)"

```

---

_[View the full topic](https://discuss.elastic.co/t/add-logstash-host-name-to-json-formatted-logstream/140567)._
