Author: nbubna
Date: Wed May 2 22:55:15 2007
New Revision: 534721
URL: http://svn.apache.org/viewvc?view=rev&rev=534721
Log:
restore CommonsLogLogSystem from shell status now that CommonsLogLogChute has
moved to Engine and we're waiting for the 1.6 release there
Modified:
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/log/CommonsLogLogSystem.java
Modified:
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/log/CommonsLogLogSystem.java
URL:
http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/log/CommonsLogLogSystem.java?view=diff&rev=534721&r1=534720&r2=534721
==============================================================================
---
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/log/CommonsLogLogSystem.java
(original)
+++
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/log/CommonsLogLogSystem.java
Wed May 2 22:55:15 2007
@@ -19,32 +19,105 @@
* under the License.
*/
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.runtime.log.LogSystem;
/**
* Redirects Velocity's LogSystem messages to commons-logging.
*
- * <p>This is basically an empty subclass of CommmonsLogLogChute that exists
- * merely for backwards compatibility with VelocityTools 1.x. Please
- * use CommonsLogLogChute directly, as this will likely be removed
- * in VelocityTools 2.1, if not earlier.
+ * @author Nathan Bubna
+ * @since VelocityTools 1.1
+ * @version $Id$
+ */
+
+/**
+ * Redirects Velocity's LogSystem messages to commons-logging.
+ *
+ * <p>Please use CommonsLogLogChute in Velocity Engine 1.6 as this will be
+ * removed in VelocityTools releases subsequent to Velocity 1.6's release,
+ * if not earlier.
+ * </p>
+ *
+ * <p>To use, first set up commons-logging, then tell Velocity to use
+ * this class for logging by adding the following to your velocity.properties:
+ *
+ * <code>
+ * runtime.log.logsystem.class =
org.apache.velocity.tools.generic.log.CommonsLogLogSystem
+ * </code>
+ * </p>
+ *
+ * <p>You may also set this property to specify what log/name Velocity's
+ * messages should be logged to (example below is default).
+ * <code>
+ * runtime.log.logsystem.commons.logging.name = org.apache.velocity
+ * </code>
* </p>
*
* @author Nathan Bubna
+ * @deprecated Use CommonsLogLogChute in Velocity 1.6 instead.
* @since VelocityTools 1.1
- * @deprecated Use CommonsLogLogChute instead
* @version $Id$
*/
@Deprecated
-public class CommonsLogLogSystem
- extends CommonsLogLogChute implements LogSystem
+public class CommonsLogLogSystem implements LogSystem
{
+
+ /** Property key for specifying the name for the log instance */
public static final String LOGSYSTEM_COMMONS_LOG_NAME =
- LOGCHUTE_COMMONS_LOG_NAME;
+ "runtime.log.logsystem.commons.logging.name";
+
+ /** Default name for the commons-logging instance */
+ public static final String DEFAULT_LOG_NAME = "org.apache.velocity";
+
+
+ /** the commons-logging Log instance */
+ protected Log log;
+
+
+ /********** LogSystem methods *************/
+
+ public void init(RuntimeServices rs) throws Exception
+ {
+ String name =
+ (String)rs.getProperty(LOGSYSTEM_COMMONS_LOG_NAME);
+
+ if (name == null)
+ {
+ name = DEFAULT_LOG_NAME;
+ }
+ log = LogFactory.getLog(name);
+ logVelocityMessage(LogSystem.DEBUG_ID,
+ "CommonsLogLogSystem name is '" + name + "'");
+ }
+ /**
+ * Send a log message from Velocity.
+ */
public void logVelocityMessage(int level, String message)
{
- log(level, message);
+ switch (level)
+ {
+ case LogSystem.WARN_ID:
+ log.warn(message);
+ break;
+ case LogSystem.INFO_ID:
+ log.info(message);
+ break;
+ //NOTE: this is a hack to offer minor support for the
+ // new trace level in Velocity 1.5
+ case -1:
+ log.trace(message);
+ break;
+ case LogSystem.ERROR_ID:
+ log.error(message);
+ break;
+ case LogSystem.DEBUG_ID:
+ default:
+ log.debug(message);
+ break;
+ }
}
}