# How to use logger in script file?

**URL:** <https://discuss.elastic.co/t/how-to-use-logger-in-script-file/37923>\
**Category:** Elasticsearch\
**Created:** [December 24, 2015, 9:09am UTC](https://discuss.elastic.co/t/how-to-use-logger-in-script-file/37923 "2015-12-24T09:09:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Red](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@Red](https://discuss.elastic.co/u/Red)\
**Post date:** [December 24, 2015, 9:09am UTC](https://discuss.elastic.co/t/how-to-use-logger-in-script-file/37923/1 "2015-12-24T09:09:57Z")

</div>

ive tried using logger object. the script code is :  
\> import org.elasticsearch.common.logging.\*;  
\> // ESLogger el;  
\>ESLogger logger=ESLoggerFactory.getLogger('test\_logger');  
// logger.info('SCRIPT\_LOG:::This is a log message');

and i got the error message:

> {  
> "error": "QueryParsingException[[goods\_v1] script\_score the script could not be loaded]; nested: ElasticsearchIllegalArgumentException[Unable to find on disk script test\_logger]; ",  
> "status": 400  
> }

ive had a test for the code, it seems that the error is from line:

> ESLogger logger=ESLoggerFactory.getLogger('test\_logger');

the line before it is correct when uncommited:

> ESLogger el;

so , how to use logger in script file?

---

<div class="post-metadata">

**Author:** ![Sergey\_Novikov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sergey_novikov/32/831_2.png) [@Sergey\_Novikov](https://discuss.elastic.co/u/Sergey_Novikov)\
**Post date:** [January 6, 2016, 4:26pm UTC](https://discuss.elastic.co/t/how-to-use-logger-in-script-file/37923/2 "2016-01-06T16:26:33Z")

</div>

check [https://github.com/imotov/elasticsearch-native-script-example/blob/master/src/main/java/org/elasticsearch/examples/nativescript/script/LookupScript.java#L131](https://github.com/imotov/elasticsearch-native-script-example/blob/master/src/main/java/org/elasticsearch/examples/nativescript/script/LookupScript.java#L131)

---

<div class="post-metadata">

**Author:** ![Red](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@Red](https://discuss.elastic.co/u/Red)\
**Post date:** [January 9, 2016, 12:08pm UTC](https://discuss.elastic.co/t/how-to-use-logger-in-script-file/37923/3 "2016-01-09T12:08:00Z")

</div>

ok, thank you for your help.  
it's solved by adding some configure in elasticsearch.yml file.

> script.groovy.sandbox.receiver\_whitelist : org.elasticsearch.common.logging.ESLoggerFactory,org.elasticsearch.common.logging.ESLogger,java.lang.Object

or

> script.groovy.file.receiver\_whitelist : org.elasticsearch.common.logging.ESLoggerFactory,org.elasticsearch.common.logging.ESLogger,java.lang.Object

---

<div class="post-metadata">

**Author:** ![Beda\_Bogdan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/beda_bogdan/32/9343_2.png) [@Beda\_Bogdan](https://discuss.elastic.co/u/Beda_Bogdan)\
**Post date:** [April 22, 2016, 9:09am UTC](https://discuss.elastic.co/t/how-to-use-logger-in-script-file/37923/4 "2016-04-22T09:09:01Z")

</div>

Hi! Did this actually work for you?

I put the above one by one as well as both in the elasticsearch.yml file, restarted the node - no luck (I've re-deployed the node)  
I created a .java.policy in node's root and disabled filtering. Still, didn't work  
I added the grant permissions in java.policy in JAVA Home - no luck

All these give me and error at compilation as ESLogger was not found.

Also, from what I understood from @Sergey_Novikov's answer, I was expecting to be able to use [logger.info](http://logger.info)('arg') directly from the script, as it is but it didn't work -compilation is fine but I am getting illegal argument exception when executing the script. (I think the error may be misleading and the logger is not actually available)

Any suggestion? (I am trying to use groovy)

Thank you

---

<div class="post-metadata">

**Author:** ![Beda\_Bogdan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/beda_bogdan/32/9343_2.png) [@Beda\_Bogdan](https://discuss.elastic.co/u/Beda_Bogdan)\
**Post date:** [April 22, 2016, 9:50am UTC](https://discuss.elastic.co/t/how-to-use-logger-in-script-file/37923/5 "2016-04-22T09:50:12Z")

</div>

I finally managed to get it to work by granting permissions to import org.elasticsearch.common.logging.\*; in elasticsearch/modules/lang-groovy/plugin-security.policy

---

<div class="post-metadata">

**Author:** ![Red](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@Red](https://discuss.elastic.co/u/Red)\
**Post date:** [April 22, 2016, 11:36am UTC](https://discuss.elastic.co/t/how-to-use-logger-in-script-file/37923/6 "2016-04-22T11:36:25Z")

</div>

you get it

---

<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:57pm UTC](https://discuss.elastic.co/t/how-to-use-logger-in-script-file/37923/7 "2017-07-05T22:57:01Z")

</div>


