# How to emit console.log output when using javascript-lang for custom scripts?

**URL:** <https://discuss.elastic.co/t/how-to-emit-console-log-output-when-using-javascript-lang-for-custom-scripts/21374>\
**Category:** Elasticsearch\
**Created:** [December 23, 2014, 6:43pm UTC](https://discuss.elastic.co/t/how-to-emit-console-log-output-when-using-javascript-lang-for-custom-scripts/21374 "2014-12-23T18:43:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_Heckel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tim_heckel/32/1039_2.png) [@Tim\_Heckel](https://discuss.elastic.co/u/Tim_Heckel)\
**Post date:** [December 23, 2014, 6:43pm UTC](https://discuss.elastic.co/t/how-to-emit-console-log-output-when-using-javascript-lang-for-custom-scripts/21374/1 "2014-12-23T18:43:17Z")

</div>

Hi all -- I'd like to emit to stdout information within my custom .js  
script (located in /elasticsearch/1.4.2/config/scripts/test.js).

I've tried both console.log and print (just a guess), but neither work:

"error": "ElasticsearchIllegalArgumentException[failed to execute script];  
nested: EcmaError[ReferenceError: "console" is not defined.  
(Script2.js#19)]; "  
"error": "ElasticsearchIllegalArgumentException[failed to execute script];  
nested: EcmaError[ReferenceError: "print" is not defined.  
(Script1.js#19)]; "

Any way for me to hook into stdout to emit logging information this way?  
Thanks very much.

Tim

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/ea610adb-986c-4de2-a429-6fb03b45a640%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ea610adb-986c-4de2-a429-6fb03b45a640%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [January 16, 2015, 10:23am UTC](https://discuss.elastic.co/t/how-to-emit-console-log-output-when-using-javascript-lang-for-custom-scripts/21374/2 "2015-01-16T10:23:36Z")

</div>

Hello Tim ,

Its very much possible from groovy , by accessing the Elasticsearch logger  
instance.  
You should be able to do something similar for javascript too.  
Some good folks from Elasticsearch has given a good documentation on it  
against my issue.

_import org.elasticsearch.common.logging._; \*

\*ESLogger logger=ESLoggerFactory.getLogger('myscript'); \*

\*logger.info [http://logger.info](http://logger.info)('This is a log message'); \*

LINK - [Expose logger object in the scripts · Issue #9068 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/9068)

Thanks  
Vineeth Mohan,  
Elasticsearch consultant,  
[qbox.io](http://qbox.io) ( Elasticsearch service provider [https://qbox.io/](https://qbox.io/))

On Wed, Dec 24, 2014 at 12:13 AM, Tim Heckel [timheckel@gmail.com](mailto:timheckel@gmail.com) wrote:

> Hi all -- I'd like to emit to stdout information within my custom .js  
> script (located in /elasticsearch/1.4.2/config/scripts/test.js).
> 
> I've tried both console.log and print (just a guess), but neither work:
> 
> "error": "ElasticsearchIllegalArgumentException[failed to execute script];  
> nested: EcmaError[ReferenceError: "console" is not defined.  
> (Script2.js#19)]; "  
> "error": "ElasticsearchIllegalArgumentException[failed to execute script];  
> nested: EcmaError[ReferenceError: "print" is not defined.  
> (Script1.js#19)]; "
> 
> Any way for me to hook into stdout to emit logging information this way?  
> Thanks very much.
> 
> Tim
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/ea610adb-986c-4de2-a429-6fb03b45a640%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ea610adb-986c-4de2-a429-6fb03b45a640%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/ea610adb-986c-4de2-a429-6fb03b45a640%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/ea610adb-986c-4de2-a429-6fb03b45a640%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5mbn3ZRGpCk2Ey3bnJ-JQMXyW\_J8ObGHnL8ef3N7CG\_7Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5mbn3ZRGpCk2Ey3bnJ-JQMXyW_J8ObGHnL8ef3N7CG_7Q%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 12:38am UTC](https://discuss.elastic.co/t/how-to-emit-console-log-output-when-using-javascript-lang-for-custom-scripts/21374/3 "2017-07-06T00:38:26Z")

</div>


