23

Can I override a logging level for a specific class only using logback.xml? i.e everything remains in INFO, except for one class which will log in DEBUG.

I appended this after the default one, but does not seem to work

<logger name="com.pack1.pack2.paack3.ClassName" additivity="false" level="debug">
    <appender-ref ref="file1"/>
</logger>

Thanks, Donald

Donald
  • 329
  • 1
  • 3
  • 7
  • 1
    Have you tried the simpler statement ``? AFAIK, the level isn't case-sensitive. Can you share your full logback.xml? – MiguelKVidal Sep 26 '16 at 18:24

3 Answers3

9

Doing it exactly like this works for me:

<logger name="org.apache.zookeeper" level="WARN" />
F. P. Freely
  • 1,026
  • 14
  • 24
  • 3
    Careful with the appender-ref tag, for me this duplicated the log output. Simply using after the root logger definition did it for me – Schorsch Jan 02 '20 at 13:59
  • It seems to work fine, thanks. It's nice that it's possible to either specify a specific class, a specific package or a parent package. – Eric Duminil Jun 14 '23 at 07:38
5

(In case you set the name of logger explicitly) check if the name of the logger matches the name you set for your logger in your source code.

Use the upper case letters for level keywords (DEBUG, INFO ....) and I am not sure but maybe you should use Level instead of level.

Mr.Q
  • 4,316
  • 3
  • 43
  • 40
1

I'm pretty sure I've done that before and it's worked. Try uppercase DEBUG.

David Roussel
  • 5,788
  • 1
  • 30
  • 35