11

I am using log4j to do some logging on one of my applications. The Loggers in my config are looking like this.

<Root level="info">
    <AppenderRef ref="Console"/>
</Root>

<Logger name="org.eclipse.jetty.server.Server" level="warn" additivity="false">
    <AppenderRef ref="Console"></AppenderRef>
</Logger>
<Logger name="org.eclipse.jetty.util.log" level="warn" additivity="false">
    <AppenderRef ref="Console"></AppenderRef>
</Logger>
<Logger name="org.eclipse.jetty.server.ServerConnector" level="warn" additivity="false">
    <AppenderRef ref="Console"></AppenderRef>
</Logger>

Basically, I want the "info" level messages from the code that I have written, but I want the external libs to only log if something is a warning or more dire.

This is working as I might expect, but there are a lot of classes under "org.eclipse.jetty"

Is it possible to do something like this?

<Logger name="org.eclipse.jetty.*" level="warn">
    <AppenderRef ref="Console" level="warn"></AppenderRef>
</Logger>

That is, I want everything in the entire package to only warn/error/fatal.

I tried the above and it had no effect. Is there a "wildcard" or something I can use to set up a logger for everything in the package?

Zack
  • 13,454
  • 24
  • 75
  • 113
  • 1
    Not sure right now, but i think the package is enough - at least for property based configuration, it is working that way – Simon Schrottner Jun 14 '17 at 20:47
  • Wow. I didn't even think to just try the package name. Thank you! I'll give you the accept if you answer the question. – Zack Jun 14 '17 at 21:19

2 Answers2

14

For property based configuration you just simply take the package name without any wildcards. Should work with XML too :)

Simon Schrottner
  • 4,146
  • 1
  • 24
  • 36
0

I've similar issue but I've tons of classes in a Apache kafka library package and i just need to enable logging for various packages whos names match below regular expression, org.apache.kafka*.clients.

In future if I update my Kafka library a support for Kafka Producer with version larger than 2.6 might get added and there will be a producer to support it corresponding version, e.g. there might be version 2.8 for producer with package name org.apache.kafka280.clients.producer.

This is to just futureproof my configuration for logging.

Various classes I want to be logged currently are as follows.

org.apache.kafka.clients.producer
org.apache.kafka260.clients.producer
org.apache.kafka221.clients.producer
org.apache.kafka240.clients.producer
org.apache.kafka250.clients.producer
org.apache.kafka251.clients.producer