KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > lf5 > UsingLogMonitorAdapter


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 examples.lf5.UsingLogMonitorAdapter;
17
18 import org.apache.log4j.lf5.LogLevel;
19 import org.apache.log4j.lf5.util.AdapterLogRecord;
20 import org.apache.log4j.lf5.util.LogMonitorAdapter;
21
22 /**
23  * This class is a simple example of how use the LogMonitorAdapter to
24  * bypass the Log4JAppender and post LogRecords directly to the LogMonitor
25  *
26  * To make this example work, ensure that the lf5.jar and lf5-license.jar
27  * files are in your classpath, and then run the example at the command line.
28  *
29  * @author Richard Hurst
30  */

31
32 // Contributed by ThoughtWorks Inc.
33

34 public class UsingLogMonitorAdapter {
35   //--------------------------------------------------------------------------
36
// Constants:
37
//--------------------------------------------------------------------------
38

39   //--------------------------------------------------------------------------
40
// Protected Variables:
41
//--------------------------------------------------------------------------
42

43   //--------------------------------------------------------------------------
44
// Private Variables:
45
//--------------------------------------------------------------------------
46
private static LogMonitorAdapter _adapter;
47
48   static {
49     _adapter = LogMonitorAdapter.newInstance(LogMonitorAdapter.LOG4J_LOG_LEVELS);
50   }
51   //--------------------------------------------------------------------------
52
// Constructors:
53
//--------------------------------------------------------------------------
54

55   //--------------------------------------------------------------------------
56
// Public Methods:
57
//--------------------------------------------------------------------------
58

59   public static void main(String JavaDoc[] args) {
60     UsingLogMonitorAdapter test = new UsingLogMonitorAdapter();
61     test.doMyBidding();
62   }
63
64   public void doMyBidding() {
65     String JavaDoc logger = this.getClass().getName();
66
67     // will default to debug log level
68
_adapter.log(logger, "Doh this is a debugging");
69
70     _adapter.log(logger, LogLevel.INFO, "Hmmm fobidden doughnut");
71     _adapter.log(logger, LogLevel.WARN, "Danger Danger Will Robinson",
72         new RuntimeException JavaDoc("DANGER"), "32");
73     _adapter.log(logger, LogLevel.ERROR, "Exit stage right->");
74     _adapter.log(logger, LogLevel.FATAL, "What's up Doc?",
75         new NullPointerException JavaDoc("Unfortunate exception"));
76   }
77
78   //--------------------------------------------------------------------------
79
// Protected Methods:
80
//--------------------------------------------------------------------------
81

82   //--------------------------------------------------------------------------
83
// Private Methods:
84
//--------------------------------------------------------------------------
85

86   //--------------------------------------------------------------------------
87
// Nested Top-Level Classes or Interfaces:
88
//--------------------------------------------------------------------------
89
}
90
91
92
93
94
95
Popular Tags