KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cowsultants > itracker > ejb > client > util > Logger


1 /*
2  * This software was designed and created by Jason Carroll.
3  * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4  * The author can be reached at jcarroll@cowsultants.com
5  * ITracker website: http://www.cowsultants.com
6  * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it only under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  */

18
19 package cowsultants.itracker.ejb.client.util;
20
21 import java.rmi.*;
22 import java.util.*;
23 import javax.rmi.*;
24 import javax.naming.*;
25
26 import org.apache.log4j.*;
27
28 import cowsultants.itracker.ejb.client.interfaces.*;
29
30 public class Logger {
31     private static final org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger("cowsultants.ITracker");
32     private static String JavaDoc logLevel = "DEBUG";
33
34     static {
35         Enumeration appenders = logger.getAllAppenders();
36         if(! appenders.hasMoreElements() && ! logger.getRootLogger().getAllAppenders().hasMoreElements()) {
37             //Create a console appender in case log4j not setup correctly
38
logger.setLevel((Level) Level.toLevel(logLevel));
39             logger.addAppender(new ConsoleAppender(new PatternLayout("%d{ABSOLUTE} %-5p [%c{1}] %m%n")));
40             logger.info("Could not determine current configuration, adding new ConsoleAppender, setting logLevel to " + logLevel);
41         }
42     }
43
44     public static boolean isLoggingDebug() {
45         return logger.isDebugEnabled();
46     }
47
48     public static boolean isLoggingInfo() {
49         return logger.isInfoEnabled();
50     }
51
52     public static void logDebug(String JavaDoc message) {
53         logger.debug(message);
54     }
55
56     public static void logDebug(String JavaDoc location, String JavaDoc message) {
57         logger.debug(location + ": " + message);
58     }
59
60     public static void logDebug(String JavaDoc message, Throwable JavaDoc t) {
61         logger.debug(message, t);
62     }
63
64     public static void logInfo(String JavaDoc message) {
65         logger.info(message);
66     }
67
68     public static void logInfo(String JavaDoc location, String JavaDoc message) {
69         logger.info(location + ": " + message);
70     }
71
72     public static void logInfo(String JavaDoc message, Throwable JavaDoc t) {
73         logger.info(message, t);
74     }
75
76     public static void logWarn(String JavaDoc message) {
77         logger.warn(message);
78     }
79
80     public static void logWarn(String JavaDoc location, String JavaDoc message) {
81         logger.warn(location + ": " + message);
82     }
83
84     public static void logWarn(String JavaDoc message, Throwable JavaDoc t) {
85         logger.warn(message, t);
86     }
87
88     public static void logError(String JavaDoc message) {
89         logger.error(message);
90     }
91
92     public static void logError(String JavaDoc location, String JavaDoc message) {
93         logger.error(location + ": " + message);
94     }
95
96     public static void logError(String JavaDoc message, Throwable JavaDoc t) {
97         logger.error(message, t);
98     }
99
100 }
Popular Tags