Mule and its logs

Mule applications produce a (sometimes) lengthy log output that is displayed on the console and saved to the Mule log file.  This can be tweaked to show more, or less, output but you may sometimes need to see all the log entries (or need to not see them).

Mule uses Log4j for its logging purposes. All logging features are configured using the standard log4j.properties text file that should be placed in the same directory as your Mule application. There is a log4j.properties file under MULE_HOME\conf.

The first line in this file allows you control what level of logs you wish to see, for example:

log4j.rootCategory=INFO,stdout

This line specifies that informational messages should be displayed on the console.  Actually, informational messages and any messages considered to be of a higher category are listed.  The categories are as follows:

1 – FATAL refers to critical events that will lead to Mule terminating completely.
2 – ERROR refers to any sort of exception, even non-FATAL ones.
3 – WARN refers to warnings; not exceptions but situations that could be harmful.
4 – INFO refers to information that shows how Mule operates and its ongoing progress. It is a rather rough look at the application’s progress but helps you see what’s going on.
5 – DEBUG is the most detailed level of logging and shows all events that have occurred. This is the most useful manner in which to debug the sequence of events in an application.

Given this list, you can set your logging category to INFO which will include anything that would have been caught by the WARN, ERROR and FATAL categories.

The second parameter shown in the example above is “stdout” and instructs log4j to post all these messages on to the standard output device.  You can add “file” to save these items into the Mule log file:

log4j.rootCategory=INFO,stdout, file

or you can remove “stdout” so that all INFO messages will be placed in the file but not shown on screen:

log4j.rootCategory=INFO,file

Logs are displayed on screen (or saved into a file) based upon the behaviour encoded in log4j appender classes. The next two sections in a log4j.properties file define these classes and their properties. This example shows how log4j is being configured to store logs in a file called mule.log that should have a maximum size of 10MB:

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=mule.log
log4j.appender.file.MaxFileSize=10MB

The class used is called org.apache.log4j.RollingFileAppender which backs up log files once they reach a certain size.

Rather usefully, you can also configure log4j to use specific log categories for particular classes but not for the whole Mule application:

log4j.rootCategory=FATAL,stdout
log4j.logger.org.mule.model=DEBUG

This example shows how only FATAL log messages should be displayed on screen; but any DEBUG messages generated by any class in the org.mule.model.* package (or packages) will also be displayed.  It is a great mechanism to display detailed messages for the classes that are causing problems while debugging for instance.

If you enjoyed this post, make sure you subscribe to our RSS feed!
This entry was posted in Mule and tagged , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

7 Responses to Mule and its logs

  1. Pingback: Using Mule's ExceptionBasedRouter | blog.ricston.com

  2. Sandy says:

    Running from console is fine.But whenever I started Mule within Eclipse, it will display the log in the console of IDE,not in log file.I want to store the log from component(Spring beans) into log file.But I am not able to do that using this approach.

    Can you tell how can I resolve that issue.
    Thanks in advance
    Sandy

  3. Antoine Borg says:

    Hello Sandy,

    Presumably you do have a log4j.properties file for your project. If you don’t then this explains why Eclipse does whatever it thinks best. If you do, it would be interesting to see how it’s configured to verify that it is going to send everything to the console.

    Have you tried raising this suggestion on the Mule user-list?

    Thanks for reading

    Antoine

  4. Aron says:

    I got a problem that is how to add “file” , like file.txt or?
    and also, which path should i put ?

  5. Hi Aron, not sure I am understanding what you are asking. All of this configuration is technically configuration of log4j, so looking at the log4j documentation should give you all you need. If you have further questions feel free to ask here again.

  6. Dennis says:

    I am having a problem with Studio 3.5 (Windows 7) reading log4j properties from a delivered .jar file rather than using any file configured in the project in Eclipse. The issue is posted on the Mulesoft forum, but no response yet. Other comments I have seen indicate that log4j.properties should be in src/main/app. However, this folder does not show up in Studio, even though it does exist. When I tried to put the file into that folder from Windows Explorer, it gets overwritten when I start the app.

    I have been searching, and found issue STUDIO-681 that seems to be the same problem was resolved in Studio 3.2. Apparently it’s back. Any suggestion on how I can get Mule to quit using the properties from the .jar file?

    In the forum I found the suggestion to put the path to the file as an argument in the Run configuration. When I tried that, I received the following exception: Exception in thread “main” org.mule.api.MuleRuntimeException: Application directory does not exist: ‘C:\_workspaces\mule\realTimeException in thread “main” org.mule.api.MuleRuntimeException: Application directory does not exist: ‘C:\_workspaces\mule\realTime\.mule\apps\-Dlog4j.configuration=C:\_workspaces\mule\realTime\hip-online\resources\config\log4j.properties’

    Do you have any suggestion on how I can get Studio to quit using the properties from the jar file?

  7. Alan Cassar says:

    Hi Dennis,

    Mule expects the log4j.properties file (when deployed in a Mule standalone) in ${app.home}/classes/log4j.properties or ${app.home}/classes/log4j.xml. In MuleStudio, you have to place it under src/main/resources/log4j.properties or src/main/resources/log4j.xml. Anything that goes in the directory src/main/resources, when packaged is placed under the ${app.home}/classes/ directory.

    I have just tested this in MuleStudio 3.5 and it works perfectly well.

Leave a Reply

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


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Add video comment