View Javadoc
1 package org.apache.turbine.services.logging; 2 3 /* ==================================================================== 4 * The Apache Software License, Version 1.1 5 * 6 * Copyright (c) 2001 The Apache Software Foundation. All rights 7 * reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in 18 * the documentation and/or other materials provided with the 19 * distribution. 20 * 21 * 3. The end-user documentation included with the redistribution, 22 * if any, must include the following acknowledgment: 23 * "This product includes software developed by the 24 * Apache Software Foundation (http://www.apache.org/)." 25 * Alternately, this acknowledgment may appear in the software itself, 26 * if and wherever such third-party acknowledgments normally appear. 27 * 28 * 4. The names "Apache" and "Apache Software Foundation" and 29 * "Apache Turbine" must not be used to endorse or promote products 30 * derived from this software without prior written permission. For 31 * written permission, please contact apache@apache.org. 32 * 33 * 5. Products derived from this software may not be called "Apache", 34 * "Apache Turbine", nor may "Apache" appear in their name, without 35 * prior written permission of the Apache Software Foundation. 36 * 37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 48 * SUCH DAMAGE. 49 * ==================================================================== 50 * 51 * This software consists of voluntary contributions made by many 52 * individuals on behalf of the Apache Software Foundation. For more 53 * information on the Apache Software Foundation, please see 54 * <http://www.apache.org/>;. 55 */ 56 57 import javax.servlet.ServletContext; 58 import org.apache.turbine.util.RunData; 59 60 /*** 61 * This class implements Logger interface using log method from ServletContext. 62 * This implementation is very simple, so there is no extracting data from RunData, 63 * and no log levels. 64 * 65 * @see org.apache.turbine.services.logging.Logger 66 * @author <a href="mailto:Tomasz.Zielinski@e-point.pl">Tomasz Zielinski</a> 67 * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a> 68 * @version $Id: ServletLogger.java,v 1.2 2002/07/11 16:53:26 mpoeschl Exp $ 69 */ 70 public class ServletLogger extends BaseLogger 71 { 72 /*** context for calling method: "log" */ 73 protected ServletContext context=null; 74 75 protected String lf = System.getProperty("line.separator", "\n"); 76 77 public ServletLogger() 78 { 79 super(); 80 } 81 82 /*** Initialize*/ 83 public void init(LoggingConfig loggingConfig) 84 { 85 this.context = (ServletContext) loggingConfig.getServletContext(); 86 } 87 88 /*** Empty method*/ 89 public void shutdown() 90 { 91 } 92 93 /*** 94 * It performs action that are need for deterimne whether 95 * logger was well configured or has any output 96 */ 97 public boolean checkLogger() 98 { 99 return (true); 100 } 101 102 /*** 103 * This is a log method with logLevel == DEBUG 104 */ 105 public void debug(String message) 106 { 107 log(DEBUG, message, null, null); 108 } 109 110 /*** 111 * This is a log method with logLevel == DEBUG 112 */ 113 public void debug(String message, Throwable t) 114 { 115 log(DEBUG, message, null, t); 116 } 117 118 /*** 119 * This is a log method with logLevel == DEBUG 120 */ 121 public void debug(String message, RunData data) 122 { 123 log(DEBUG, message, data, null); 124 } 125 126 /*** 127 * This is a log method with logLevel == DEBUG 128 */ 129 public void debug(String message, RunData data, Throwable t) 130 { 131 log(DEBUG, message, data, t); 132 } 133 134 /*** 135 * This is a log method with logLevel == INFO 136 */ 137 public void info(String message) 138 { 139 log(INFO, message, null, null); 140 } 141 142 /*** 143 * This is a log method with logLevel == INFO 144 */ 145 public void info(String message, Throwable t) 146 { 147 log(INFO, message, null, t); 148 } 149 150 /*** 151 * This is a log method with logLevel == INFO 152 */ 153 public void info(String message, RunData data) 154 { 155 log(INFO, message, data, null); 156 } 157 158 /*** 159 * This is a log method with logLevel == INFO 160 */ 161 public void info(String message, RunData data, Throwable t) 162 { 163 log(INFO, message, data, t); 164 } 165 166 /*** 167 * This is a log method with logLevel == WARN 168 */ 169 public void warn(String message) 170 { 171 log(WARN, message, null, null); 172 } 173 174 /*** 175 * This is a log method with logLevel == WARN 176 */ 177 public void warn(String message, Throwable t) 178 { 179 log(WARN, message, null, t); 180 } 181 182 /*** 183 * This is a log method with logLevel == WARN 184 */ 185 public void warn(String message, RunData data) 186 { 187 log(WARN, message, data, null); 188 } 189 190 /*** 191 * This is a log method with logLevel == WARN 192 */ 193 public void warn(String message, RunData data, Throwable t) 194 { 195 log(WARN, message, data, t); 196 } 197 198 /*** 199 * This is a log method with logLevel == ERROR 200 */ 201 public void error(String message) 202 { 203 log(ERROR, message, null, null); 204 } 205 206 public void error(String message, Throwable e) 207 { 208 log(ERROR, message, null, e); 209 210 } 211 212 public void error(Throwable e) 213 { 214 log(ERROR, null, null, e); 215 } 216 217 public void error(String message, RunData data) 218 { 219 log(ERROR, message, data, null); 220 } 221 222 public void error(String message, RunData data, Throwable e) 223 { 224 log(ERROR, message, data, e); 225 } 226 227 /*** appends log level to the message */ 228 protected void log(int level, String message, RunData data, Throwable e) 229 { 230 String levelS; 231 switch (level) 232 { 233 case DEBUG: levelS = LEVELDEBUG; break; 234 case INFO: levelS = LEVELINFO; break; 235 case WARN: levelS = LEVELWARN; break; 236 case ERROR: levelS = LEVELERROR; break; 237 default: levelS = LEVELDEBUG; 238 } 239 240 logAll(levelS, message, data, e); 241 } 242 243 /*** log message using context log method. */ 244 protected void logAll(String level, String description, RunData data, 245 Throwable t) 246 { 247 248 boolean odp=true; 249 250 StringBuffer logEntry = new StringBuffer(); 251 logEntry.append ( " -- " ); 252 logEntry.append ( level ); 253 logEntry.append ( " -- " ); 254 logEntry.append ( description ); 255 256 if (t != null) 257 { 258 context.log(logEntry.toString(), t); 259 } 260 else 261 { 262 context.log(logEntry.toString()); 263 } 264 } 265 }

This page was automatically generated by Maven