Here is an example for logging details into separate files, rollout file for every month and delete logs older than 180 days:
#property settings
property.LOG_DIR = /opt/logs/app_name/
#Console appenders
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yy/MM/dd HH:mm:ss.SSS} %p %c{1}: %m%n
#root loggers
rootLogger.level = INFO
rootLogger.appenderRef.stdout.ref = STDOUT
rootLogger.appenderRefs = stdout
rootLogger.appenderRef.files.ref = Rolling
# Rolling file appender
appender.rolling.type = RollingFile
appender.rolling.name = Rolling
appender.rolling.fileName= ${LOG_DIR}/application.log
appender.rolling.filePattern= ${logFile}.%i
appender.rolling.layout.type=PatternLayout
appender.rolling.layout.pattern=%d{yy/MM/dd HH:mm:ss.SSS} %p %c{1}: %m%n
appender.rolling.policies.type=Policies
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.policies.size.size=50MB
appender.rolling.strategy.max=20
#custom logging for audit-viewer
logger.aduit.name = auditlogger
logger.aduit.level = info
logger.aduit.appenderRefs = auditRef
logger.aduit.appenderRef.auditRef.ref = AuditAppender
logger.aduit.additivity = false
# Logging audit details to dedicated file
appender.aduitfile.type = RollingFile
appender.aduitfile.fileName = ${AUDIT_FILE}
appender.aduitfile.filePattern= ${LOG_DIR}/audit.%d{yyyy-MM}.log
appender.aduitfile.name = AuditAppender
appender.aduitfile.layout.type = PatternLayout
appender.aduitfile.layout.pattern = %d{yy/MM/dd HH:mm:ss.SSS} %p %c{1}: %m%n
appender.aduitfile.policies.type = Policies
appender.aduitfile.policies.time.type =TimeBasedTriggeringPolicy
appender.aduitfile.strategy.type = DefaultRolloverStrategy
#Rollout files based on month
appender.aduitfile.policies.time.interval=1
appender.aduitfile.policies.time.modulate= true
appender.aduitfile.ImmediateFlush=true
appender.aduitfile.append=true
appender.aduitfile.strategy.action.type = Delete
appender.aduitfile.strategy.action.basepath = ${LOG_DIR}
appender.aduitfile.strategy.action.maxdepth = 1
appender.aduitfile.strategy.action.PathConditions.type = IfFileName
#This below field uses relative path from basepath
appender.aduitfile.strategy.action.PathConditions.glob = audit.*.log
appender.aduitfile.strategy.action.condition.type = IfLastModified
appender.aduitfile.strategy.action.condition.age = P180D
# Settings to quiet third party or custom logs that are too verbose
loggers = mongodb, aduit
logger.mongodb.name=org.mongodb.driver.cluster
logger.mongodb.level=ERROR
Here if you wish to have logs from some class into separate file, like auditlogger
then use it inside a class as follows:
private val logger = LogManager.getLogger("auditlogger") //dont change this appender ref
logger.info("Find me inside 'audit.log' file")