Coverage details for org.chwf.plugin.Logger

LineHitsSource
1 /*
2 Chrysalis Web Framework [http://chrysalis.sourceforge.net]
3 Copyright (c) 2002, 2003, 2004, Paul Strack
4  
5 All rights reserved.
6  
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9  
10 1. Redistributions of source code must retain the above copyright notice, this
11 list of conditions and the following disclaimer.
12  
13 2. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16  
17 3. Neither the name of the copyright holder nor the names of its contributors
18 may be used to endorse or promote products derived from this software without
19 specific prior written permission.
20  
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
25 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32  
33 package org.chwf.plugin;
34  
35 /**
36  * An abstract superclass for custom logging. The default logger uses the
37  * (crude) logging utilities defined in the Servlet API; a custom Logger
38  * plugin can be used to switch this out for Log4J or the JDK 1.4 logging API.
39  * This plugin is not intended to be a full-featured logging API; it is simply
40  * a minimalist logging API to support integrating Chrysalis logging with more
41  * advanced logging frameworks.
42  *
43  * @author <a href="mailto:pfstrack@users.sourceforge.net">Paul Strack</a>
44  */
451public abstract class Logger {
46  
47   /** Id for the logger plugin in the config file. */
48   public static final String LOGGER_ID = "logger";
49  
50   /** The default logger. */
51   private static final String DEFAULT_LOGGER =
52     "org.chwf.plugin.defaults.DefaultLogger";
53  
54   /** The logger specified in the configuration. */
551  private static final Logger LOGGER = initLogger();
56  
57   /**
58    * Initialize the logger.
59    *
60    * @return The logger.
61    * @throws IllegalStateException If logger cannot be initialized.
62    */
63   private static Logger initLogger() throws IllegalStateException {
641    return (Logger) Plugin.initPlugin(Logger.class, LOGGER_ID, DEFAULT_LOGGER);
65   }
66  
67   /**
68    * Returns the <code>Logger</code> object.<p>
69    *
70    * @return The logger.
71    */
72   public static Logger getInstance() {
738    return Logger.LOGGER;
74   }
75  
76   /** No-op constructor. */
771  protected Logger() {
781  }
79  
80   /**
81    * Log the message at the debug level.<p>
82    *
83    * @param context The context class for the log message.
84    * @param message The message (string value is logged).
85    */
86   public void debug(Class context, Object message) {
872    debug(context, message, null);
882  }
89  
90   /**
91    * Log the message at the debug level.<p>
92    *
93    * @param context The context class for the log message.
94    * @param message The message (string value is logged).
95    * @param ex The exception (logs the stack-trace).
96    */
97   public void debug(Class context, Object message, Throwable ex) {
984    log(context, message, null, true);
994  }
100  
101   /**
102    * Log the message.<p>
103    *
104    * @param context The context class for the log message.
105    * @param message The message (string value is logged).
106    */
107   public void log(Class context, Object message) {
1082    log(context, message, null, false);
1092  }
110  
111   /**
112    * Log the message.<p>
113    *
114    * @param context The context class for the log message.
115    * @param message The message (string value is logged).
116    * @param ex The exception (logs the stack-trace).
117    */
118   public void log(Class context, Object message, Throwable ex) {
1194    log(context, message, ex, false);
1204  }
121  
122   /**
123    * Log the message. This method must be overridden by custom subclasses.<p>
124    *
125    * @param context The context class for the log message.
126    * @param message The message (string value is logged).
127    * @param ex The exception: logs the stack-trace (may be <code>null</code>).
128    * @param debug True if logged at the debug level.
129    */
130   protected abstract void log(
131     Class context,
132     Object message,
133     Throwable ex,
134     boolean debug);
135 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.