2 Minutes To Code (β Version)

Log4j - 2 minute tutorial

How to make log files rotate based on size and zip old rotated logs using log4j.properties

		#Worked with 2.17 version
		log4j.rootLogger=INFO, loggerId
		log4j.appender.loggerId=org.apache.log4j.rolling.RollingFileAppender
		log4j.appender.loggerId.rollingPolicy=org.apache.log4j.rolling.FixedWindowRollingPolicy
		log4j.appender.loggerId.rollingPolicy.maxIndex=5
		log4j.appender.loggerId.triggeringPolicy=org.apache.log4j.rolling.SizeBasedTriggeringPolicy
		log4j.appender.loggerId.triggeringPolicy.MaxFileSize=10000000
		log4j.appender.loggerId.rollingPolicy.FileNamePattern=worker-%i.log.gz
		log4j.appender.loggerId.rollingPolicy.ActiveFileName=worker.log
		log4j.appender.loggerId.layout=org.apache.log4j.PatternLayout
		log4j.appender.loggerId.layout.ConversionPattern=%d [%t] %-5p (%F:%L) - %m%n