1 16 package org.apache.log4j.varia.test; 17 18 19 import org.apache.log4j.varia.JDBCAppender; 20 import org.apache.log4j.*; 21 22 23 public class JDBCTest 24 { 25 public static void main (String argv[]) 26 { 27 try { 28 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 29 } 30 catch (Exception e) 31 { 32 e.printStackTrace(); 33 System.out.println(e.toString()); 34 } 35 36 37 Category rootLog = Category.getRoot(); 38 Layout layout = new PatternLayout("%p [%t] %c - %m%n"); 39 JDBCAppender appender = new JDBCAppender(); 40 appender.setLayout(layout); 41 appender.setOption(JDBCAppender.URL_OPTION, "jdbc:odbc:someDB"); 42 43 44 appender.setOption(JDBCAppender.USER_OPTION, "auser"); 45 appender.setOption(JDBCAppender.PASSWORD_OPTION, "thepassword"); 46 47 48 49 rootLog.addAppender(appender); 50 51 52 try { 53 Category log = Category.getInstance("main"); 54 log.debug("Debug 1"); 55 Thread.sleep(500); 56 log.info("info 1"); 57 Thread.sleep(500); 58 log.warn("warn 1"); 59 Thread.sleep(500); 60 log.error("error 1"); 61 Thread.sleep(500); 62 log.fatal("fatal 1"); 63 Thread.sleep(500); 64 65 66 appender.setOption(JDBCAppender.BUFFER_OPTION, "5"); 67 log.debug("Debug 2"); 68 Thread.sleep(500); 69 log.info("info 2"); 70 Thread.sleep(500); 71 log.warn("warn 2"); 72 Thread.sleep(500); 73 log.error("error 2"); 74 Thread.sleep(500); 75 log.fatal("fatal 2"); 76 Thread.sleep(500); 77 78 79 appender.setOption(JDBCAppender.BUFFER_OPTION, "2"); 80 appender.setThreshold(Priority.WARN); 81 log.debug("Debug 3"); 82 Thread.sleep(500); 83 log.info("info 3"); 84 Thread.sleep(500); 85 log.warn("warn 3"); 86 Thread.sleep(500); 87 log.error("error 3"); 88 Thread.sleep(500); 89 log.fatal("fatal 3"); 90 } 91 catch (InterruptedException e) 92 { 93 System.out.println("Interrupted"); 94 } 95 } 96 } 97 | Popular Tags |