48

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.

Opal
  • 81,889
  • 28
  • 189
  • 210

1 Answers1

81

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?

Bob Kuhar
  • 10,838
  • 11
  • 62
  • 115
  • 15
    A logger should always be "*static* final" (shared across all instances of the logged class) as it's too expensive to have a separate logger instance for every instance of the logged class. – Alex Apr 18 '14 at 21:33
  • 1
    You'd have that in annotation on JavaConf ? http://stackoverflow.com/questions/36999436/creating-a-logger-on-a-logback-java-based-no-xml-configuration – Stephane May 16 '16 at 21:18