log4j loggers DevOps System Administrator Jahia 7.3

Custom logger

Question

Is it possible to define custom loggers, to log some information in a special log file?

Answer

Jahia contains log4j, there could be defined a customer appender, which could log in a custom log file like:

    <appender name="CUSTOM" class="org.apache.log4j.DailyRollingFileAppender">
        <param name="File" value="${jahia.log.dir}custom.log"/>
        <param name="Threshold" value="debug"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d: %-5p [%t] %c: %m%n"/>
        </layout>
    </appender> 

The appender above create a custom.log file in the log directory. To use this appender you have to define loggers like:

    <logger name="org.jahia.tools.groovyConsole">
        <level value="debug"/>
 <appender-ref ref="CUSTOM"/>
    </logger>

The logger above logs all output from the groovyConsole in the custom.log file