KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > util > Logger


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.util;
15
16 import org.apache.log4j.Level;
17 import org.apache.log4j.LogManager;
18
19 /**
20  * Compiere Logger
21  *
22  * @author Jorg Janke
23  * @version $Id: Logger.java,v 1.1 2003/10/04 03:55:46 jjanke Exp $
24  */

25 public class Logger extends org.apache.log4j.Logger
26 {
27     /**
28      * Get Compiere Logger
29      * @see org.apache.log4j.Logger#getLogger(java.lang.String)
30      * @param name fully quantified classname
31      * @return Compiere Logger
32      *
33     static public org.apache.log4j.Logger getLogger(String name)
34     {
35       return org.apache.log4j.LogManager.getLogger (name, LoggerFactory.get());
36     } // getLogger
37
38     /**
39      * Get Compiere Logger
40      * @see org.apache.log4j.Logger#getLogger(java.lang.Class)
41      * @param clazz class
42      * @return Compiere Logger
43      *
44     static public org.apache.log4j.Logger getLogger(Class clazz)
45     {
46       return getLogger(clazz.getName());
47     } // getLogger
48
49     /**
50      * Get Compiere Logger
51      * @param name fully quantified classname
52      * @return Compiere Logger
53      */

54     static public Logger getCLogger(String JavaDoc name)
55     {
56       return (Logger)LogManager.getLogger (name, LoggerFactory.get());
57     } // getCLogger
58

59     /**
60      * Get Compiere Logger
61      * @param clazz class
62      * @return Compiere Logger
63      */

64     static public Logger getCLogger(Class JavaDoc clazz)
65     {
66       return getCLogger(clazz.getName());
67     } // getCLogger
68

69     /**
70      * Get Root Logger
71      * @return Root Logger
72      */

73     public static org.apache.log4j.Logger getRootLogger()
74     {
75       return LogManager.getRootLogger();
76     } // getRootLogger
77

78     /** Saved Logging Level */
79     static Level s_logLevel = Level.ERROR;
80
81     /**
82      * Switch Logging Off and save current Level
83      */

84     public static void switchLoggingOff()
85     {
86         Level level = getRootLogger().getLevel();
87         if (level.equals(Level.OFF))
88             return;
89         Logger.getRootLogger().setLevel(Level.OFF);
90         s_logLevel = level;
91     } // switchLoggingOff
92

93     /**
94      * Switch Logging On with Old level
95      */

96     public static void switchLoggingOn()
97     {
98         Logger.getRootLogger().setLevel(s_logLevel);
99     } // switchLoggingOn
100

101     /**
102      * Shutdown all Loggers
103      */

104     public static void shutdownAll()
105     {
106         LogManager.shutdown();
107     } // shutdown
108

109     /*************************************************************************/
110
111     /**
112      * Constructor
113      */

114     protected Logger(String JavaDoc name)
115     {
116         super(name);
117     } // Logger
118

119 } // Logger
120
Popular Tags