log4j2.properties example
A simple log4j2.properties
example, just for self-reference
P.S Tested with Log4j 2.11.2
src/resources/log4j2.properties
status = warn
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 = logs/app.log
appender.rolling.filePattern = logs/$${date:yyyy-MM}/app-%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.mkyong
logger.app.level = debug
logger.app.additivity = false
logger.app.appenderRef.rolling.ref = LogToRollingFile
logger.app.appenderRef.console.ref = LogToConsole
rootLogger.level = info
rootLogger.appenderRef.stdout.ref = LogToConsole
Download Source Code
$ git clone https://github.com/mkyong/java-logging.git
$ cd log4j2
$ cd log4j2
properties file doesn’t work, just creates a blank log
Hey buddy! is it working properly in your project?
It’s work, It’s actually working.
I’m using Log4j latest version
I’m Conor and I’ll check it.
If you’re using Maven I believe log4j2.properties will go into src/main/resources folder…
in console its printing but the file is not generated
hello, Could yo hhelp me please, i set mi version into properties section of my pom
<log4j2.version>2.19.0</log4j2.version>
And config the log4j2.properties, when i lounch the api it generate the app.log but the file is empty. 0Kb, ¿what could be wrong? thanks in advance
did you resolve it ? I’m facing the same issue
How do we define “app” in logger.app.name