1 16 17 package org.apache.velocity.tools.generic.log; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 import org.apache.velocity.runtime.RuntimeServices; 22 import org.apache.velocity.runtime.log.LogSystem; 23 24 46 public class CommonsLogLogSystem implements LogSystem 47 { 48 49 50 public static final String LOGSYSTEM_COMMONS_LOG_NAME = 51 "runtime.log.logsystem.commons.logging.name"; 52 53 54 public static final String DEFAULT_LOG_NAME = "org.apache.velocity"; 55 56 57 58 protected Log log; 59 60 61 62 63 public void init(RuntimeServices rs) throws Exception 64 { 65 String name = 66 (String )rs.getProperty(LOGSYSTEM_COMMONS_LOG_NAME); 67 68 if (name == null) 69 { 70 name = DEFAULT_LOG_NAME; 71 } 72 log = LogFactory.getLog(name); 73 logVelocityMessage(LogSystem.DEBUG_ID, 74 "CommonsLogLogSystem name is '" + name + "'"); 75 } 76 77 80 public void logVelocityMessage(int level, String message) 81 { 82 switch (level) 83 { 84 case LogSystem.WARN_ID: 85 log.warn(message); 86 break; 87 case LogSystem.INFO_ID: 88 log.info(message); 89 break; 90 case LogSystem.DEBUG_ID: 91 log.debug(message); 92 break; 93 case LogSystem.ERROR_ID: 94 log.error(message); 95 break; 96 default: 97 log.debug(message); 98 break; 99 } 100 } 101 102 } 103 | Popular Tags |