1 package org.apache.velocity.runtime.log; 2 3 18 19 import java.util.List ; 20 import java.util.ArrayList ; 21 import java.util.Iterator ; 22 23 import org.apache.velocity.runtime.RuntimeServices; 24 import org.apache.velocity.runtime.RuntimeConstants; 25 26 58 public class LogManager 59 { 60 64 public static LogSystem createLogSystem( RuntimeServices rsvc ) 65 throws Exception 66 { 67 71 72 Object o = rsvc.getProperty( RuntimeConstants.RUNTIME_LOG_LOGSYSTEM ); 73 74 if (o != null && o instanceof LogSystem) 75 { 76 ((LogSystem) o).init( rsvc ); 77 78 return (LogSystem) o; 79 } 80 81 89 90 List classes = null; 91 Object obj = rsvc.getProperty( RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS ); 92 93 96 97 if ( obj instanceof List ) 98 { 99 classes = (List ) obj; 100 } 101 else if ( obj instanceof String ) 102 { 103 classes = new ArrayList (); 104 classes.add( obj ); 105 } 106 107 112 113 for( Iterator ii = classes.iterator(); ii.hasNext(); ) 114 { 115 String claz = (String ) ii.next(); 116 117 if (claz != null && claz.length() > 0 ) 118 { 119 rsvc.info("Trying to use logger class " + claz ); 120 121 try 122 { 123 o = Class.forName( claz ).newInstance(); 124 125 if ( o instanceof LogSystem ) 126 { 127 ((LogSystem) o).init( rsvc ); 128 129 rsvc.info("Using logger class " + claz ); 130 131 return (LogSystem) o; 132 } 133 else 134 { 135 rsvc.error("The specifid logger class " + claz + 136 " isn't a valid LogSystem"); 137 } 138 } 139 catch( NoClassDefFoundError ncdfe ) 140 { 141 rsvc.debug("Couldn't find class " + claz 142 + " or necessary supporting classes in " 143 + "classpath. Exception : " + ncdfe); 144 } 145 } 146 } 147 148 157 158 LogSystem als = null; 159 160 try 161 { 162 als = new AvalonLogSystem(); 163 164 als.init( rsvc ); 165 } 166 catch( NoClassDefFoundError ncdfe ) 167 { 168 String errstr = "PANIC : Velocity cannot find any of the" 169 + " specified or default logging systems in the classpath," 170 + " or the classpath doesn't contain the necessary classes" 171 + " to support them." 172 + " Please consult the documentation regarding logging." 173 + " Exception : " + ncdfe; 174 175 System.out.println( errstr ); 176 System.err.println( errstr ); 177 178 throw ncdfe; 179 } 180 181 rsvc.info("Using AvalonLogSystem as logger of final resort."); 182 183 return als; 184 } 185 } 186 187 | Popular Tags |