Search code examples
javalog4jlog4j2properties-filetomcat9

Not Every log is printing in Log files using LOG4j2 Properties file


I have configured my webapp in java using log4j2 for logs using properties file.

When I am starting tomcat ,there are so many logs printing in console but in my file only few lines are printing.

What should I do in order to print every line which is present in console to my Log File.

Recently I have migrated from log 1.x to log 2.16

When I am using log1.x everything is printed in log files which are in console but in log2 its not printing.

For Example when I am staring tomcat ,I am getting only my app related logs in the file but not anything related to tomcat startup logs or any other jar related logs

Can anyone help me on this

below is my config file

log4j2 properties:

status = all



appender.console.type = Console
appender.console.name = LogToConsole
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n



#appender.file.type = File
#appender.file.name = LogToFile
#appender.file.fileName=logs/app.log
#appender.file.layout.type=PatternLayout
#appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n



# Rotate log file
appender.rolling.type = RollingFile
appender.rolling.name = LogToRollingFile
appender.rolling.fileName = ${catalina.home}/logs/SunnyLogs.log
appender.rolling.filePattern = ${catalina.home}/logs/$${date:yyyy-MM}/SunnyLogs-%d{MM-dd-yyyy}-%i.log.gz
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d %p %C{1.} [%t] %m%n
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=10MB
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.max = 10



# Log to console and rolling file
logger.app.name = com.sunny.common
logger.app.level = all
logger.app.additivity = false
logger.app.appenderRef.rolling.ref = LogToRollingFile
logger.app.appenderRef.console.ref = LogToConsole



rootLogger.level = all
rootLogger.appenderRef.stdout.ref = LogToConsole

Solution

  • After deep Research I have found one Jar as my solution

    Log4j-jcl-2.16 jar.

    After adding this to my build path I am getting all Logs printed in my file