Posted on by | Posted in Developer Blog, Open Source Blog | Tagged ,

Sometimes even the simple things take quite some time. For a special application log I've been searching for a way to write log calls for one package to a separate file using Log4j. I've been searching the web, skimming through the log4j documentation but didn't really find anything. This message, though only a question, contained the missing hint.

Suppose you have a log configuration that already has root loggers configured. To make only one package log to another file, but not to the root logger appenders, you add something like this:,FILE
log4j.appender.FILE.layout.ConversionPattern=%d{DATE} %5p [%30.30C:%4L] %m%n

What does it do? In the first line you create a logger that logs anything above info inclusive. In the same line, separated by a comma, you add the name of your appender. By setting additivity to false you prevent the logger to inherit any loggers from ancestors (including any root loggers).

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.