Logging to the console in Java

7
When executing Java code I want to show some information such as attribute values. I'd rather not use System.out.println() but make the output configurable. Is there a way to do this?
asked
1 answers
8

I found my answer in the Wiki! https://world.mendix.com/display/refguide/Using+logger+and+transactions

An example is: Core.getLogNode("XMLExporter").error("Could not find or create folder: " + targetFolder.getAbsolutePath() );

Though the wiki seems to be missing some options, I noticed I can output various types of logging: critical, debug, error, info, trace, warn

The log node name will appear in the console menu if I go to advanced > console log level and I can set the various levels of logging that are shown in there.

Nice trick: instead of putting in a String as the log node name (like "XMLExporter" in the example) I can just add this.toString there, as this method is implemented for all Mendix generated Java actions and will return the class name.

answered