Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are wildcards allowed in the Log4j (via Spring Boot Logging) logging.level property?

Tags:

java

logging

While I was installing a Java application that uses Log4j (via Spring Boot Logging), I was told that I could configure the logging level for all packages used in the application by including the following line in the application.properties file:

logging.level.*=ERROR

Where ERROR could be whatever logging level I wanted to use.

However, as I changed the level from one value to another, no matter what value I used, I found that log messages down to DEBUG would appear in the log.

Eventually, I found that using specific package names I could control the minimum level to be logged. That is, logging.level.org.orgname.appname=ERROR would do what I wanted.

Are the log level properties meant to to support wildcards like "*"?

like image 512
Mr. Lance E Sloan Avatar asked Dec 18 '16 02:12

Mr. Lance E Sloan


People also ask

What is logging level spring boot?

In Spring, the log level configurations can be set in the application. properties file which is processed during runtime. Spring supports 5 default log levels, ERROR , WARN , INFO , DEBUG , and TRACE , with INFO being the default log level configuration.

Which is not supported by spring boot default configuration with respect to logging?

By default, Spring Boot logs only to the console and does not write log files. If you want to write log files in addition to the console output, you need to set a logging. file or logging.

How do I enable log4j2 in Spring Boot?

In a Spring Boot application, you can specify a Log4J 2 XML configuration file as log4j2.xml or log4j2-spring.xml in the project classpath. The Spring Boot team however recommends using the -spring variant for your logging configuration.

What is Log4j level in Spring MVC?

This log4j level is opposite to ALL level. It turns off all the logging. This is very easy to use Log4J functionality inside Spring MVC applications. The following example will take you through simple steps to explain the simple integration between Log4J and Spring or Spring MVC.

How to create a Log4j application in Java?

Create log4J configuration file log4j.properties under the src folder. The final step is to create the content of all the Java files and Bean Configuration file and run the application as explained below. Here is the content of HelloWorld.java file Following is the content of the second file MainApp.java

Why do I need to keep changing Log4j 2 configurations?

Also, you will often need to keep changing Log4J 2 configurations of an application across its deployment lifecycle. For example, it is common to set the logging level to DEBUG during development, and later switch it to ERROR to avoid filling your logs with excessive debug information.


1 Answers

Since my question seems unpopular, but I've found an answer anyway, I'll post it for completeness.

Neither Log4j nor Spring Boot Logging support wildcards such as logging.level.*. There is some documentation that uses that exact phrase, but they mean for the reader to substitute a package name for the asterisk. My colleagues didn't understand that and used it verbatim in documentation for their application.

The equivalent in Spring Boot Logging is logging.level.root. The equivalent in Log4j configuration files is log4j.rootLogger, although that requires one or more additional arguments giving the names of log appender objects.

like image 182
Mr. Lance E Sloan Avatar answered Sep 28 '22 00:09

Mr. Lance E Sloan