Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Can you explain why you want multiple loggers in more detail? I don't think it's possible to have multiple log4j instances. </p> <p>If you just want multiple appenders, look here: </p> <ul> <li><a href="http://www.velocityreviews.com/forums/t721794-log4j-different-logger-instances.html" rel="noreferrer">http://www.velocityreviews.com/forums/t721794-log4j-different-logger-instances.html</a></li> </ul> <p>Here's the log4j.properties from the above link:</p> <pre><code># logj4.properties log4j.rootCategory = WARN, A log4j.category.com.lewscanon = WARN, F log4j.category.com.lewscanon.mouser = DEBUG, X log4j.appender.A = org.apache.log4j.ConsoleAppender log4j.appender.A.layout = org.apache.log4j.PatternLayout log4j.appender.F = org.apache.log4j.RollingFileAppender log4j.appender.F.layout = org.apache.log4j.PatternLayout log4j.appender.F.File = /projects/mouser/logs/lewscanon.log log4j.appender.F.MaxFileSize = 512KB log4j.appender.F.MaxBackupIndex = 2 log4j.appender.X = org.apache.log4j.RollingFileAppender log4j.appender.X.layout = org.apache.log4j.PatternLayout log4j.appender.X.File = /projects/mouser/logs/mouser.log log4j.appender.X.MaxFileSize = 512KB log4j.appender.X.MaxBackupIndex = 2 log4j.appender.A.layout.ConversionPattern= %d %-16c{1}:%-39m %-t %x%n log4j.appender.F.layout.ConversionPattern= %d %-16c{1}:%-39m %-t %x%n log4j.appender.X.layout.ConversionPattern= %d %-16c{1}:%-39m %-t %x%n </code></pre> <p>These lines:</p> <pre><code>log4j.rootCategory = WARN, A log4j.category.com.lewscanon = WARN, F log4j.category.com.lewscanon.mouser = DEBUG, X </code></pre> <p>say the following:</p> <ul> <li>Log everything to appender A (which is console). Only log warnings and above</li> <li>Log everything from com.lewscanon package to appender F (which goes to file lewscanon.log). Only log warnings and above</li> <li>Log everything from com.lewscannon.mouser package to appender X (which goes to file mouser.log). Only log debug and above</li> </ul> <p>It's also possible to supply full class names:</p> <pre><code>log4j.category.com.lewscanon.SomeClass = WARN, F </code></pre> <p>means log everything from <code>com.lewscanon.SomeClass</code> class to appender F, level warn and above.</p> <p>I suppose the above is granular enough, but if you absolutely need it more granular (I don't think that's practical enough, though), per:</p> <ul> <li><a href="http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Logger.html" rel="noreferrer">http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Logger.html</a></li> </ul> <p><code>Logger.getLogger(String name)</code> accepts names. So you can do something like:</p> <pre><code>log4j.category.myFancyLogger = INFO, F </code></pre> <p>and use <code>Logger.getLogger("myFancyLogger")</code> to get the logger that logs to appender F with level info.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload