}
catch (Exception e)
{
String msg = "Could not init runtime.log.logsystem " + o;
log.error(msg, e);
throw new VelocityException(msg, e);
}
}
// then check for a LogSystem
else if (o instanceof LogSystem)
{
// inform the user about the deprecation
log.debug("LogSystem has been deprecated. Please use a LogChute implementation.");
try
{
// wrap the LogSystem into a chute.
LogChute chute = new LogChuteSystem((LogSystem)o);
chute.init(rsvc);
return chute;
}
catch (Exception e)
{
String msg = "Could not init runtime.log.logsystem " + o;
log.error(msg, e);
throw new VelocityException(msg, e);
}
}
else
{
String msg = o.getClass().getName() + " object set as runtime.log.logsystem is not a valid log implementation.";
log.error(msg);
throw new VelocityException(msg);
}
}
/* otherwise, see if a class was specified. You can put multiple
* classes, and we use the first one we find.
*
* Note that the default value of this property contains the
* AvalonLogChute, the Log4JLogChute, CommonsLogLogChute,
* ServletLogChute, and the JdkLogChute for
* convenience - so we use whichever we works first.
*/
List classes = new ArrayList();
Object obj = rsvc.getProperty( RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS );
/*
* we might have a list, or not - so check
*/
if ( obj instanceof List)
{
classes = (List) obj;
}
else if ( obj instanceof String)
{
classes.add( obj );
}
/*
* now run through the list, trying each. It's ok to
* fail with a class not found, as we do this to also
* search out a default simple file logger
*/
for( Iterator ii = classes.iterator(); ii.hasNext(); )
{
String claz = (String) ii.next();
if (claz != null && claz.length() > 0 )
{
log.debug("Trying to use logger class " + claz );
try
{
o = ClassUtils.getNewInstance( claz );
if (o instanceof LogChute)
{
((LogChute)o).init(rsvc);
log.debug("Using logger class " + claz);
return (LogChute)o;
}
else if (o instanceof LogSystem)
{
// inform the user about the deprecation
log.debug("LogSystem has been deprecated. Please use a LogChute implementation.");
LogChute chute = new LogChuteSystem((LogSystem)o);
chute.init(rsvc);
return chute;
}
else
{
String msg = "The specified logger class " + claz +
" does not implement the "+LogChute.class.getName()+" interface.";
log.error(msg);
// be extra informative if it appears to be a classloader issue
// this should match all our provided LogChutes
if (isProbablyProvidedLogChute(claz))
{
// if it's likely to be ours, tip them off about classloader stuff
log.error("This appears to be a ClassLoader issue. Check for multiple Velocity jars in your classpath.");
}
throw new VelocityException(msg);
}
}
catch(NoClassDefFoundError ncdfe)
{
// note these errors for anyone debugging the app
if (isProbablyProvidedLogChute(claz))
{
log.debug("Target log system for " + claz +
" is not available (" + ncdfe.toString() +
"). Falling back to next log system...");
}
else
{
log.debug("Couldn't find class " + claz +
" or necessary supporting classes in classpath.",
ncdfe);
}
}
catch(UnsupportedOperationException uoe)
{
// note these errors for anyone debugging the app
if (isProbablyProvidedLogChute(claz))
{
log.debug("Target log system for " + claz +
" is not supported (" + uoe.toString() +
"). Falling back to next log system...");
}
else
{
log.debug("Couldn't find necessary resources for "+claz, uoe);
}
}
catch(Exception e)
{
String msg = "Failed to initialize an instance of " + claz +
" with the current runtime configuration.";
// log unexpected init exception at higher priority
log.error(msg, e);
throw new VelocityException(msg,e);
}
}
}
/* If the above failed, that means either the user specified a