# ES(5.x)-to-JSON logging log4j.properties example/snippet

**URL:** https://discuss.elastic.co/t/es-5-x-to-json-logging-log4j-properties-example-snippet/97566
**Category:** Elasticsearch
**Created:** [August 18, 2017, 10:57am UTC](https://discuss.elastic.co/t/es-5-x-to-json-logging-log4j-properties-example-snippet/97566 "2017-08-18T10:57:56Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![uschtwill](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/uschtwill/32/14077_2.png) [@uschtwill](https://discuss.elastic.co/u/uschtwill)
#### Post date: [August 18, 2017, 10:57am UTC](https://discuss.elastic.co/t/es-5-x-to-json-logging-log4j-properties-example-snippet/97566/1 "2017-08-18T10:57:56Z")

</div>

Hello everybody,

I am trying to get ES to log to JSON with [https://github.com/vy/log4j2-logstash-layout](https://github.com/vy/log4j2-logstash-layout), but can not get it to work. The examples I found are using the deprecated logging.yml.

Does anybody have an example of a working configuration?

This was already asked [here](https://discuss.elastic.co/t/not-able-to-configure-log4j2-correctly-for-elasticsearch-5-0/66943), but @anishm wasn't fortunate enough to get a reply.

Happy day!  
Will

---

<div class="post-metadata">

### Author: ![uschtwill](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/uschtwill/32/14077_2.png) [@uschtwill](https://discuss.elastic.co/u/uschtwill)
#### Post date: [August 21, 2017, 8:48am UTC](https://discuss.elastic.co/t/es-5-x-to-json-logging-log4j-properties-example-snippet/97566/2 "2017-08-21T08:48:32Z")

</div>

Anybody?

---

<div class="post-metadata">

### Author: ![uschtwill](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/uschtwill/32/14077_2.png) [@uschtwill](https://discuss.elastic.co/u/uschtwill)
#### Post date: [August 22, 2017, 8:20am UTC](https://discuss.elastic.co/t/es-5-x-to-json-logging-log4j-properties-example-snippet/97566/3 "2017-08-22T08:20:25Z")

</div>

Can I provide more information or enhance the question in any way to elicit a reply?

---

<div class="post-metadata">

### Author: ![uschtwill](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/uschtwill/32/14077_2.png) [@uschtwill](https://discuss.elastic.co/u/uschtwill)
#### Post date: [August 23, 2017, 11:14am UTC](https://discuss.elastic.co/t/es-5-x-to-json-logging-log4j-properties-example-snippet/97566/4 "2017-08-23T11:14:52Z")

</div>

...not giving up yet!

---

<div class="post-metadata">

### Author: ![uschtwill](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/uschtwill/32/14077_2.png) [@uschtwill](https://discuss.elastic.co/u/uschtwill)
#### Post date: [August 24, 2017, 10:58am UTC](https://discuss.elastic.co/t/es-5-x-to-json-logging-log4j-properties-example-snippet/97566/5 "2017-08-24T10:58:29Z")

</div>

Surely someone else has gotten ES to log JSON? It would be bonkers, if one of the main component of the tool set that so strongly endorses structured logging, can't easily be swayed into structured logging itself. No?

---

<div class="post-metadata">

### Author: ![uschtwill](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/uschtwill/32/14077_2.png) [@uschtwill](https://discuss.elastic.co/u/uschtwill)
#### Post date: [August 29, 2017, 12:49pm UTC](https://discuss.elastic.co/t/es-5-x-to-json-logging-log4j-properties-example-snippet/97566/6 "2017-08-29T12:49:47Z")

</div>

Got it! Thanks for nothing, lads! 🙂

1. Add the following to `log4j2.properties`:

```auto
appender.json_file.type = file
appender.json_file.name = json_file
appender.json_file.fileName = ${sys:es.logs}-json.log
appender.json_file.layout.type = JSONLayout
appender.json_file.layout.compact = true
appender.json_file.layout.eventEol = true
rootLogger.appenderRef.json_file.ref = json_file

```

1. Add the following to `$JAVA_HOME/lib/security/java.policy`:

```auto
grant {
  permission java.lang.RuntimePermission "accessDeclaredMembers";
  permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
};

```

1. Download [http://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.8.1/jackson-annotations-2.8.1.jar](http://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.8.1/jackson-annotations-2.8.1.jar) and [http://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.8.1/jackson-databind-2.8.1.jar](http://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.8.1/jackson-databind-2.8.1.jar) to `/usr/share/elasticsearch/lib`.

Sources:

- [https://github.com/elastic/elasticsearch/issues/22103](https://github.com/elastic/elasticsearch/issues/22103)
- [http://docs.oracle.com/javase/7/docs/technotes/guides/security/PolicyFiles.html](http://docs.oracle.com/javase/7/docs/technotes/guides/security/PolicyFiles.html)

---

<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: [September 26, 2017, 12:49pm UTC](https://discuss.elastic.co/t/es-5-x-to-json-logging-log4j-properties-example-snippet/97566/7 "2017-09-26T12:49:56Z")

</div>

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