KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log4j > varia > test > JDBCTest


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 JavaDoc argv[])
26     {
27         try {
28       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
29         }
30         catch (Exception JavaDoc 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 JavaDoc e)
92         {
93             System.out.println("Interrupted");
94         }
95     }
96 }
97
Popular Tags