# Logging embedded elasticsearch logs to file with log4j2

**URL:** <https://discuss.elastic.co/t/logging-embedded-elasticsearch-logs-to-file-with-log4j2/53966>\
**Category:** Elasticsearch\
**Created:** [June 26, 2016, 2:35pm UTC](https://discuss.elastic.co/t/logging-embedded-elasticsearch-logs-to-file-with-log4j2/53966 "2016-06-26T14:35:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rajind\_Ruparathna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rajind_ruparathna/32/10545_2.png) [@Rajind\_Ruparathna](https://discuss.elastic.co/u/Rajind_Ruparathna)\
**Post date:** [June 26, 2016, 2:35pm UTC](https://discuss.elastic.co/t/logging-embedded-elasticsearch-logs-to-file-with-log4j2/53966/1 "2016-06-26T14:35:02Z")

</div>

Hi, I'm using elasticsearch 2.3 embedded in my Java program and I want to log generate logs similar to how the standalone elasticsearch does logging. Can you please point me in the right direction ?

I've tried this so far.

Settings elasticsearchSettings = Settings.settingsBuilder()  
.put("path.conf", "elasticsearch/conf")  
.put("[node.name](http://node.name)", "chin chao")  
.put("path.home", "elasticsearch")  
.put("path.data", "elasticsearch/data")  
.put("path.logs", "elasticsearch/logs")  
.put("[cluster.name](http://cluster.name)", "elasticsearch")  
.build();

LogConfigurator.configure(elasticsearchSettings, true);

But I am getting following error since I am using log4j2 in my program.

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.  
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/PropertyConfigurator

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [June 26, 2016, 2:48pm UTC](https://discuss.elastic.co/t/logging-embedded-elasticsearch-logs-to-file-with-log4j2/53966/2 "2016-06-26T14:48:22Z")

</div>

This is not supported. Running embedded in general isn't supported.

It might work if you bridge log4j1 to log4j2 but since this isn't a thing  
we it might break unexpectedly.

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [June 26, 2016, 9:58pm UTC](https://discuss.elastic.co/t/logging-embedded-elasticsearch-logs-to-file-with-log4j2/53966/3 "2016-06-26T21:58:56Z")

</div>

First, the cause of the error `No log4j2 configuration file found` is that you do not have a `log4j2.xml` file in your class path.

Second, as Nik already commented, you need a bridge jar [https://logging.apache.org/log4j/log4j-2.6.1/log4j-1.2-api/index.html](https://logging.apache.org/log4j/log4j-2.6.1/log4j-1.2-api/index.html) so all log4j messages are redirected to log4j2

You should ignore `org.elasticsearch.common.logging.LogConfigurator`, instead, use `org.apache.logging.log4j.core.config.ConfigurationFactory` and related classes to control logging programmatically. See [https://logging.apache.org/log4j/log4j-2.6.1/manual/customconfig.html](https://logging.apache.org/log4j/log4j-2.6.1/manual/customconfig.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:** [July 5, 2017, 10:40pm UTC](https://discuss.elastic.co/t/logging-embedded-elasticsearch-logs-to-file-with-log4j2/53966/4 "2017-07-05T22:40:23Z")

</div>


