Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4j2.properties set logger level to many packages

AFAIK the logger level for a package/class in log4j2 properties file should be set like below.

loggers = abc
logger.abc.name = com.abc.MyClass
logger.abc.level = INFO

So if I have 50 classes/packages to specify, does it mean I have to have 50 entries in loggers and 50 of entries for each name and level.

Is not there an alternative way to do it with one line for each logger so it can be done in 50 lines?

like image 212
Asma Zinneera Jabir Avatar asked Aug 14 '17 14:08

Asma Zinneera Jabir


2 Answers

You can specify the logging... for each package. Like this:

logger.mongodb.name = org.mongodb.driver
logger.mongodb.level = warn

logger.ehcache.name = org.ehcache.core
logger.ehcache.level = warn
like image 120
Dimitar II Avatar answered Oct 18 '22 03:10

Dimitar II


In the name you can put a package (or subpackage), you don't need to specify specific class name; unless you want specific configuration for that class obviously.

Also, you can specify default configuration for all classes that do not fall in specific configurations (rootLogger).

Look for "Configuration with Properties" section in here for more details.

like image 45
albert_nil Avatar answered Oct 18 '22 04:10

albert_nil