Configure Rollingfile loggers in log4j2.properties

Below is how we can enable RollingFile loggers in log4j2

## Default Appender ##
appender.rolling.type=RollingFile
appender.rolling.name=IIQRFile
appender.rolling.fileName=C:/SailpointLogs/sailpoint.log
appender.rolling.filePattern=C:/SailpointLogs/sailpoint-%d{yyyy-MM-dd}-%i.log.gz
appender.rolling.layout.type=PatternLayout
## OOTB pattern is '%d{ISO8601} %5p %t %c{4}:%L - %m%n' ##
appender.rolling.layout.pattern=%d{DEFAULT} %5p %t %c{4}:%L - %m%n
appender.rolling.policies.type=Policies
appender.rolling.policies.size.type=SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=200MB
appender.rolling.strategy.type=DefaultRolloverStrategy
appender.rolling.strategy.max=15

## Same as Default Appender, we will use this appender in case where we need the logs generated sperately from the default loggger appender IIQRFile ##
appender.specificFile.type=RollingFile
appender.specificFile.name=IIQSpecificFile
appender.specificFile.fileName=C:/SailpointLogs/Specific/specific.log
appender.specificFile.filePattern=C:/SailpointLogs/Specific/specific-%d{yyyy-MM-dd}-%i.log.gz
appender.specificFile.layout.type=PatternLayout
appender.specificFile.layout.pattern=%d{DEFAULT} %5p %t %c{4}:%L - %m%n
appender.specificFile.policies.type=Policies
appender.specificFile.policies.size.type=SizeBasedTriggeringPolicy
appender.specificFile.policies.size.size=200MB
appender.specificFile.strategy.type=DefaultRolloverStrategy
appender.specificFile.strategy.max=15

## Sailpoint Console Appender same as default, this will be used to log console ##
appender.consoleFile.type=RollingFile
appender.consoleFile.name=IIQConsoleFile
appender.consoleFile.fileName=C:/SailpointLogs/SailpointConsole/console.log.gz
appender.consoleFile.filePattern=C:/SailpointLogs/SailpointConsole/console-%d{yyyy-MM-dd}-%i.log
appender.consoleFile.layout.type=PatternLayout
appender.consoleFile.layout.pattern=%d{DEFAULT} %5p %t %c{4}:%L - %m%n
appender.consoleFile.policies.type=Policies
appender.consoleFile.policies.size.type=SizeBasedTriggeringPolicy
appender.consoleFile.policies.size.size=200MB
appender.consoleFile.strategy.type=DefaultRolloverStrategy
appender.consoleFile.strategy.max=15

Below appender can be added if we need to have a separate logger that will only logs error

## Error Only Appender ##
appender.error.type=RollingFile
appender.error.name=IIQErrorFile
appender.error.fileName=C:/SailpointLogs/Error/error.log
appender.error.filePattern=C:/SailpointLogs/Error/error-%d{yyyy-MM-dd}-%i.log
appender.error.layout.type=PatternLayout
appender.error.layout.pattern=%d{DEFAULT} %5p %t %c{4}:%L - %m%n
appender.error.policies.type=Policies
appender.error.policies.size.type=SizeBasedTriggeringPolicy
appender.error.policies.size.size=200MB
appender.error.strategy.type=DefaultRolloverStrategy
appender.error.strategy.max=15
appender.error.filter.threshold.type=LevelRangeFilter
appender.error.filter.threshold.minLevel=error
appender.error.filter.threshold.maxLevel=error

Now after listing all the appenders, below is how you have to add the entries in the rootLogger to work with all your appenders

#######################################
## rootLogger specify all appender rollings used by your log4j2
#######################################

rootLogger.level=warn
## Only appenderRef that has been used in log4j2, Here we are using all that are part of this example ##
rootLogger.appenderRefs=IIQRFile,IIQErrorFile,IIQSpecificFile,IIQConsoleFile
rootLogger.appenderRef.stdout.ref=stdout

## Specify the default appenderRef and error appenderRef to automate logging ##
rootLogger.appenderRef.rolling.ref=IIQRFile

## To log errors by default ##
rootLogger.appenderRef.error.ref=IIQErrorFile

Below is how we will enable IIQ console logger in IIQConsoleFile appender

#######################################
## SailPoint Console loggers iiq.bat console
#######################################

logger.spConsole.name=sailpoint.server.SailPointConsole
logger.spConsole.level=all
## remove the below 2 lines if you want to log in default IIQRFile appender ##
logger.spConsole.additivity=false
logger.spConsole.appenderRef.connector.ref=IIQConsoleFile

Below is how you will log to your default appender IIQRFile

logger.orgSpringframework.name=org.springframework
logger.orgSpringframework.level=info

Below is how you can log to your appender IIQSpecificFile in special cases

logger.ObjectConfig.name=sailpoint.object.ObjectConfig
logger.ObjectConfig.level=trace
logger.ObjectConfig.additivity=false
logger.ObjectConfig.appenderRef.connector.ref=IIQSpecificFile

Disable Heartbeat logger

## Disable Heartbeat logger ##
logger.heartbeat.name=sailpoint.server.HeartbeatService
logger.heartbeat.level=off
1 Like