We are upgrading log4j 1.2.14
to 2.12.1
and I have the log4j2.properties
file as below
status = error
log4j2.appender.console.type = Console
log4j2.appender.console.name = LogToConsole
log4j2.appender.console.layout.type = PatternLayout
log4j2.appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
#log4j2.appender.file.type = File
#log4j2.appender.file.name = LogToFile
#log4j2.appender.file.fileName=logs/app.log
#log4j2.appender.file.layout.type=PatternLayout
#log4j2.appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
# Rotate log file
log4j2.appender.rolling.type = RollingRandomAccessFile
log4j2.appender.rolling.name = LogToRollingRandomAccessFile
log4j2.appender.rolling.fileName = ${server.home}/logs/server.log
log4j2.appender.rolling.filePattern = logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz
log4j2.appender.rolling.layout.type = PatternLayout
log4j2.appender.rolling.layout.pattern = %d %p %C{1.} [%t] %m%n
log4j2.appender.rolling.policies.type = Policies
log4j2.appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
log4j2.appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.rolling.policies.size.size=10MB
log4j2.appender.rolling.strategy.type = DefaultRolloverStrategy
log4j2.appender.rolling.strategy.max = 10
# Log to console and rolling file
#logger.app.type = AsyncLogger
log4j2.logger.app.name = com.ssl.server
log4j2.logger.app.level = info
log4j2.logger.app.additivity = false
log4j2.logger.app.appenderRef.rolling.ref = LogToRollingRandomAccessFile
log4j2.logger.app.appenderRef.console.ref = LogToConsole
log4j2.rootLogger.level = info
log4j2.rootLogger.appenderRef.stdout.ref = LogToConsole
I have below dependancies in my pom.xml
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.12.1</version>
</dependency>
I am initializing the logger as below
private static final org.apache.logging.log4j.Logger LOG = org.apache.logging.log4j.LogManager.getLogger(SSLServer.class.getName());
When I start the standalone Java application using the main()
am getting below error and server.log
file is not created, I did some research regarding the below error and most of the articles were referring to log4j2.xml
configuration and none of the config changes worked in my log4j2.properties
log warn: org.apache.logging.log4j.status.StatusLogger - No Root logger was configured, creating default ERROR-level Root logger with Console appender
No Root logger was configured, creating default ERROR-level Root logger with Console appender
getClass().getClassLoader().getResource("conf/log4j2.properties").getFile()
? – Boxerlog4j
doc I see that by default it will look forlog4j-test.properties
iflog4j.configurationFile
is not provided, can you please check mylog4j2.properties
and see why its not creating the log file – Forayerlog4j2.properties
file has priority over thelog4j2.xml
so, could you add your project structure to the post? Maybe a screenshot. – Boxer