简体   繁体   中英

How to configure log4j2.properties file to create logs for specific package

Below is my project structure:

src->main->java->com->dot->filter->here are many folders (ax,by,cz) which contain the classes

src->main->java->resources->log4j2.properties

Below is my log4j2.properties file:

status = error
name = PropertiesConfig
 
property.filename = C:\\logs\\debug.log
 
filters = threshold
filter.threshold.type = ThresholdFilter
filter.threshold.level = debug
 
appenders = rolling
appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
appender.rolling.fileName = ${filename}
appender.rolling.filePattern = C:\\logs\\PreviousLogs\\-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 1
appender.rolling.policies.time.modulate = true
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=10MB
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.max = 20
 
loggers = rolling
  
logger.rolling.name = com.dite.filter.ax

logger.rolling.level = debug
logger.rolling.additivity = true
logger.rolling.appenderRef.rolling.ref = RollingFile

for the above configuration I couldn't generate the logs

is there anything wrong in this line logger.rolling.name = com.dite.filter.ax ?

could any one please tell me what mistake I have done in this configuration?

or

suggest me other way to generate logs for above specified package structure

You configuration of the com.dite.filter.ax logger is correct, but you didn't configure the root logger.

If you want to ignore all log messages that do not come from com.dite.filter.ax and its descendants use:

rootLogger.level = OFF

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM