Search Java Code Snippets


  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.





#Java - Code Snippets for '#Log4j' - 5 code snippet(s) found

 Sample 1. Exception handling and logging using Log4j

private static final Logger LOGGER = Logger.getLogger(BuggyBread.class);

public static void main(String[] args) {
   try {
      // Do Something   
   } catch (Throwable t) {
      LOGGER.error("Shit Happens");
   } finally {
      // release the connections
   }
}



   Like      Feedback     exception handling  exceptions  log4j  logging  logger  finally


 Sample 2. Rolling File Appender for Log4j


                 ignoreExceptions="false">
      
   %d %p %c - %m %n
      

      

   Like      Feedback     log4j  log4j appender  log4j rolling file appender


 Sample 3. Sample Log4j config with Rolling File Appender within Time Based Triggering Policy

<Configuration status="DEBUG">
<Appenders>
<RollingFile name="File" fileName="logs/xyz.log" filePattern="logs/xyz-%d{MM-dd-yyyy}.log.gz">
      <TimeBasedTriggeringPolicy />
   </RollingFile>
</Appenders>
<Loggers>
<Root level="DEBUG">
<AppenderRef ref="File" />
</Root>
</Loggers>
</Configuration>

   Like      Feedback     log4j  rolling logs with log4j  TimeBasedTriggeringPolicy


 Sample 4. Sample Log4j config with RollingRandomAccessFile appender and TimeBasedTriggeringPolicy

<Configuration status="INFO">
<Appenders>
<RollingRandomAccessFile name="File" fileName="logs/xyz.log" immediateFlush="true" filePattern="logs/xyz-%d{MM-dd-yyyy}.log.gz">
      <TimeBasedTriggeringPolicy />
   </RollingRandomAccessFile>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="File" />
</Root>
</Loggers>
</Configuration>

   Like      Feedback     log4j  rolling logs with log4j  TimeBasedTriggeringPolicy  RollingRandomAccessFile


Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
 Sample 5. Sample Log4j config file with RollingRandomAccessFile appender ( Rolling Logs ) and SizeBasedTriggeringPolicy

<Configuration status="INFO">
<Appenders>
<RollingRandomAccessFile name="File" fileName="logs/xyz.log" immediateFlush="true" filePattern="logs/xyz-%d{MM-dd-yyyy}.log.gz">
      <SizeBasedTriggeringPolicy size="250 MB"/>
   </RollingRandomAccessFile>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="File" />
</Root>
</Loggers>
</Configuration>

   Like      Feedback     log4j  SizeBasedTriggeringPolicy  RollingRandomAccessFile



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner