FreeMarker integrates with the following logging packages: SLF4J, Apache Commons Logging, Log4J, Avalon LogKit, and java.util.logging (Java 1.4 and above). By default, FreeMarker will look for the following logging packages in this order, and will automatically use the first package it finds: Log4J, Avalon, java.util.logging. However, if you call the static selectLoggerLibrary method on the freemarker.log.Logger class with appropriate parameter and before using any FreeMarker classes that log messages, you can explicitly select a logger package, or even disable the logging. See the API documentation for more details.
Prior to FreeMarker 2.4, SLF4J and Apache Commons Logging aren't searched automatically due to backward compatibility constraints, so to use one of them you must do this:
Doing this is recommended, because starting from 2.4 SLF4J will be used by default if present, otherwise Apache Commons Logging if present, otherwise Log4J if present, etc.
All log messages produced by FreeMarker are logged into the logger hierarchy whose top-level logger is named freemarker. Currently used loggers are:
|freemarker.beans||Logs messages of the Beans wrapper module.|
|freemarker.cache||Logs messages related to template loading and caching.|
|freemarker.runtime||Logs template exceptions thrown during template processing.|
|freemarker.runtime.attempt||Logs template exceptions thrown during template processing, but caught by attempt/recover directives. Enable DEBUG severity to see the exceptions.|
|freemarker.servlet||Logs messages of the FreemarkerServlet class.|
|freemarker.jsp||Logs messages of the FreeMarker JSP support.|
You can call the static selectLoggerLibrary method on the freemarker.log.Logger class and pass it a string that will be used to prefix the above mentioned logger names. This is useful if you want to have separate loggers on a per-web-application basis (assuming the application uses its own local freemarker.jar). Also, you can disable logging with Logger.selectLoggerLibrary(Logger.LIBRARY_NONE). In any case, selectLoggerLibrary must be called early, before FreeMarker could log anything, or else it will not have (consistent) effect.