简体   繁体   中英

log4j2 no entries in log file

When I run my code, the log file is produced but there are no entries. What am I doing wrong?

In java, I instantiate the logger like so:

static Logger log = LogManager.getRootLogger();

Here is my properties file:

status = error
name = PropertiesConfig
dest = C:\\Logs\\cds_import_logs\\cs_import.log
#Make sure to change log file path as per your need
property.filename = C:\\Logs\\cds_import_logs\\cs_import.log

filters = threshold

filter.threshold.type = ThresholdFilter
filter.threshold.level = all

appenders = rolling

appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
appender.rolling.fileName = ${filename}
appender.rolling.filePattern = debug-backup-%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

#Make sure to change the package structure as per your application
logger.rolling.name = com.howtodoinjava
logger.rolling.level = debug
logger.rolling.additivity = false
logger.rolling.appenderRef.rolling.ref = RollingFile

Change

static Logger log = LogManager.getRootLogger();

to

static Logger log = LogManager.getLogger(YOUR_CLASS_NAME.class.getName());

I tested it and it works.

Also, make sure that you have your correct package name (not com.howtotodoinjava) in the below line:

logger.rolling.name = com.howtodoinjava

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