Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure logback for package?

Is it possible to configure logback to log at e.g. WARN or INFO level for all packages but x.y? And then separate configuration for package x.y only.

like image 995
Opal Avatar asked Jun 20 '12 14:06

Opal


People also ask

How do I setup a Logback XML file?

In a Logback. xml file, all the configuration options are enclosed within the <configuration> root element. In the root element, you can set the debug=true attribute to inspect Logback's internal status. You can also configure auto scanning of the configuration file by setting the scan=true attribute.

How do you specify Logback xml in application properties?

If you name your configuration file logback-spring. xml , rather than logback. xml , you can use <springProperty> to access properties from Spring's environment including those configured in application.

How do I specify the path for Logback xml?

You may specify the location of the default configuration file with a system property named "logback. configurationFile". The value of this property can be a URL, a resource on the class path or a path to a file external to the application.


1 Answers

I don't know of any way you can get the "NOT" package aspect of your question, but I routinely log one package at DEBUG and all the rest at INFO and...above is it...WARN and ERROR. This is straight up-the-middle logback. My loggers are all like...

package rekdev.org.service.api; public class DefaultConfigResource {     // ...     private static final Logger log = LoggerFactory.getLogger( DefaultConfigResource.class );     // ... } 

...on a logback.xml configuration like...

  <logger name="rekdev.org.service.api" level="debug" />   ...   <root level="info">     <appender-ref ref="STDOUT" />     <appender-ref ref="DAILY_ROLLING" />     <appender-ref ref="SYSLOG" />   </root> 

Has the effect of most output popping out at INFO, WARN, ERROR but all the rekdev.org.service.api classes. All the classes in the rekdev.org.service.api package produce output at DEBUG, INFO, WARN, ERROR.

Or did I misunderstand your questions entirely?

like image 51
Bob Kuhar Avatar answered Sep 29 '22 19:09

Bob Kuhar