Answer the question
In order to leave comments, you need to log in
How to distribute logs to files in log4j2?
Hello. Help, please, to solve a problem. I would like log4j2 to write events with different levels to different files at the same time. For example
File all.log - all events
File info.log - events with level info Warn.log
file - events with level warn
and so on.
I would like to make a setting through a property file. However, I cannot force the framework to write to several files at once. The maximum that is obtained is one file.
name=PropertiesConfig
property.filename = logs
appenders = console, file, info
appender.console.type = Console
appender.console.name = STDOUT
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 = LOGFILE
appender.file.fileName = /tmp/all.log
appender.file.layout.type=PatternLayout
appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
appender.info.type = File
appender.info.name = INFO
appender.info.fileName = /tmp/info.log
appender.info.layout.type=PatternLayout
appender.info.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
loggers = file, info
logger.file.name = com.portal
logger.file.level = debug
logger.file.appenderRefs = file
logger.file.appenderRef.file.ref = LOGFILE
logger.info.name = com.portal
logger.info.level = all
logger.info.appenderRefs = info
logger.info.appenderRef.file.ref = INFO
rootLogger.level = debug
rootLogger.appenderRefs = stdout
rootLogger.appenderRef.stdout.ref = STDOUT
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question