| Log.java |
1 // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
2 // Distributable under LGPL license. See terms of license at gnu.org.
3
4 package nl.justobjects.pushlet.util;
5
6 import nl.justobjects.pushlet.core.Config;
7 import nl.justobjects.pushlet.core.ConfigDefs;
8
9 /**
10 * Logging wrapper.
11 * <p/>
12 * Provides a hook to direct logging to your own logging library. Override the DefaultLogger class by setting
13 * "logging.class" in pushlet.properties to your own logger
14 * to integrate your own logging library.
15 *
16 * @author Just van den Broecke
17 * @version $Id: Log.java,v 1.4 2007/11/23 21:29:43 justb Exp $
18 */
19public class Log implements ConfigDefs {
20 private static DefaultLogger logger = new DefaultLogger();
21
22 /**
23 * General purpose initialization.
24 */
25 static public void init() {
26 try {
27 logger = (DefaultLogger) Config.getClass(LOGGER_CLASS, "nl.justobjects.pushlet.util.DefaultLogger").newInstance();
28 } catch (Throwable t) {
29 // Hmmm cannot log this since we don't have a log...
30 System.out.println("Cannot instantiate Logger from config ex=" + t);
31 return;
32 }
33
34 logger.init();
35
36 // Set log level
37 logger.setLevel(Config.getIntProperty(Config.LOG_LEVEL));
38
39 logger.info("Logging intialized logger class=" + logger.getClass());
40 }
41
42 /**
43 * Log message for trace level.
44 *
45 * @param aMessage the message to be logged
46 */
47 static public void trace(String aMessage) {
48 logger.debug(aMessage);
49 }
50
51 /**
52 * Log message for debug level.
53 *
54 * @param aMessage the message to be logged
55 */
56 static public void debug(String aMessage) {
57 logger.debug(aMessage);
58 }
59
60 /**
61 * Log message for info level.
62 *
63 * @param aMessage the message to be logged
64 */
65 static public void info(String aMessage) {
66 logger.info(aMessage);
67 }
68
69 /**
70 * Log message for warning level.
71 *
72 * @param aMessage the message to be logged
73 */
74 static public void warn(String aMessage) {
75 logger.warn(aMessage);
76 }
77
78 /**
79 * Log message for warning level with exception.
80 *
81 * @param aMessage the message to be logged
82 * @param aThrowable the exception
83 */
84 static public void warn(String aMessage, Throwable aThrowable) {
85 logger.warn(aMessage, aThrowable);
86 }
87
88 /**
89 * Log message for error level.
90 *
91 * @param aMessage the message to be logged
92 */
93 static public void error(String aMessage) {
94 logger.error(aMessage);
95 }
96
97 /**
98 * Log message (error level with exception).
99 *
00 * @param aMessage the message to be logged
01 * @param aThrowable the exception
02 */
03 static public void error(String aMessage, Throwable aThrowable) {
04 logger.error(aMessage, aThrowable);
05 }
06
07 /**
08 * Log message for fatal level.
09 *
10 * @param aMessage the message to be logged
11 */
12 static public void fatal(String aMessage) {
13 logger.fatal(aMessage);
14 }
15
16 /**
17 * Log message (fatal level with exception).
18 *
19 * @param aMessage the message to be logged
20 * @param aThrowable the exception
21 */
22 static public void fatal(String aMessage, Throwable aThrowable) {
23 logger.fatal(aMessage, aThrowable);
24 }
25
26 /**
27 * Set log level
28 *
29 * @param aLevel the message to be logged
30 */
31 static public void setLevel(int aLevel) {
32 logger.setLevel(aLevel);
33 }
34}
35
36/*
37* $Log: Log.java,v $
38* Revision 1.4 2007/11/23 21:29:43 justb
39* add hooks for custom logging (you can override DefaultLogger in pushlet.properties)
40*
41* Revision 1.3 2007/11/23 21:10:17 justb
42* add hooks for custom logging (you can override DefaultLogger in pushlet.properties)
43*
44* Revision 1.2 2005/02/21 11:15:59 justb
45* support log levels
46*
47* Revision 1.1 2005/02/18 10:07:23 justb
48* many renamings of classes (make names compact)
49*
50* Revision 1.7 2004/09/03 22:35:37 justb
51* Almost complete rewrite, just checking in now
52*
53* Revision 1.6 2004/08/12 13:16:08 justb
54* make debug flag false
55*
56* Revision 1.5 2004/03/10 14:01:55 justb
57* formatting and *Subscriber refactoring
58*
59* Revision 1.4 2003/08/15 09:54:46 justb
60* fix javadoc warnings
61*
62* Revision 1.3 2003/08/15 08:37:40 justb
63* fix/add Copyright+LGPL file headers and footers
64*
65* Revision 1.2 2003/08/12 09:42:47 justb
66* enhancements
67*
68* Revision 1.1 2003/08/12 08:46:00 justb
69* cvs comment tags added
70*
71*
72*/| Log.java |