Liferay's Logging System
Liferay uses Log4j extensively to implement logging for nearly every class in the portal. If you need to debug something specific while a system is running, you can use the Control Panel to set logging levels by class dynamically.
To view the log levels, go to the Control Panel, click Server Administration in the Server section, and then click the Log Levels tab.
You will then see a paginated list of logging categories. These categories correspond to Liferay classes that have log messages in them. By default, all categories are set to display messages only if there is an error that occurs in the class. This is why you see ERROR displayed in all of the drop down list boxes on the right side of the portlet.
Each category is filtered by its place in the class hierarchy. For example, if you wanted to see logging for a specific class that is registered in Liferay, you would browse to that specific class and change its log level to something that is more descriptive, such as DEBUG. Once you click the Save button at the bottom of the list, you will start seeing DEBUG messages from that class in your application server's log file.
If you are not sure which class you want to see log messages for, you can find a place higher up in the hierarchy and select the package name instead of an individual class name. If you do this, messages for every class lower in the hierarchy will be displayed in your application server's log file.
Illustration 89: Changing Logging LevelsBe careful when you do this. If you set the log level to DEBUG somewhere near the top of the hierarchy (such as com.liferay, for example), you may wind up with a lot of messages in your log file. This could make it difficult to find the one you were looking for, and causes the server to do more work writing messages to its log file.
If you are working in the extension environment or have created a plugin and want to set the log level for one of your own classes, you can register that class (so long as it uses Log4J to do its logging) with Liferay so that you can control the log levels more easily.
You will first need to implement Log4J logging in your class, with a statement such as the following (taken from Liferay's JCRHook class):
private static Log _log = LogFactory.getLog(JCRHook.class);
You would then use this _log variable to create log messages in your code for the various logging levels:
_log.error("Reindexing " + node.getName(), e1);
To enable your logging messages to appear in your server's log file via the Control Panel, click the Add Category tab on the same Log Levels page.
Illustration 90: Adding a Logging CategoryYou will see that you can add a logging category. Simply put in the fully qualified name of your class or of the package that contains the classes whose log messages you want to view, choose a log level, and then click the Save button. You will now start to see log messages from your own class or classes in the server's log file.