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