Monitoring is a process that detects, diagnoses, remedies and reports an application's performance and availability to ensure that it meets user expectations. Magnolia provides built-in tools for logging and debugging application behavior. It also supports Java Management Extensions (JMX), a Java technology for managing and monitoring. These mechanisms provide developers, administrators and especially the support team detailed context for application failures.
Magnolia uses Apache log4j, a Java-based logging utility. It logs events in Magnolia core code as well as any modules that support logging. Log4j is configured in three places:
- log4j.xml file is permanent configuration. This XML file resides in the
/<CATALINA_HOME>/webapps/<contextPath>/WEB-INF/config/defaultdirectory. Any configuration changes you make in this file persist through instance restarts. Conversely, you need to restart Magnolia for any changes to take effect. You should configure long-time, persistent logging here, such as sending an email notification to your own support team when errors occur in a critical component. In the XML file you can also choose whether you wish to log a single Java class or the whole package.
- Tools > Logging menu in AdminCentral is for transient configuration. Any changes you make here are active immediately but they are only valid until the next restart. When the instance is restarted, your changes revert back to default settings. This tool is useful for ad hoc debugging of production issues since you don't need to restart Magnolia to turn it on.
- Configuration >
/server/auditLoggingis for audit logging. Audit logging means tracking user activity in the system such as who signed in and what they did. Here you select the actions you want to audit such as login, create, activate and so on.
Turning on log4j's own debugging
If you are configuring log4j for the first time, add the
debug=true attribute in the
This will print out attributes and their values from the XML configuration file into the console at startup. This makes it easier to catch errors resulting from typos.
Categories (loggers in log4j terminology) define what data is logged and how much detail is provided. Think of categories as the classes and packages you want to log.
Here's an example from the default log4j.xml configuration file.
Elements and their attributes are:
namedefines the class or package to log. Type the fully-qualified Java class or package name here.
additivitysets appender additivity. If you set its value to
true, output from the category is directed to any appenders referenced in the category itself and any appenders defined in its ancestors following the dot notation in the
nameattribute. If you set the value to
false, output is directed only to appenders referenced in the category itself, not to ancestors. In the default configuration, typical ancestors are
info.magnolia(following up the dot notation) and
rootat the bottom of the XML file. All categories inherit their settings from
valueis the logging priority level such as INFO or DEBUG.
refis the name of an appender configuration in the same file.
Class or package
The choice between logging a single class or the whole package depends on whether the issue is limited to a single class. An action such as content activation is spread out over a few different classes. Logging only one of them may not provide enough information.
Example: Suppose you have an issue with content activation. Logging the
info.magnolia.module.exchangesimple.BaseSyndicatorImpl class will tell you almost everything that happens when content is activated in the Community Edition since it is responsible for activating content to a subscriber. However, if you want to capture events from all related classes, set the category name to the package
- To log a specific class, use the fully-qualified class name as the category name.
- To log a whole package, use the fully-qualified package name as the category name.
Magnolia uses the standard log4j levels.
The highest possible rank and is intended to turn off logging.
Severe errors that cause premature termination. Visible in console.
Other runtime errors or unexpected conditions. Visible in console.
Use of deprecated APIs, poor use of API, "almost" errors, other runtime situations that are undesirable or unexpected, but not necessarily "wrong". Visible in console.
Interesting runtime events (startup/shutdown). Visible in console, so be conservative and keep to a minimum.
Detailed information on the flow through the system. Written to logs only.
More detailed information. Written to logs only.
Appenders define where the output is directed. The following appenders are configured by default in
log4j.xml. They write messages to the console and to various log files.
Default output for DEBUG messages
Default output for DEBUG messages.
Default output for ERROR messages.
Content activation process.
Disabled by default.
log-activation appender is used to log events related to content activation.
It is actually two appenders:
log-activation appender uses the
AsyncAppender class to queue up the messages while the referenced
sync-log-activation appender does the actually writing of the messages to the
All appenders that write to a log file use the
RollingFileAppender class. Rolling means that the system takes a backup of the log file when its size reaches a limit set in the
MaxFileSize parameter, 1 MB by default. The old file is date-stamped and a new file is started in the same directory.
Example: Debugging content activation
This example shows how to log more detail about content activation action. It is useful when activation fails and the default INFO messages do not provide enough information to pinpoint the root cause.
Content activation is spread out into three different packages:
info.magnolia.cms.exchangeprovides some basic support objects for activation.
info.magnolia.module.activationpackage is the Community Edition simple activation feature.
info.magnolia.module.exchangetransactionalis the Enterprise Edition .
Add the categories to Log4j.xml if not already there:
Each category references the
log-activation appender which sends output to the
magnolia-activation.log file. Since
true, output is also sent to ancestor appenders, in this case the console.
Priority is set at INFO level by default. If more information is needed, this is the detail that needs to be changed.
To change the level to DEBUG:
- Stop the Magnolia instance.
priorityin the three categories to DEBUG.
- Save the file.
- Start Magnolia.
To test the new configuration, activate some content and view the logged DEBUG messages in the
Note that by default there is a temp folder called
tmp configured in
magnolia.properties in the actual webapp. This folder contains various
exchange_*.xml.gz files that are stored when debugging is enabled for activation. The location of the files is specified by the
Logging tool - transient configuration
The Logging Tool allows you to configure logging for all key Magnolia classes, as well as Apache, Ehcache and Jackrabbit classes. This configuration is transient: it only persists until the next instance restart.
This tool does not have its own app in Magnolia 5 yet. You can access it at
If you know or suspect that a particular class, group of classes or module is causing your issue, change the logging level on that class to DEBUG.
- Go to Tools > Logging
- Find the class in the list.
- Select DEBUG from the drop-down list.
- Click Set.
- Reproduce the error.
Set all changed classes back to their original detail level (typically INFO) once you have finished debugging. They will reset anyway the next time you start Magnolia.
View the recorded messages in the log file:
- Go to Tools > Log Viewer
magnolia-debug.logfrom the dropdown.
- Click View.
Newest entries are at the end of the file. Click >> to go to the end. When the detail level is set to DEBUG, a line starting with the word DEBUG is written each time the class is called.
With the exception of DEBUG and OFF, logged events are also displayed in the console. Console is the terminal window where you issued the Magnolia start command. Keep an eye on the console as you reproduce an error.
To download the log file:
- Go to Tools > Log Viewer
- Select magnolia-debug.log from the dropdown.
- Click Download.
- Edit the file to include only the relevant lines where the error occurs.
Example: Logging mail errors
documentation has an example of error resolution using the logging tool.
Capturing request and response headers
Request and response headers are information passed between a browser and a web server. Headers consist of fields that define the operating parameters of the HTTP transaction. Capturing the headers tells you what records are passed and provides a clue for troubleshooting.
The request header contains details of what the browser wants and what it will accept back from the server. It also contains the type, version and capabilities of the browser so that the server returns compatible data.
Example: Request header
The response header contains the date, size and type of file that the server is sending back to the client and data about the server itself. The header is attached to the files being sent back to the client.
Example: Response header
To capture the headers, you can use a browser extension or plugin that displays headers for the currently open page. A plugin's advantage over a header-sniffing website is that you can also use it for sites that only exist in your local environment or intranet.
- Safari: Developer Tools
- Firefox: Web Developer or Live HTTP Headers add-on
- Chrome: Developer Tools
- Internet Explorer: Fiddler
To view headers in Developer Tools:
- Open Developer Tools.
- Go to Network.
- Reload the page.
- Select the page in the list.
- Go to Headers tab.
Command line tools
Any Unix-like system likely has these command line tools already installed.
Rich client applications:
A header-sniffing website can report headers for a site that resides on the public Internet. These tools do not work for a site that exists only in your local environment.
You can observe Java Virtual Machine and application server performance through Java Management Extensions (JMX). JMX is Java technology used for managing and monitoring applications and system objects. Objects are represented as management beans (MBean). JMX is supported by many Java application servers such as Apache Tomcat, JBoss AS, IBM WebSphere and Oracle WebLogic.
Java Monitoring and Management Console (JConsole) is a graphical tool that supports JMX monitoring and management on a local or remote machine. It draws graphs for visual representation of performance and resource consumption, which makes it easier to observe changes over time. As a downside, the results are not as easy to export as with Jmxterm.
- Start JConsole:
- Connect to a process:
- Local: Select a Java process running on the local machine. Magnolia running on Tomcat would be listed as
- Remote: Type a remote process location as
- Local: Select a Java process running on the local machine. Magnolia running on Tomcat would be listed as
- Click Connect
See Using JConsole for instructions on how to view and interpret the charts.
Saving Chart Data
To save data from a JConsole chart in CSV format:
- Right-click the chart and select Save data as...
- Specify a file to save.
The CSV file can be imported into a spreadsheet to re-create the chart.
Example: Flushing the cache in JConsole
JMX is not only used to observe events. You can also invoke operations. In this example the server cache is flushed on the public instance using JConsole:
- Open JConsole and connect to the Magnolia process.
- Go to the MBeans tab.
- Expand Magnolia > Cachemonitor > magnoliaPublic > Operations. This is a list of invokable operations provided by the CacheMonitor MBean.
- Click flushAll to invoke the flush operation.
Jmxterm is a command line JMX tool. Unlike JConsole, it does not have a graphical user interface. However, its big advantage is that Magnolia Support can give you a script that you can paste into your Jmxterm and run it. You can also write the Jmxterm output to a file and attach it to a support ticket. This makes it easier to collect and analyze specific data. Jmxterm is good for point-in-time observation whereas JConsole is better for visualizing events over a longer period.
Example: Flushing the cache in Jmxterm
jvms command tells you what Java processes are running on the machine.
Open the connection to the Catalina JVM using the process ID.
domains command lists the domains available in the Java process.
Set the domain to
beans command provides a list of MBeans in the domain. Here are the beans in the Magnolia domain.
We need the
CacheMonitor bean for the public instance.
info tells you what a bean does. The
CacheMonitor bean provides several attributes and operations.
flushAll operation to flush the cache.
This particular operation does not return any value, just
Let's see how many times the cache has been flushed by checking the
Flushes attribute with the
Three times, it seems.
Example: Running a Jmxterm script
Jmxterm can read a script file with the
-i <input script> command line option.
Save the following script as
<JVM process ID> with the ID of the Java Virtual Machine that is executing the Magnolia application. You can find it with
ps | grep jvm.
Execute the script with:
-nsets Jmxterm to non-interactive mode.
-i <input script>reads the script.
-o <output file>writes the output to a file.
You should get results like this in the output file: