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 /**
7  * Default logger.
8  * <p/>
9  * Logs to stdout. Override this class by setting "logger.class" in pushlet.properties to your own logger
10 * to integrate your own logging library.
11 *
12 * @author Just van den Broecke
13 * @version $Id: DefaultLogger.java,v 1.2 2007/12/07 12:57:40 justb Exp $
14 */
15public class DefaultLogger implements PushletLogger {
16
17
18    /**
19     * Level intialized with default.
20     */
21    private int level = LOG_LEVEL_INFO;
22
23    public DefaultLogger() {
24    }
25
26    public void init() {
27
28    }
29
30    /**
31     * Log message for trace level.
32     *
33     * @param aMessage the message to be logged
34     */
35    public void trace(String aMessage) {
36        if (level < LOG_LEVEL_TRACE) {
37            return;
38        }
39        print("TRACE", aMessage);
40    }
41
42    /**
43     * Log message for debug level.
44     *
45     * @param aMessage the message to be logged
46     */
47    public void debug(String aMessage) {
48        if (level < LOG_LEVEL_DEBUG) {
49            return;
50        }
51        print("DEBUG", aMessage);
52    }
53
54    /**
55     * Log message for info level.
56     *
57     * @param aMessage the message to be logged
58     */
59    public void info(String aMessage) {
60        if (level < LOG_LEVEL_INFO) {
61            return;
62        }
63        print("INFO", aMessage);
64    }
65
66    /**
67     * Log message for warning level.
68     *
69     * @param aMessage the message to be logged
70     */
71    public void warn(String aMessage) {
72        if (level < LOG_LEVEL_WARN) {
73            return;
74        }
75        print("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    public void warn(String aMessage, Throwable aThrowable) {
85        warn(aMessage + " exception=" + aThrowable);
86    }
87
88    /**
89     * Log message for error level.
90     *
91     * @param aMessage the message to be logged
92     */
93    public void error(String aMessage) {
94        if (level < LOG_LEVEL_ERROR) {
95            return;
96        }
97        print("FATAL", 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    public void error(String aMessage, Throwable aThrowable) {
07        error(aMessage + " exception=" + aThrowable);
08    }
09
10    /**
11     * Log message for fatal level.
12     *
13     * @param aMessage the message to be logged
14     */
15    public void fatal(String aMessage) {
16        if (level < LOG_LEVEL_FATAL) {
17            return;
18        }
19        print("FATAL", aMessage);
20    }
21
22    /**
23     * Log message (fatal level with exception).
24     *
25     * @param aMessage   the message to be logged
26     * @param aThrowable the exception
27     */
28    public void fatal(String aMessage, Throwable aThrowable) {
29        fatal(aMessage + " exception=" + aThrowable);
30    }
31
32    /**
33     * Set log level
34     *
35     * @param aLevel the message to be logged
36     */
37    public void setLevel(int aLevel) {
38        level = aLevel;
39    }
40
41    /**
42     * Print message.
43     *
44     * @param aTag   the log type
45     * @param aMessage the message to be logged
46     */
47    private void print(String aTag, String aMessage) {
48        // SImple std out e.g. to catalina.out in Tomcat
49        System.out.println("Pushlet[" + aTag + "] " + aMessage);
50    }
51
52}
53
54/*
55* $Log: DefaultLogger.java,v $
56* Revision 1.2  2007/12/07 12:57:40  justb
57* added log4j and make it the default logging method
58*
59* Revision 1.1  2007/11/23 21:10:17  justb
60* add hooks for custom logging (you can override DefaultLogger in pushlet.properties)
61*
62*
63*
64*/