Skip to main content

Integration & IT Modernization

Generating Log Entries in Mule Java Component

Successful Marketing Cloud Implementation

This is another journal post so I don’t have to re-learn the same thing many times over in the future.

There are different options if you need to use log file to debug Java component with Mule application.

The laziest way is to use System.out.println() inside your Java code. If you do that, you just need to remember the STDOUT from system.out.println() will not show up in your application log file. Instead, if you run the application inside Anypoint studio, the output will scroll through the “console” window. If you deploy the application on Mule server, the System.out.println() will output to logs/mule_ee.log file for on-prem server. I didn’t test Cloudhub, I suppose it will go to system.log.

This is a no-thrills method to implement, but you have to check two log files: the application log file for the standard Mule logger output and mule_ee.log for system.out.println() from your java component.

The next choice is to use log4j framework. Suppose your Java class is “Foo”, then this is what you need to do to send log entries to the application log file:

import org.apache.log4j.Logger;
public class Foo {
private static Logger log = Logger.getLogger(Foo.class);
void testCall() {
log.info(“this is my logging entry”);
}

the advantage is the output goes to the same application log file. You don’t have to search two log files. It does take some extra coding.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow Us
TwitterLinkedinFacebookYoutubeInstagram