How to use logger in script file?

ive tried using logger object. the script code is :
> import org.elasticsearch.common.logging.*;
> // ESLogger el;
>ESLogger logger=ESLoggerFactory.getLogger('test_logger');
//'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?


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


script.groovy.file.receiver_whitelist : org.elasticsearch.common.logging.ESLoggerFactory,org.elasticsearch.common.logging.ESLogger,java.lang.Object

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'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

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

you get it