How to log to catalina.out from a javascript Listener

Hello all

I’m trying to print to catalina.out from a javascript Listener, but fail to figure out how to achieve that.
I’m using v7.9 CE with the embedded Tomcat server.

Can this be done?
Thanks so much

Hi @eugene,

Do you already know how you would do that from Java code?

Cheers,
Thorben

Hello @thorben

I spent many hours trying to figure out the correct syntax for println().
I hope this will help someone else from having to do the same.
During my searching I also came across the following methods:

1 print(“Hello”);
2 java.lang.System.out.println(‘Hello’); //must be ’ and not "
3 var logger = java.util.logging.Logger;
var log = logger.getLogger(‘MY_JS_LOGGER’);
log.info(‘Hello’);

Option 3 is not causing an error but nothing appears in catalina.out either.

Thanks for your response.

Did you try with the proper nashorn syntax for accessing java classes ? https://wiki.openjdk.java.net/display/Nashorn/Nashorn+extensions

Thanks @StephenOTT

As always, your assistance is much appreciated.

Also note that Js is not cached in Camunda executions. So there will be extra overhead if you go with your option 3. If you really need it, I would look at something like creating a engine plugin that generates a static logger for you to access rather than generating new loggers every execution of a script. Again only if you are using option 3.

For option 2 you can see a example here: https://docs.camunda.org/manual/7.9/user-guide/process-engine/scripting/#printing-to-console-using-scripts

1 Like