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 java.util.Iterator; 58 import java.util.Properties; 59 import java.util.Vector; 60 import org.apache.commons.configuration.Configuration; 61 import org.apache.turbine.services.InitializationException; 62 import org.apache.turbine.services.resources.ResourceService; 63 64 /*** 65 * Small helper class that encapsulates the logging configuration 66 * information. This class reads its information from a Properties 67 * file. 68 * 69 * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a> 70 * @version $Id: PropertiesLoggingConfig.java,v 1.4 2002/07/11 16:53:26 mpoeschl Exp $ 71 */ 72 public class PropertiesLoggingConfig implements LoggingConfig 73 { 74 private String name = null; 75 private Object context = null; 76 77 private Vector files = null; 78 79 private String syslogHost = null; 80 private String syslogFacility = null; 81 82 private String remoteHost = null; 83 private int remotePort = -1; 84 85 private String emailTo = null; 86 private String emailSubject = null; 87 private String emailFrom = null; 88 private String emailBufferSize = null; 89 90 private String dbLogger = null; 91 private String dbPool = null; 92 93 private String className = null; 94 private String level = null; 95 private String format = null; 96 private boolean console = false; 97 private long fileSize = -1; 98 private int backupFiles = DEFAULT_BACKUP_FILES; 99 private ResourceService props = null; 100 101 protected PropertiesLoggingConfig() 102 { 103 } 104 105 public void setInitResource (Object props) 106 { 107 this.props = (ResourceService) props; 108 } 109 110 /*** 111 * returns all properties in a properties object - used by log4j 112 * initialization 113 **/ 114 public Properties getFacilityProperties(String facilityName) 115 { 116 // Extract the log4j values out of the configuration and 117 // place them in a Properties object so that we can 118 // use the log4j PropertyConfigurator. 119 Properties p = new Properties(); 120 121 Configuration facilityConfiguration = 122 props.getConfiguration(facilityName); 123 Iterator i = facilityConfiguration.getKeys(); 124 while (i.hasNext()) 125 { 126 String key = (String) i.next(); 127 128 // We have to deal with ExtendedProperties way 129 // of dealing with "," in properties which is to 130 // make them separate values. Log4j category 131 // properties contain commas so we must stick them 132 // back together for log4j. 133 String[] values = facilityConfiguration.getStringArray(key); 134 135 String value = null; 136 if (values.length == 1) 137 { 138 value = values[0]; 139 } 140 else if (values.length > 1) 141 { 142 StringBuffer valueSB = new StringBuffer(); 143 for (int j=0; j<values.length-1; j++) 144 { 145 valueSB.append(values[j]).append(","); 146 } 147 value = valueSB.append(values[values.length-1]).toString(); 148 } 149 150 p.put(key, value); 151 } 152 153 return p; 154 } 155 156 public void init() 157 throws InitializationException 158 { 159 if (this.props == null) 160 { 161 return; 162 } 163 164 // Just get the resources for the particular facility that 165 // we are interested in. 166 ResourceService res = props.getResources(name); 167 Iterator keys = res.getKeys(); 168 169 while (keys.hasNext()) 170 { 171 String key = (String) keys.next(); 172 173 if (key.equals(LoggingConfig.CLASSNAME)) 174 { 175 setClassName(res.getString(key)); 176 } 177 else if (key.equals(LoggingConfig.LEVEL)) 178 { 179 setLevel(res.getString(key)); 180 } 181 else if (key.equals(Logger.SIZE_KEY)) 182 { 183 setFileSize(res.getLong(key)); 184 } 185 else if (key.equals(Logger.BACKUP_KEY)) 186 { 187 setBackupFiles(res.getInt(key)); 188 } 189 else if (key.equals(Logger.FORMAT_KEY)) 190 { 191 setFormat(res.getString(key)); 192 } 193 else if (key.indexOf(LoggingConfig.DESTINATION) > -1) 194 { 195 if (key.indexOf(Logger.FILE_KEY) > -1) 196 { 197 files = res.getVector(key); 198 } 199 else if (key.indexOf(Logger.REMOTE_KEY) > -1) 200 { 201 if (key.indexOf(Logger.HOST_KEY) > -1) 202 { 203 setRemoteHost(res.getString(key)); 204 } 205 else if (key.indexOf(Logger.PORT_KEY) > -1) 206 { 207 setRemotePort(res.getInt(key)); 208 } 209 } 210 else if (key.indexOf(Logger.CONSOLE_KEY) > -1) 211 { 212 setConsole(res.getBoolean(key)); 213 } 214 else if (key.indexOf(Logger.SYSLOGD_KEY) > -1) 215 { 216 if (key.indexOf(Logger.HOST_KEY) > -1) 217 { 218 setSyslogHost(res.getString(key)); 219 } 220 else if (key.indexOf(Logger.FACILITY_KEY) > -1) 221 { 222 setSyslogFacility(res.getString(key)); 223 } 224 } 225 else if (key.indexOf(Logger.EMAIL_KEY) > -1) 226 { 227 if (key.indexOf(Logger.EMAILFROM_KEY) > -1) 228 { 229 setEmailFrom(res.getString(key)); 230 } 231 else if (key.indexOf(Logger.EMAILTO_KEY) > -1) 232 { 233 setEmailTo(res.getString(key)); 234 } 235 else if (key.indexOf(Logger.EMAILSUBJECT_KEY) > -1) 236 { 237 setEmailSubject(res.getString(key)); 238 } 239 else if (key.indexOf(Logger.EMAILBUFFERSIZE_KEY) > -1) 240 { 241 setEmailBufferSize(res.getString(key)); 242 } 243 } 244 else if (key.indexOf(Logger.DB_KEY) > -1) 245 { 246 if (key.indexOf(Logger.DB_LOGGER_KEY) > -1) 247 { 248 setDbLogger(res.getString(key)); 249 } 250 else if (key.indexOf(Logger.DB_POOL_KEY) > -1) 251 { 252 setDbPool(res.getString(key)); 253 } 254 } 255 } 256 } 257 } 258 259 public Object getServletContext() 260 { 261 return context; 262 } 263 264 public void setServletContext(Object value) 265 { 266 this.context = value; 267 } 268 269 public String getFormat() 270 { 271 return format; 272 } 273 274 public void setFormat(String value) 275 { 276 this.format = value; 277 } 278 279 public String getName() 280 { 281 return name; 282 } 283 284 public void setName(String value) 285 { 286 this.name = value; 287 } 288 289 public String getRemoteHost() 290 { 291 return remoteHost; 292 } 293 294 public void setRemoteHost(String value) 295 { 296 this.remoteHost = value; 297 } 298 299 public int getRemotePort() 300 { 301 return remotePort; 302 } 303 304 public void setRemotePort(int value) 305 { 306 this.remotePort = value; 307 } 308 309 public int getBackupFiles() 310 { 311 return backupFiles; 312 } 313 314 public void setBackupFiles(int value) 315 { 316 this.backupFiles = value; 317 } 318 319 public long getFileSize() 320 { 321 return fileSize; 322 } 323 324 public void setFileSize(long value) 325 { 326 this.fileSize = value; 327 } 328 329 public Vector getFiles() 330 { 331 return this.files; 332 } 333 334 public void setFiles(Vector value) 335 { 336 this.files = value; 337 } 338 339 public boolean getConsole() 340 { 341 return console; 342 } 343 344 public void setConsole(boolean value) 345 { 346 this.console = value; 347 } 348 349 public String getSyslogHost() 350 { 351 return syslogHost; 352 } 353 354 public void setSyslogHost(String syslogHost) 355 { 356 this.syslogHost = syslogHost; 357 } 358 359 public String getSyslogFacility() 360 { 361 return syslogFacility; 362 } 363 364 public void setSyslogFacility(String syslogFacility) 365 { 366 this.syslogFacility = syslogFacility; 367 } 368 369 public String getEmailFrom() 370 { 371 return emailFrom; 372 } 373 374 public void setEmailFrom(String emailFrom) 375 { 376 this.emailFrom = emailFrom; 377 } 378 379 public String getEmailTo() 380 { 381 return emailTo; 382 } 383 384 public void setEmailTo(String emailTo) 385 { 386 this.emailTo = emailTo; 387 } 388 389 public String getEmailSubject() 390 { 391 return emailSubject; 392 } 393 394 public void setEmailSubject(String emailSubject) 395 { 396 this.emailSubject = emailSubject; 397 } 398 399 public String getEmailBufferSize() 400 { 401 return emailBufferSize; 402 } 403 404 public void setEmailBufferSize(String bufferSize) 405 { 406 this.emailBufferSize = bufferSize; 407 } 408 409 public void setDbLogger(String v) 410 { 411 dbLogger = v; 412 } 413 414 public String getDbLogger() 415 { 416 return dbLogger; 417 } 418 419 public void setDbPool(String v) 420 { 421 dbPool = v; 422 } 423 424 public String getDbPool() 425 { 426 return dbPool; 427 } 428 429 public void setClassName(String className) 430 { 431 this.className = className; 432 } 433 434 public String getClassName() 435 { 436 return className; 437 } 438 439 public String getLevel() 440 { 441 return level; 442 } 443 444 public void setLevel(String level) 445 { 446 this.level = level; 447 } 448 }

This page was automatically generated by Maven