Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Anchor
top1
top1
Log4j Purging



Info
titleThis Page is under construction
Tip

Find all the steps for Log4j Insights Engine Log Purging


Expand
titlePrerequisite
  • Java
  • Eclipse latest version
Expand
titleSteps For SetupSteps For Setup


Info
titleWith the recommended below settings, maximum of 5 log backup files of 5 MB size each will be maintained


Step 1:

  • Add log4j dependency in pom.xmlUpdate the below highlighted lines in log4j.properties file
Panel
borderColorgreen
bgColorwhite
titleColorgreen
borderWidth2
borderStylesolid
titlelog4j dependency

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>

Step 2:

  • Basic program to store content in log file

package com.cognizant.devops.Log4jProject;

import
Panel
borderColorgreen
bgColorwhite
titleColorgreen
borderWidth2
borderStylesolid
titleProgram
configuration

# Root logger option

log4j.rootLogger=ERROR, stdout, file 

# Redirect log messages to a log file, support file rolling.

log4j.appender.file=org.apache.log4j.BasicConfigurator;RollingFileAppenderimport org

log4j.apacheappender.log4j.Logger;

 

public class Log4jHelloWorld {

 

    static final Logger logger = Logger.getLogger(Log4jHelloWorld.class);

 

    public static void main(String[] args)

    {

        //Configure logger

   

        BasicConfigurator.configure();

        for(int i=0;i<20000;i++)

        {

        System.out.println("Hello World!"+i);

        logger.info("Hello World!"+i);

        

        }

    }

}

Step 3:

Create log4j.properties file in src/main/resources

Add the build path points to src/main/resources

file.File=${sys:INSIGHTS_HOME}logs/PlatformEngine/log4j.log

log4j.appender.file.MaxFileSize=5MB

log4j.appender.file.MaxBackupIndex=5

log4j.appender.file.layout=org.apache.log4j.PatternLayout

log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n




Top Section