Search code examples
log4jignitegridgain

Ignite Log4j not creating logs as ignite.log


Configured Ignite Log4J module and logs are getting generated as ignite-uniqueid.log for each and every time. My requirement is to get the logs with single ignite.log only.


Solution

  • Please, take a look at a similar question.

    I found it useful to replace the Ignite's Log4jRollingFileAppender with the default RollingFileAppender that doesn't modify a destination filename.

    More details:

    Change Ignite configuration file:

    ...
        <property name="gridLogger">
           <bean class="org.apache.ignite.logger.log4j.Log4JLogger">
              <constructor-arg type="java.lang.String" value="config/ignite-logging-log4j.xml"/>
           </bean>
        </property>
    ...
    

    Made the following changes inside the ignite-logging-log4j.xml file settings. You can use the default one from the Ignite distribution zip as a placeholder. Change the FILE appender to this:

     <!--<appender name="FILE" class="org.apache.ignite.logger.log4j.Log4jRollingFileAppender">-->
        <appender name="FILE" class="org.apache.log4j.RollingFileAppender">
            <param name="Threshold" value="DEBUG"/>
            <param name="File" value="C:/Ignite/log/MyIgnite.log"/>
            <param name="Append" value="true"/>
            <param name="MaxFileSize" value="1KB"/>
            <param name="MaxBackupIndex" value="10"/>
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="[%d{ISO8601}][%-5p][%t][%c{1}] %m%n"/>
            </layout>
        </appender>
    

    Start Ignite instance.

    public static void main(String[] args){
        Ignition.start("config/<your-ignite-config-filename>.xml");
    }
    

    After that, you should observe a bunch of ~1KB log files within your directory:

    -rw-r--r-- 1  177 May  1 01:15 MyIgnite.log
    -rw-r--r-- 1 1512 May  1 01:15 MyIgnite.log.1
    -rw-r--r-- 1 1050 May  1 01:15 MyIgnite.log.10
    -rw-r--r-- 1 1146 May  1 01:15 MyIgnite.log.2
    -rw-r--r-- 1 1402 May  1 01:15 MyIgnite.log.3