You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by wg...@apache.org on 2005/10/01 06:37:29 UTC
svn commit: r292918 [1/3] - in /jakarta/velocity/core/trunk: ./ build/lib/
src/java/org/apache/velocity/ src/java/org/apache/velocity/app/event/
src/java/org/apache/velocity/app/event/implement/
src/java/org/apache/velocity/runtime/ src/java/org/apache...
Author: wglass
Date: Fri Sep 30 21:36:58 2005
New Revision: 292918
URL: http://svn.apache.org/viewcvs?rev=292918&view=rev
Log:
Comprehensive logging update patch from Nathan Bubna.
Introduces LogChute interface, deprecates LogSystem.
See VELOCITY-403 for patch details.
Note: now requires JDK 1.4 to compile and Log4j 1.2.12.
Solves issues from
* VELOCITY-78
* VELOCITY-157
* VELOCITY-159
* VELOCITY-193
* VELOCITY-403
Added:
jakarta/velocity/core/trunk/build/lib/log4j-1.2.12.jar (with props)
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/AvalonLogChute.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/HoldingLogChute.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/JdkLogChute.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/Log.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/Log4JLogChute.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/LogChute.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/LogChuteSystem.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/NullLogChute.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/RuntimeLoggerLog.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/StandardOutLogChute.java
Removed:
jakarta/velocity/core/trunk/build/lib/log4j-1.2.8.jar
Modified:
jakarta/velocity/core/trunk/project.xml
jakarta/velocity/core/trunk/src/java/org/apache/velocity/Template.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/event/EventHandlerUtil.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/event/implement/EscapeReference.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/event/implement/IncludeNotFound.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeConstants.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeServices.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/VelocimacroFactory.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/VelocimacroManager.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/defaults/velocity.properties
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Include.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Macro.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Parse.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/VMProxyArg.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/AvalonLogSystem.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/Log4JLogSystem.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/LogManager.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/LogSystem.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/NullLogSystem.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/PrimordialLogSystem.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/Parser.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTAddNode.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTAndNode.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTDivNode.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTEQNode.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTGENode.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTGTNode.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIntegerRange.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTLENode.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTLTNode.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTModNode.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMulNode.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTNENode.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTSubtractNode.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/AbstractExecutor.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/BooleanPropertyExecutor.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/GetExecutor.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/parser/node/SimpleNode.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/ContentResource.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/ResourceCacheImpl.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/JarHolder.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/ResourceLoaderFactory.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/util/introspection/Introspector.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/util/introspection/UberspectImpl.java
jakarta/velocity/core/trunk/src/java/org/apache/velocity/util/introspection/UberspectLoggable.java
jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/ClassloaderChangeTestCase.java
jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/EventHandlingTestCase.java
jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/ExternalLoggerTestCase.java
jakarta/velocity/core/trunk/src/test/org/apache/velocity/test/FilteredEventHandlingTestCase.java
Added: jakarta/velocity/core/trunk/build/lib/log4j-1.2.12.jar
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/build/lib/log4j-1.2.12.jar?rev=292918&view=auto
==============================================================================
Binary file - no diff available.
Propchange: jakarta/velocity/core/trunk/build/lib/log4j-1.2.12.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: jakarta/velocity/core/trunk/project.xml
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/project.xml?rev=292918&r1=292917&r2=292918&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/project.xml (original)
+++ jakarta/velocity/core/trunk/project.xml Fri Sep 30 21:36:58 2005
@@ -184,7 +184,7 @@
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
- <version>1.2.11</version>
+ <version>1.2.12</version>
<url>http://logging.apache.org/log4j/</url>
<type>jar</type>
<properties>
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/Template.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/Template.java?rev=292918&r1=292917&r2=292918&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/Template.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/Template.java Fri Sep 30 21:36:58 2005
@@ -268,7 +268,7 @@
String msg = "Template.merge() failure. The document is null, " +
"most likely due to parsing error.";
- rsvc.error(msg);
+ rsvc.getLog().error(msg);
throw new Exception(msg);
}
}
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/event/EventHandlerUtil.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/event/EventHandlerUtil.java?rev=292918&r1=292917&r2=292918&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/event/EventHandlerUtil.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/event/EventHandlerUtil.java Fri Sep 30 21:36:58 2005
@@ -59,7 +59,7 @@
}
catch (Exception E)
{
- rsvc.error("Couldn't initialize event handler. " + E);
+ rsvc.getLog().error("Couldn't initialize event handler.", E);
}
}
@@ -115,7 +115,7 @@
}
catch (Exception E)
{
- rsvc.error("Couldn't initialize event handler. " + E);
+ rsvc.getLog().error("Couldn't initialize event handler.", E);
}
}
@@ -178,7 +178,7 @@
}
catch (Exception E)
{
- rsvc.error("Couldn't initialize event handler. " + E);
+ rsvc.getLog().error("Couldn't initialize event handler.", E);
}
}
@@ -245,7 +245,7 @@
}
catch (Exception E)
{
- rsvc.error("Couldn't initialize event handler. " + E);
+ rsvc.getLog().error("Couldn't initialize event handler.", E);
}
}
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/event/implement/EscapeReference.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/event/implement/EscapeReference.java?rev=292918&r1=292917&r2=292918&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/event/implement/EscapeReference.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/event/implement/EscapeReference.java Fri Sep 30 21:36:58 2005
@@ -118,7 +118,8 @@
}
catch (MalformedPerl5PatternException E)
{
- rs.error("Invalid regular expression '" + matchRegExp + "'. No escaping will be performed.");
+ rs.getLog().error("Invalid regular expression '" + matchRegExp
+ + "'. No escaping will be performed.");
matchRegExp = null;
}
}
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/event/implement/IncludeNotFound.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/event/implement/IncludeNotFound.java?rev=292918&r1=292917&r2=292918&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/event/implement/IncludeNotFound.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/app/event/implement/IncludeNotFound.java Fri Sep 30 21:36:58 2005
@@ -69,7 +69,7 @@
*/
else
{
- rs.error("Can't find include not found page: " + notfound);
+ rs.getLog().error("Can't find include not found page: " + notfound);
return null;
}
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeConstants.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeConstants.java?rev=292918&r1=292917&r2=292918&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeConstants.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeConstants.java Fri Sep 30 21:36:58 2005
@@ -87,6 +87,7 @@
/**
* Log message prefixes
*/
+ public final static String TRACE_PREFIX = " [trace] ";
public final static String DEBUG_PREFIX = " [debug] ";
public final static String INFO_PREFIX = " [info] ";
public final static String WARN_PREFIX = " [warn] ";
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java?rev=292918&r1=292917&r2=292918&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeInstance.java Fri Sep 30 21:36:58 2005
@@ -39,9 +39,7 @@
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.runtime.directive.Directive;
import org.apache.velocity.runtime.log.LogManager;
-import org.apache.velocity.runtime.log.LogSystem;
-import org.apache.velocity.runtime.log.NullLogSystem;
-import org.apache.velocity.runtime.log.PrimordialLogSystem;
+import org.apache.velocity.runtime.log.Log;
import org.apache.velocity.runtime.parser.ParseException;
import org.apache.velocity.runtime.parser.Parser;
import org.apache.velocity.runtime.parser.node.SimpleNode;
@@ -49,7 +47,6 @@
import org.apache.velocity.runtime.resource.ResourceManager;
import org.apache.velocity.util.ClassUtils;
import org.apache.velocity.util.SimplePool;
-import org.apache.velocity.util.StringUtils;
import org.apache.velocity.util.introspection.Introspector;
import org.apache.velocity.util.introspection.Uberspect;
import org.apache.velocity.util.introspection.UberspectLoggable;
@@ -109,12 +106,12 @@
private VelocimacroFactory vmFactory = null;
/**
- * The Runtime logger. We start with an instance of
- * a 'primordial logger', which just collects log messages
- * then, when the log system is initialized, we dump
- * all messages out of the primordial one into the real one.
+ * The Runtime logger. We start with an instance of
+ * a 'primordial logger', which just collects log messages
+ * then, when the log system is initialized, all the
+ * messages get dumpted out of the primordial one into the real one.
*/
- private LogSystem logSystem = new PrimordialLogSystem();
+ private Log log = new Log();
/**
* The Runtime parser pool
@@ -195,7 +192,7 @@
* make a new introspector and initialize it
*/
- introspector = new Introspector( this );
+ introspector = new Introspector(getLog());
/*
* and a store for the application attributes
@@ -228,7 +225,7 @@
info("Starting Jakarta Velocity v@version@");
info("RuntimeInstance initializing.");
initializeProperties();
- initializeLogger();
+ initializeLog();
initializeResourceManager();
initializeDirectives();
initializeEventHandlers();
@@ -289,7 +286,7 @@
if (uberSpect instanceof UberspectLoggable)
{
- ((UberspectLoggable) uberSpect).setRuntimeLogger(this);
+ ((UberspectLoggable) uberSpect).setLog(getLog());
}
uberSpect.init();
@@ -646,32 +643,12 @@
*
* @throws Exception
*/
- private void initializeLogger() throws Exception
+ private void initializeLog() throws Exception
{
- /*
- * Initialize the logger. We will eventually move all
- * logging into the logging manager.
- */
- if (logSystem instanceof PrimordialLogSystem)
- {
- PrimordialLogSystem pls = (PrimordialLogSystem) logSystem;
- logSystem = LogManager.createLogSystem(this);
-
- /*
- * in the event of failure, lets do something to let it
- * limp along.
- */
-
- if (logSystem == null)
- {
- logSystem = new NullLogSystem();
- }
- else
- {
- pls.dumpLogMessages(logSystem);
- }
- }
- }
+ // since the Log we started with was just placeholding,
+ // let's update it with the real LogChute settings.
+ LogManager.updateLog(this.log, this);
+ }
/**
@@ -1017,92 +994,43 @@
}
/**
- * Added this to check and make sure that the configuration
- * is initialized before trying to get properties from it.
- * This occurs when there are errors during initialization
- * and the default properties have yet to be layed down.
+ * Returns a convenient Log instance that wraps the current LogChute.
*/
- private boolean showStackTrace()
+ public Log getLog()
{
- if (configuration.isInitialized())
- {
- return getBoolean(RUNTIME_LOG_WARN_STACKTRACE, false);
- }
- else
- {
- return false;
- }
+ return log;
}
/**
- * Handle logging.
- *
- * @param level level of message to log
- * @param message message to log
- */
- private void log(int level, Object message)
- {
- String out;
-
- /*
- * now, see if the logging stacktrace is on
- * and modify the message to suit
- */
- if (showStackTrace() &&
- (message instanceof Throwable || message instanceof Exception))
- {
- out = StringUtils.stackTrace((Throwable)message);
- }
- else
- {
- out = message.toString();
- }
-
- /*
- * just log it, as we are guaranteed now to have some
- * kind of logger - save the if()
- */
- logSystem.logVelocityMessage(level, out);
- }
-
- /**
- * Log a warning message.
- *
- * @param message message to log
+ * @deprecated Use getLog() and call warn() on it.
*/
public void warn(Object message)
{
- log(LogSystem.WARN_ID, message);
+ getLog().warn(message);
}
/**
- * Log an info message.
- *
- * @param message message to log
+ * @deprecated Use getLog() and call info() on it.
*/
public void info(Object message)
{
- log(LogSystem.INFO_ID, message);
+ getLog().info(message);
}
/**
- * Log an error message.
- *
- * @param message message to log
+ * @deprecated Use getLog() and call error() on it.
*/
public void error(Object message)
{
- log(LogSystem.ERROR_ID, message);
+ getLog().error(message);
}
/**
- * Log a debug message.
- *
- * @param message message to log
+ * @deprecated Use getLog() and call debug() on it.
*/
public void debug(Object message)
{
- log(LogSystem.DEBUG_ID, message);
+ getLog().debug(message);
}
/**
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeServices.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeServices.java?rev=292918&r1=292917&r2=292918&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeServices.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/RuntimeServices.java Fri Sep 30 21:36:58 2005
@@ -25,6 +25,7 @@
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.runtime.directive.Directive;
+import org.apache.velocity.runtime.log.Log;
import org.apache.velocity.runtime.parser.ParseException;
import org.apache.velocity.runtime.parser.node.SimpleNode;
import org.apache.velocity.runtime.resource.ContentResource;
@@ -335,6 +336,11 @@
* implemenation.
*/
public Uberspect getUberspect();
+
+ /**
+ * Returns a convenient Log instance that wraps the current LogChute.
+ */
+ public Log getLog();
/**
* Returns the event handlers for the application.
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/VelocimacroFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/VelocimacroFactory.java?rev=292918&r1=292917&r2=292918&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/VelocimacroFactory.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/VelocimacroFactory.java Fri Sep 30 21:36:58 2005
@@ -316,7 +316,7 @@
"will not automatically reload global library macros");
}
- rsvc.info("Velocimacro : initialization complete.");
+ rsvc.getLog().info("Velocimacro : initialization complete.");
}
return;
@@ -369,7 +369,7 @@
Macro.macroToString(msg, argArray);
msg.append(" : source = ").append(sourceTemplate);
// Already checked for getBlather()
- rsvc.info(msg.toString());
+ rsvc.getLog().info(msg);
}
return true;
@@ -452,7 +452,7 @@
{
if (getBlather())
{
- rsvc.info( s );
+ rsvc.getLog().info(s);
}
}
@@ -463,7 +463,7 @@
{
if (getBlather())
{
- rsvc.warn( s );
+ rsvc.getLog().warn(s);
}
}
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/VelocimacroManager.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/VelocimacroManager.java?rev=292918&r1=292917&r2=292918&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/VelocimacroManager.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/VelocimacroManager.java Fri Sep 30 21:36:58 2005
@@ -446,8 +446,8 @@
}
catch ( Exception e )
{
- rsvc.error("VelocimacroManager.parseTree() : exception " +
- macroname + " : " + StringUtils.stackTrace(e));
+ rsvc.getLog().error("VelocimacroManager.parseTree() : exception "
+ + macroname, e);
}
}
}
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/defaults/velocity.properties
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/defaults/velocity.properties?rev=292918&r1=292917&r2=292918&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/defaults/velocity.properties (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/defaults/velocity.properties Fri Sep 30 21:36:58 2005
@@ -10,10 +10,10 @@
#----------------------------------------------------------------------------
#----------------------------------------------------------------------------
-# default LogSystem to use: default: AvalonLogSystem
+# default LogChute to use: default: AvalonLogChute, Log4JLogChute, JdkLogChute
#----------------------------------------------------------------------------
-runtime.log.logsystem.class = org.apache.velocity.runtime.log.AvalonLogSystem,org.apache.velocity.runtime.log.SimpleLog4JLogSystem
+runtime.log.logsystem.class = org.apache.velocity.runtime.log.AvalonLogChute,org.apache.velocity.runtime.log.Log4JLogChute,org.apache.velocity.runtime.log.JdkLogChute
#---------------------------------------------------------------------------
# This is the location of the Velocity Runtime log.
@@ -31,30 +31,6 @@
runtime.log.warn.stacktrace = false
runtime.log.info.stacktrace = false
runtime.log.invalid.references = true
-
-#----------------------------------------------------------------------------
-# Configuration for the Log4JLogSystem.
-# You must define the runtime.log.logsystem.class property to be:
-# org.apache.velocity.runtime.log.Log4JLogSystem
-#
-# You must also include Log4J's .jar files into your classpath. They are
-# included with the Velocity distribution in the build/lib directory.
-#
-# There are several different options that you can configure.
-# Uncomment the ones that you want and also define their settings.
-#----------------------------------------------------------------------------
-#runtime.log.logsystem.log4j.pattern=%d - %m%n
-#runtime.log.logsystem.log4j.file.size=100000
-#runtime.log.logsystem.log4j.file.backups=1
-#runtime.log.logsystem.log4j.syslogd.host=my.syslog.server.com
-#runtime.log.logsystem.log4j.syslogd.facility=LOG_DAEMON
-#runtime.log.logsystem.log4j.remote.host=my.remote.server.com
-#runtime.log.logsystem.log4j.remote.port=1099
-#runtime.log.logsystem.log4j.email.server=localhost
-#runtime.log.logsystem.log4j.email.from=root@localhost
-#runtime.log.logsystem.log4j.email.to=root@localhost
-#runtime.log.logsystem.log4j.email.subject=Velocity Error Report
-#runtime.log.logsystem.log4j.email.buffer.size=512
#----------------------------------------------------------------------------
# T E M P L A T E E N C O D I N G
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java?rev=292918&r1=292917&r2=292918&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java Fri Sep 30 21:36:58 2005
@@ -367,7 +367,7 @@
}
catch(Exception ee)
{
- rsvc.error("Error getting iterator for #foreach : " + ee.getMessage());
+ rsvc.getLog().error("Error getting iterator for #foreach", ee);
}
if (i == null)
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Include.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Include.java?rev=292918&r1=292917&r2=292918&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Include.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Include.java Fri Sep 30 21:36:58 2005
@@ -140,8 +140,8 @@
}
else
{
- rsvc.error("#include() error : invalid argument type : "
- + n.toString());
+ rsvc.getLog().error("#include() invalid argument type: "
+ + n.toString());
outputErrorToStream( writer, "error with arg " + i
+ " please see log.");
}
@@ -165,7 +165,7 @@
{
if ( node == null )
{
- rsvc.error("#include() error : null argument");
+ rsvc.getLog().error("#include() null argument");
return false;
}
@@ -175,7 +175,7 @@
Object value = node.value( context );
if ( value == null)
{
- rsvc.error("#include() error : null argument");
+ rsvc.getLog().error("#include() null argument");
return false;
}
@@ -210,20 +210,19 @@
/*
* the arg wasn't found. Note it and throw
*/
-
- rsvc.error("#include(): cannot find resource '" + arg +
- "', called from template " +
- context.getCurrentTemplateName() + " at (" +
- getLine() + ", " + getColumn() + ")" );
+ rsvc.getLog().error("#include(): cannot find resource '" + arg +
+ "', called from template " +
+ context.getCurrentTemplateName() + " at (" +
+ getLine() + ", " + getColumn() + ")" );
throw rnfe;
}
catch (Exception e)
{
- rsvc.error("#include(): arg = '" + arg +
- "', called from template " +
- context.getCurrentTemplateName() + " at (" +
- getLine() + ", " + getColumn() + ") : " + e);
+ rsvc.getLog().error("#include(): arg = '" + arg +
+ "', called from template " +
+ context.getCurrentTemplateName() + " at (" +
+ getLine() + ", " + getColumn() + ')', e);
}
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Macro.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Macro.java?rev=292918&r1=292917&r2=292918&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Macro.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Macro.java Fri Sep 30 21:36:58 2005
@@ -135,8 +135,8 @@
* define a block
*/
- rs.error("#macro error : Velocimacro must have name as 1st " +
- "argument to #macro(). #args = " + numArgs);
+ rs.getLog().error("#macro error : Velocimacro must have name as 1st " +
+ "argument to #macro(). #args = " + numArgs);
throw new MacroParseException("First argument to #macro() must be " +
" macro name.");
@@ -193,7 +193,7 @@
StringBuffer msg = new StringBuffer("Failed to add macro: ");
macroToString(msg, argArray);
msg.append(" : source = ").append(sourceTemplate);
- rs.warn(msg.toString());
+ rs.getLog().warn(msg);
}
}
@@ -251,7 +251,7 @@
StringBuffer msg = new StringBuffer("Macro.getArgArray() : nbrArgs=");
msg.append(numArgs).append(" : ");
macroToString(msg, argArray);
- rsvc.debug(msg.toString());
+ rsvc.getLog().debug(msg);
}
return argArray;
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Parse.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Parse.java?rev=292918&r1=292917&r2=292918&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Parse.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/Parse.java Fri Sep 30 21:36:58 2005
@@ -85,7 +85,7 @@
*/
if ( node.jjtGetChild(0) == null)
{
- rsvc.error( "#parse() error : null argument" );
+ rsvc.getLog().error("#parse() null argument");
return false;
}
@@ -96,7 +96,7 @@
if ( value == null)
{
- rsvc.error( "#parse() error : null argument" );
+ rsvc.getLog().error("#parse() null argument");
return false;
}
@@ -137,8 +137,9 @@
path.append( " > " + templateStack[i] );
}
- rsvc.error( "Max recursion depth reached (" +
- templateStack.length + ")" + " File stack:" + path );
+ rsvc.getLog().error("Max recursion depth reached (" +
+ templateStack.length + ')' + " File stack:" +
+ path);
return false;
}
@@ -158,11 +159,10 @@
/*
* the arg wasn't found. Note it and throw
*/
-
- rsvc.error("#parse(): cannot find template '" + arg +
- "', called from template " +
- context.getCurrentTemplateName() + " at (" +
- getLine() + ", " + getColumn() + ")" );
+ rsvc.getLog().error("#parse(): cannot find template '" + arg +
+ "', called from template " +
+ context.getCurrentTemplateName() + " at (" +
+ getLine() + ", " + getColumn() + ")" );
throw rnfe;
}
catch ( ParseErrorException pee )
@@ -172,16 +172,16 @@
* note it and throw
*/
- rsvc.error("#parse(): syntax error in #parse()-ed template '" +
- arg + "', called from template " +
- context.getCurrentTemplateName() + " at (" +
- getLine() + ", " + getColumn() + ")" );
+ rsvc.getLog().error("#parse(): syntax error in #parse()-ed template '"
+ + arg + "', called from template " +
+ context.getCurrentTemplateName() + " at (" +
+ getLine() + ", " + getColumn() + ")" );
throw pee;
}
catch ( Exception e)
{
- rsvc.error("#parse() : arg = " + arg + ". Exception : " + e);
+ rsvc.getLog().error("#parse() : arg = " + arg + '.', e);
return false;
}
@@ -206,7 +206,7 @@
throw (MethodInvocationException) e;
}
- rsvc.error( "Exception rendering #parse( " + arg + " ) : " + e );
+ rsvc.getLog().error("Exception rendering #parse(" + arg + ')', e);
return false;
}
finally
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/VMProxyArg.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/VMProxyArg.java?rev=292918&r1=292917&r2=292918&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/VMProxyArg.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/VMProxyArg.java Fri Sep 30 21:36:58 2005
@@ -22,6 +22,7 @@
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.context.InternalContextAdapterImpl;
+import org.apache.velocity.runtime.log.Log;
import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.runtime.parser.node.ASTReference;
import org.apache.velocity.runtime.parser.ParserTreeConstants;
@@ -106,6 +107,7 @@
private final int GENERALSTATIC = -1;
private RuntimeServices rsvc = null;
+ private Log log = null;
/**
* ctor for current impl
@@ -120,6 +122,7 @@
public VMProxyArg( RuntimeServices rs, String contextRef, String callerRef, int t )
{
rsvc = rs;
+ log = rsvc.getLog();
contextReference = contextRef;
callerReference = callerRef;
@@ -193,7 +196,7 @@
}
catch( MethodInvocationException mie )
{
- rsvc.error("VMProxyArg.getObject() : method invocation error setting value : " + mie );
+ log.error("VMProxyArg.getObject() : method invocation error setting value", mie);
}
}
else
@@ -220,8 +223,8 @@
type = GENERALSTATIC;
staticObject = o;
- rsvc.error("VMProxyArg.setObject() : Programmer error : I am a constant! No setting! : "
- + contextReference + " / " + callerReference);
+ log.error("VMProxyArg.setObject() : Programmer error : I am a constant! No setting! : "
+ + contextReference + " / " + callerReference);
}
return null;
@@ -318,7 +321,7 @@
}
catch (Exception e )
{
- rsvc.error("VMProxyArg.getObject() : error rendering reference : " + e );
+ log.error("VMProxyArg.getObject() : error rendering reference", e);
}
}
else if( type == GENERALSTATIC )
@@ -327,7 +330,9 @@
}
else
{
- rsvc.error("Unsupported VM arg type : VM arg = " + callerReference +" type = " + type + "( VMProxyArg.getObject() )");
+ log.error("Unsupported VM arg type : VM arg = " +
+ callerReference +" type = " + type +
+ "( VMProxyArg.getObject() )");
}
return retObject;
@@ -341,7 +346,7 @@
* I can think of
*/
- rsvc.error("VMProxyArg.getObject() : method invocation error getting value : " + mie );
+ log.error("VMProxyArg.getObject() : method invocation error getting value", mie);
return null;
}
@@ -399,7 +404,7 @@
if ( nodeTree != null && nodeTree.getType() != type )
{
- rsvc.error( "VMProxyArg.setup() : programmer error : type doesn't match node type.");
+ log.error("VMProxyArg.setup() : programmer error : type doesn't match node type.");
}
/*
@@ -416,8 +421,8 @@
}
catch ( Exception e )
{
- rsvc.error("VMProxyArg.setup() : exception " + callerReference +
- " : " + StringUtils.stackTrace(e));
+ log.error("VMProxyArg.setup() : exception " +
+ callerReference, e);
}
break;
@@ -457,8 +462,8 @@
* this is technically an error...
*/
- rsvc.error("Unsupported arg type : " + callerReference
- + " You most likely intended to call a VM with a string literal, so enclose with ' or \" characters. (VMProxyArg.setup())");
+ log.error("Unsupported arg type : " + callerReference +
+ " You most likely intended to call a VM with a string literal, so enclose with ' or \" characters. (VMProxyArg.setup())");
constant = true;
staticObject = new String( callerReference );
@@ -467,8 +472,8 @@
default :
{
- rsvc.error(" VMProxyArg.setup() : unsupported type : "
- + callerReference );
+ log.error("VMProxyArg.setup() : unsupported type : "
+ + callerReference );
}
}
}
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java?rev=292918&r1=292917&r2=292918&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java Fri Sep 30 21:36:58 2005
@@ -173,7 +173,7 @@
}
else
{
- rsvc.error( "VM error : " + macroName + ". Null AST");
+ rsvc.getLog().error("VM error " + macroName + ". Null AST");
}
}
catch ( Exception e )
@@ -187,8 +187,8 @@
throw (MethodInvocationException) e;
}
- rsvc.error("VelocimacroProxy.render() : exception VM = #" + macroName +
- "() : " + StringUtils.stackTrace(e));
+ rsvc.getLog().error("VelocimacroProxy.render() : exception VM = #" +
+ macroName + "()", e);
}
return true;
@@ -216,10 +216,10 @@
if ( getNumArgs() != i )
{
- rsvc.error("VM #" + macroName + ": error : too "
- + ( (getNumArgs() > i) ? "few" : "many") + " arguments to macro. Wanted "
- + getNumArgs() + " got " + i );
-
+ rsvc.getLog().error("VM #" + macroName + ": error : too " +
+ ((getNumArgs() > i) ? "few" : "many") +
+ " arguments to macro. Wanted " + getNumArgs() +
+ " got " + i);
return;
}
@@ -302,8 +302,8 @@
}
catch ( Exception e )
{
- rsvc.error("VelocimacroManager.parseTree() : exception " + macroName +
- " : " + StringUtils.stackTrace(e));
+ rsvc.getLog().error("VelocimacroManager.parseTree() : exception " +
+ macroName, e);
}
}
Added: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/AvalonLogChute.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/AvalonLogChute.java?rev=292918&view=auto
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/AvalonLogChute.java (added)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/AvalonLogChute.java Fri Sep 30 21:36:58 2005
@@ -0,0 +1,223 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.velocity.runtime.log;
+
+import java.io.File;
+import org.apache.log.Priority;
+import org.apache.log.Logger;
+import org.apache.log.Hierarchy;
+import org.apache.log.LogTarget;
+import org.apache.log.output.io.FileTarget;
+import org.apache.velocity.runtime.RuntimeServices;
+import org.apache.velocity.runtime.RuntimeConstants;
+
+/**
+ * Implementation of a Avalon logger.
+ *
+ * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
+ * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
+ * @author <a href="mailto:nbubna@apache.org">Nathan Bubna</a>
+ * @version $Id: AvalonLogChute.java 292075 2005-09-28 00:08:12Z dlr $
+ */
+public class AvalonLogChute implements LogChute
+{
+ private Logger logger = null;
+
+ private RuntimeServices rsvc = null;
+
+ /**
+ * default CTOR. Initializes itself using the property RUNTIME_LOG
+ * from the Velocity properties
+ */
+
+ public AvalonLogChute()
+ {
+ }
+
+ public void init( RuntimeServices rs )
+ throws Exception
+ {
+ this.rsvc = rs;
+
+ /*
+ * if a logger is specified, we will use this instead of
+ * the default
+ */
+ String loggerName = (String) rsvc.getProperty("runtime.log.logsystem.avalon.logger");
+
+ if (loggerName != null)
+ {
+ this.logger = Hierarchy.getDefaultHierarchy().getLoggerFor(loggerName);
+ }
+ else
+ {
+ /*
+ * since this is a Velocity-provided logger, we will
+ * use the Runtime configuration
+ */
+ String logfile = (String) rsvc.getProperty( RuntimeConstants.RUNTIME_LOG );
+
+ /*
+ * now init. If we can't, panic!
+ */
+ try
+ {
+ init( logfile );
+
+ log( 0,
+ "AvalonLogChute initialized using logfile '" + logfile + "'" );
+ }
+ catch( Exception e )
+ {
+ System.err.println(
+ "PANIC : Error configuring AvalonLogChute : " + e );
+
+ throw new Exception("Unable to configure AvalonLogChute : " + e );
+ }
+ }
+ }
+
+ /**
+ * initializes the log system using the logfile argument
+ *
+ * @param logFile file for log messages
+ */
+ public void init(String logFile)
+ throws Exception
+ {
+
+ /*
+ * make our FileTarget. Note we are going to keep the
+ * default behavior of not appending...
+ */
+ FileTarget target = new FileTarget( new File( logFile),
+ false,
+ new VelocityFormatter("%{time} %{message}\\n%{throwable}" ) );
+
+ /*
+ * use the toString() of RuntimeServices to make a unique logger
+ */
+
+ logger = Hierarchy.getDefaultHierarchy().getLoggerFor( rsvc.toString() );
+ logger.setPriority( Priority.DEBUG );
+ logger.setLogTargets( new LogTarget[] { target } );
+ }
+
+ /**
+ * logs messages
+ *
+ * @param level severity level
+ * @param message complete error message
+ */
+ public void log(int level, String message)
+ {
+ /*
+ * based on level, call teh right logger method
+ * and prefix with the appropos prefix
+ */
+
+ switch (level)
+ {
+ case LogChute.WARN_ID:
+ logger.warn( RuntimeConstants.WARN_PREFIX + message );
+ break;
+ case LogChute.INFO_ID:
+ logger.info( RuntimeConstants.INFO_PREFIX + message);
+ break;
+ case LogChute.DEBUG_ID:
+ logger.debug( RuntimeConstants.DEBUG_PREFIX + message);
+ break;
+ case LogChute.TRACE_ID:
+ logger.debug(RuntimeConstants.TRACE_PREFIX + message);
+ break;
+ case LogChute.ERROR_ID:
+ logger.error(RuntimeConstants.ERROR_PREFIX + message);
+ break;
+ default:
+ logger.info( message);
+ break;
+ }
+ }
+
+ /**
+ * logs messages and error
+ *
+ * @param level severity level
+ * @param message complete error message
+ */
+ public void log(int level, String message, Throwable t)
+ {
+ switch (level)
+ {
+ case LogChute.WARN_ID:
+ logger.warn(RuntimeConstants.WARN_PREFIX + message, t);
+ break;
+ case LogChute.INFO_ID:
+ logger.info(RuntimeConstants.INFO_PREFIX + message, t);
+ break;
+ case LogChute.DEBUG_ID:
+ logger.debug(RuntimeConstants.DEBUG_PREFIX + message, t);
+ break;
+ case LogChute.TRACE_ID:
+ logger.debug(RuntimeConstants.TRACE_PREFIX + message, t);
+ break;
+ case LogChute.ERROR_ID:
+ logger.error(RuntimeConstants.ERROR_PREFIX + message, t);
+ break;
+ default:
+ logger.info(message, t);
+ break;
+ }
+ }
+
+ /**
+ * Checks to see whether the specified level is enabled.
+ */
+ public boolean isLevelEnabled(int level)
+ {
+ switch (level)
+ {
+ case LogChute.DEBUG_ID:
+ return logger.isDebugEnabled();
+ case LogChute.INFO_ID:
+ return logger.isInfoEnabled();
+ case LogChute.TRACE_ID:
+ return logger.isDebugEnabled();
+ case LogChute.WARN_ID:
+ return logger.isWarnEnabled();
+ case LogChute.ERROR_ID:
+ return logger.isErrorEnabled();
+ default:
+ return true;
+ }
+ }
+
+ /**
+ * Also do a shutdown if the object is destroy()'d.
+ */
+ protected void finalize() throws Throwable
+ {
+ shutdown();
+ }
+
+ /** Close all destinations*/
+ public void shutdown()
+ {
+ logger.unsetLogTargets();
+ }
+
+}
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/AvalonLogSystem.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/AvalonLogSystem.java?rev=292918&r1=292917&r2=292918&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/AvalonLogSystem.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/AvalonLogSystem.java Fri Sep 30 21:36:58 2005
@@ -1,7 +1,5 @@
-package org.apache.velocity.runtime.log;
-
/*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
@@ -16,16 +14,7 @@
* limitations under the License.
*/
-import java.io.File;
-
-import org.apache.log.Priority;
-import org.apache.log.Logger;
-import org.apache.log.Hierarchy;
-import org.apache.log.LogTarget;
-import org.apache.log.output.io.FileTarget;
-
-import org.apache.velocity.runtime.RuntimeServices;
-import org.apache.velocity.runtime.RuntimeConstants;
+package org.apache.velocity.runtime.log;
/**
* Implementation of a Avalon logger.
@@ -34,120 +23,13 @@
* @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
* @version $Id$
*/
-public class AvalonLogSystem implements LogSystem
+public class AvalonLogSystem extends AvalonLogChute implements LogSystem
{
- private Logger logger = null;
-
- private RuntimeServices rsvc = null;
-
- /**
- * default CTOR. Initializes itself using the property RUNTIME_LOG
- * from the Velocity properties
- */
-
- public AvalonLogSystem()
- {
- }
-
- public void init( RuntimeServices rs )
- throws Exception
- {
- this.rsvc = rs;
-
- /*
- * if a logger is specified, we will use this instead of
- * the default
- */
- String loggerName = (String) rsvc.getProperty("runtime.log.logsystem.avalon.logger");
-
- if (loggerName != null)
- {
- this.logger = Hierarchy.getDefaultHierarchy().getLoggerFor(loggerName);
- }
- else
- {
- /*
- * since this is a Velocity-provided logger, we will
- * use the Runtime configuration
- */
- String logfile = (String) rsvc.getProperty( RuntimeConstants.RUNTIME_LOG );
-
- /*
- * now init. If we can't, panic!
- */
- try
- {
- init( logfile );
-
- logVelocityMessage( 0,
- "AvalonLogSystem initialized using logfile '" + logfile + "'" );
- }
- catch( Exception e )
- {
- System.err.println(
- "PANIC : Error configuring AvalonLogSystem : " + e );
-
- throw new Exception("Unable to configure AvalonLogSystem : " + e );
- }
- }
- }
-
/**
- * initializes the log system using the logfile argument
- *
- * @param logFile file for log messages
- */
- public void init(String logFile)
- throws Exception
- {
-
- /*
- * make our FileTarget. Note we are going to keep the
- * default behavior of not appending...
- */
- FileTarget target = new FileTarget( new File( logFile),
- false,
- new VelocityFormatter("%{time} %{message}\\n%{throwable}" ) );
-
- /*
- * use the toString() of RuntimeServices to make a unique logger
- */
-
- logger = Hierarchy.getDefaultHierarchy().getLoggerFor( rsvc.toString() );
- logger.setPriority( Priority.DEBUG );
- logger.setLogTargets( new LogTarget[] { target } );
- }
-
- /**
- * logs messages
- *
- * @param level severity level
- * @param message complete error message
+ * @deprecated Use log(level, message).
*/
public void logVelocityMessage(int level, String message)
{
- /*
- * based on level, call teh right logger method
- * and prefix with the appropos prefix
- */
-
- switch (level)
- {
- case LogSystem.WARN_ID:
- logger.warn( RuntimeConstants.WARN_PREFIX + message );
- break;
- case LogSystem.INFO_ID:
- logger.info( RuntimeConstants.INFO_PREFIX + message);
- break;
- case LogSystem.DEBUG_ID:
- logger.debug( RuntimeConstants.DEBUG_PREFIX + message);
- break;
- case LogSystem.ERROR_ID:
- logger.error(RuntimeConstants.ERROR_PREFIX + message);
- break;
- default:
- logger.info( message);
- break;
- }
+ log(level, message);
}
}
Added: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/HoldingLogChute.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/HoldingLogChute.java?rev=292918&view=auto
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/HoldingLogChute.java (added)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/HoldingLogChute.java Fri Sep 30 21:36:58 2005
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.velocity.runtime.log;
+
+import java.util.Vector;
+import java.util.Iterator;
+import org.apache.velocity.runtime.RuntimeServices;
+
+/**
+ * Pre-init logger. I believe that this was suggested by
+ * Carsten Ziegeler <cz...@sundn.de> and
+ * Jeroen C. van Gelderen. If this isn't correct, let me
+ * know as this was a good idea...
+ *
+ * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
+ * @author <a href="mailto:nbubna@apache.org">Nathan Bubna</a>
+ * @version $Id: PrimordialLogChute.java 291677 2005-09-26 17:04:21Z henning $
+ */
+public class HoldingLogChute implements LogChute
+{
+ private Vector pendingMessages = new Vector();
+
+ public void init(RuntimeServices rs) throws Exception
+ {
+ }
+
+ /**
+ * Logs messages. All we do is store them until 'later'.
+ *
+ * @param level severity level
+ * @param message complete error message
+ */
+ public void log(int level, String message)
+ {
+ synchronized(this)
+ {
+ Object[] data = new Object[2];
+ data[0] = new Integer(level);
+ data[1] = message;
+ pendingMessages.addElement(data);
+ }
+ }
+
+ /**
+ * Logs messages and errors. All we do is store them until 'later'.
+ *
+ * @param level severity level
+ * @param message complete error message
+ * @param t the accompanying java.lang.Throwable
+ */
+ public void log(int level, String message, Throwable t)
+ {
+ synchronized(this)
+ {
+ Object[] data = new Object[3];
+ data[0] = new Integer(level);
+ data[1] = message;
+ data[2] = t;
+ pendingMessages.addElement(data);
+ }
+ }
+
+ /**
+ * This will always return true.
+ */
+ public boolean isLevelEnabled(int level)
+ {
+ return true;
+ }
+
+ /**
+ * Dumps the log messages this chute is holding into a new chute
+ */
+ public void transferTo(LogChute newChute)
+ {
+ synchronized(this)
+ {
+ if (!pendingMessages.isEmpty())
+ {
+ // iterate and log each individual message...
+ for(Iterator i = pendingMessages.iterator(); i.hasNext();)
+ {
+ Object[] data = (Object[])i.next();
+ int level = ((Integer)data[0]).intValue();
+ String message = (String)data[1];
+ if (data.length == 2)
+ {
+ newChute.log(level, message);
+ }
+ else
+ {
+ newChute.log(level, message, (Throwable)data[2]);
+ }
+ }
+ }
+ }
+ }
+
+}
Added: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/JdkLogChute.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/JdkLogChute.java?rev=292918&view=auto
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/JdkLogChute.java (added)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/JdkLogChute.java Fri Sep 30 21:36:58 2005
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.velocity.runtime.log;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.velocity.runtime.RuntimeServices;
+
+/**
+ * Implementation of a simple java.util.logging LogChute.
+ *
+ * @author <a href="mailto:nbubna@apache.org>Nathan Bubna</a>
+ * @version $Id: JdkLogChute.java 291585 2005-09-26 08:56:23Z henning $
+ * @since Velocity 1.5
+ */
+public class JdkLogChute implements LogChute
+{
+ /** Property key for specifying the name for the logger instance */
+ public static final String RUNTIME_LOG_JDK_LOGGER =
+ "runtime.log.logsystem.jdk.logger";
+
+ /** Default name for the JDK logger instance */
+ public static final String DEFAULT_LOG_NAME = "org.apache.velocity";
+
+ protected Logger logger = null;
+
+ public void init(RuntimeServices rs)
+ {
+ String name = (String)rs.getProperty(RUNTIME_LOG_JDK_LOGGER);
+ if (name == null)
+ {
+ name = DEFAULT_LOG_NAME;
+ }
+ logger = Logger.getLogger(name);
+ log(LogChute.DEBUG_ID, "JdkLogChute will use logger '"+name+'\'');
+ }
+
+ /**
+ * Returns the java.util.logging.Level that matches
+ * to the specified LogChute level.
+ */
+ protected Level getJdkLevel(int level)
+ {
+ switch (level)
+ {
+ case LogChute.WARN_ID:
+ return Level.WARNING;
+ case LogChute.INFO_ID:
+ return Level.INFO;
+ case LogChute.DEBUG_ID:
+ return Level.FINE;
+ case LogChute.TRACE_ID:
+ return Level.FINEST;
+ case LogChute.ERROR_ID:
+ return Level.SEVERE;
+ default:
+ return Level.FINER;
+ }
+ }
+
+ /**
+ * Logs messages
+ *
+ * @param level severity level
+ * @param message complete error message
+ */
+ public void log(int level, String message)
+ {
+ log(level, message, null);
+ }
+
+ /**
+ * Send a log message from Velocity along with an exception or error
+ */
+ public void log(int level, String message, Throwable t)
+ {
+ Level jdkLevel = getJdkLevel(level);
+ if (t == null)
+ {
+ logger.log(jdkLevel, message);
+ }
+ else
+ {
+ logger.log(jdkLevel, message, t);
+ }
+ }
+
+ /**
+ * Checks whether the logger is enabled for the specified level
+ */
+ public boolean isLevelEnabled(int level)
+ {
+ Level jdkLevel = getJdkLevel(level);
+ return logger.isLoggable(jdkLevel);
+ }
+
+}
Added: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/Log.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/Log.java?rev=292918&view=auto
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/Log.java (added)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/Log.java Fri Sep 30 21:36:58 2005
@@ -0,0 +1,232 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.velocity.runtime.log;
+
+import org.apache.velocity.util.StringUtils;
+
+/**
+ * Convenient wrapper for LogChute functions. This implements
+ * the RuntimeLogger methods (and then some). It is hoped that
+ * use of this will fully replace use of the RuntimeLogger.
+ *
+ * @author <a href="mailto:nbubna@apache.org">Nathan Bubna</a>
+ * @version $Id: Log.java 291585 2005-09-26 08:56:23Z henning $
+ */
+public class Log
+{
+
+ private LogChute chute;
+ private boolean showStacks;
+
+ /**
+ * Creates a new Log that wraps a HoldingLogChute.
+ */
+ public Log()
+ {
+ this.chute = new HoldingLogChute();
+ }
+
+ /**
+ * Creates a new Log that wraps the specified LogChute.
+ */
+ public Log(LogChute chute)
+ {
+ if (chute == null)
+ {
+ throw new NullPointerException("The LogChute cannot be set to null!");
+ }
+ this.chute = chute;
+ }
+
+ /**
+ * Updates the LogChute wrapped by this Log instance.
+ */
+ protected void setLogChute(LogChute newLogChute)
+ {
+ this.chute = newLogChute;
+ }
+
+ /**
+ * Returns the LogChute wrapped by this Log instance.
+ */
+ protected LogChute getLogChute()
+ {
+ return this.chute;
+ }
+
+ /**
+ * Sets whether or not Throwables passed as messages
+ * (not to be confused with passing them as Throwables)
+ * will have their whole stack traces printed or not.
+ */
+ protected void setShowStackTraces(boolean showStacks)
+ {
+ this.showStacks = showStacks;
+ }
+
+ /**
+ * Tells whether or not Throwables passed as messages
+ * (not to be confused with passing them as Throwables)
+ * will have their whole stack traces printed or not.
+ */
+ public boolean getShowStackTraces()
+ {
+ return this.showStacks;
+ }
+
+ private void log(int level, Object message)
+ {
+ String out;
+ /* now, see if the logging stacktrace is on
+ * and modify the message to suit */
+ if (showStacks && message instanceof Throwable)
+ {
+ out = StringUtils.stackTrace((Throwable)message);
+ }
+ else
+ {
+ out = String.valueOf(message);
+ }
+ chute.log(level, out);
+ }
+
+ private void log(int level, Object message, Throwable t)
+ {
+ chute.log(level, String.valueOf(message), t);
+ }
+
+ /**
+ * Returns true if trace level messages will be printed by the LogChute.
+ */
+ public boolean isTraceEnabled()
+ {
+ return chute.isLevelEnabled(LogChute.TRACE_ID);
+ }
+
+ /**
+ * Log a trace message.
+ */
+ public void trace(Object message)
+ {
+ log(LogChute.TRACE_ID, message);
+ }
+
+ /**
+ * Log a trace message and accompanying Throwable.
+ */
+ public void trace(Object message, Throwable t)
+ {
+ log(LogChute.TRACE_ID, message, t);
+ }
+
+ /**
+ * Returns true if debug level messages will be printed by the LogChute.
+ */
+ public boolean isDebugEnabled()
+ {
+ return chute.isLevelEnabled(LogChute.DEBUG_ID);
+ }
+
+ /**
+ * Log a debug message.
+ */
+ public void debug(Object message)
+ {
+ log(LogChute.DEBUG_ID, message);
+ }
+
+ /**
+ * Log a debug message and accompanying Throwable.
+ */
+ public void debug(Object message, Throwable t)
+ {
+ log(LogChute.DEBUG_ID, message, t);
+ }
+
+ /**
+ * Returns true if info level messages will be printed by the LogChute.
+ */
+ public boolean isInfoEnabled()
+ {
+ return chute.isLevelEnabled(LogChute.INFO_ID);
+ }
+
+ /**
+ * Log an info message.
+ */
+ public void info(Object message)
+ {
+ log(LogChute.INFO_ID, message);
+ }
+
+ /**
+ * Log an info message and accompanying Throwable.
+ */
+ public void info(Object message, Throwable t)
+ {
+ log(LogChute.INFO_ID, message, t);
+ }
+
+ /**
+ * Returns true if warn level messages will be printed by the LogChute.
+ */
+ public boolean isWarnEnabled()
+ {
+ return chute.isLevelEnabled(LogChute.WARN_ID);
+ }
+
+ /**
+ * Log a warning message.
+ */
+ public void warn(Object message)
+ {
+ log(LogChute.WARN_ID, message);
+ }
+
+ /**
+ * Log a warning message and accompanying Throwable.
+ */
+ public void warn(Object message, Throwable t)
+ {
+ log(LogChute.WARN_ID, message, t);
+ }
+
+ /**
+ * Returns true if error level messages will be printed by the LogChute.
+ */
+ public boolean isErrorEnabled()
+ {
+ return chute.isLevelEnabled(LogChute.ERROR_ID);
+ }
+
+ /**
+ * Log an error message.
+ */
+ public void error(Object message)
+ {
+ log(LogChute.ERROR_ID, message);
+ }
+
+ /**
+ * Log an error message and accompanying Throwable.
+ */
+ public void error(Object message, Throwable t)
+ {
+ log(LogChute.ERROR_ID, message, t);
+ }
+
+}
Added: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/Log4JLogChute.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/Log4JLogChute.java?rev=292918&view=auto
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/Log4JLogChute.java (added)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/Log4JLogChute.java Fri Sep 30 21:36:58 2005
@@ -0,0 +1,247 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.velocity.runtime.log;
+
+import java.lang.reflect.Field;
+import org.apache.log4j.Logger;
+import org.apache.log4j.RollingFileAppender;
+import org.apache.log4j.PatternLayout;
+import org.apache.log4j.Level;
+import org.apache.velocity.runtime.RuntimeConstants;
+import org.apache.velocity.runtime.RuntimeServices;
+
+/**
+ * Implementation of a simple log4j system that will either latch onto
+ * an existing category, or just do a simple rolling file log.
+ *
+ * Use this one rather than {@link SimpleLog4JLogSystem}; it uses the
+ * modern <code>Logger</code> concept of Log4J, rather than the
+ * deprecated <code>Categeory</code> concept.
+ *
+ * @author <a href="mailto:geirm@apache.org>Geir Magnusson Jr.</a>
+ * @author <a href="mailto:dlr@finemaltcoding.com>Daniel L. Rall</a>
+ * @author <a href="mailto:nbubna@apache.org>Nathan Bubna</a>
+ * @version $Id: Log4JLogChute.java 292075 2005-09-28 00:08:12Z dlr $
+ * @since Velocity 1.5
+ */
+public class Log4JLogChute implements LogChute
+{
+ public static final String RUNTIME_LOG_LOG4J_LOGGER =
+ "runtime.log.logsystem.log4j.logger";
+
+ private RuntimeServices rsvc = null;
+ private boolean hasTrace = false;
+ private RollingFileAppender appender = null;
+
+ /**
+ * <a href="http://jakarta.apache.org/log4j/">Log4J</a> logging API.
+ */
+ protected Logger logger = null;
+
+ public void init(RuntimeServices rs)
+ {
+ rsvc = rs;
+
+ /* first see if there is a category specified and just use that - it allows
+ * the application to make us use an existing logger
+ */
+ String loggerName = (String)rsvc.getProperty(RUNTIME_LOG_LOG4J_LOGGER);
+ if (loggerName != null)
+ {
+ logger = Logger.getLogger(loggerName);
+
+ log(0, "Log4JLogChute using logger '"
+ + loggerName + '\'');
+ }
+ else
+ {
+ // if not, use the file...
+ String logfile = rsvc.getString(RuntimeConstants.RUNTIME_LOG);
+
+ // now init. If we can't, panic!
+ try
+ {
+ internalInit(logfile);
+ log(0, "Log4JLogChute initialized using logfile '" + logfile + "'");
+ }
+ catch(Exception e)
+ {
+ System.err.println("PANIC: error configuring Log4JLogChute - " + e);
+ }
+ }
+
+ /* Ok, now let's see if this version of log4j supports the trace level. */
+ try
+ {
+ Field traceLevel = Level.class.getField("TRACE");
+ if (traceLevel != null)
+ {
+ hasTrace = true;
+ }
+ }
+ catch (NoSuchFieldException e)
+ {
+ log(0, "The version of log4j being used does not support the \"trace\" level.");
+ }
+ }
+
+ /*
+ * initializes the log system using the logfile argument
+ */
+ private void internalInit(String logfile) throws Exception
+ {
+ /* do it by our classname to avoid conflicting with anything else
+ * that might be used...
+ */
+ logger = Logger.getLogger(this.getClass().getName());
+ logger.setAdditivity(false);
+
+ /* Priority is set for DEBUG becouse this implementation checks
+ * log level. */
+ logger.setLevel(Level.DEBUG);
+
+ this.appender =
+ new RollingFileAppender(new PatternLayout("%d - %m%n"),
+ logfile, true);
+
+ appender.setMaxBackupIndex(1);
+ appender.setMaximumFileSize(100000);
+ logger.addAppender(appender);
+ }
+
+ /**
+ * logs messages
+ *
+ * @param level severity level
+ * @param message complete error message
+ */
+ public void log(int level, String message)
+ {
+ switch (level)
+ {
+ case LogChute.WARN_ID:
+ logger.warn(message);
+ break;
+ case LogChute.INFO_ID:
+ logger.info(message);
+ break;
+ case LogChute.DEBUG_ID:
+ logger.debug(message);
+ break;
+ case LogChute.TRACE_ID:
+ if (hasTrace)
+ {
+ logger.trace(message);
+ }
+ else
+ {
+ logger.debug(message);
+ }
+ break;
+ case LogChute.ERROR_ID:
+ logger.error(message);
+ break;
+ default:
+ logger.debug(message);
+ break;
+ }
+ }
+
+ /**
+ * Send a log message from Velocity along with an exception or error
+ */
+ public void log(int level, String message, Throwable t)
+ {
+ switch (level)
+ {
+ case LogChute.WARN_ID:
+ logger.warn(message, t);
+ break;
+ case LogChute.INFO_ID:
+ logger.info(message, t);
+ break;
+ case LogChute.DEBUG_ID:
+ logger.debug(message, t);
+ break;
+ case LogChute.TRACE_ID:
+ if (hasTrace)
+ {
+ logger.trace(message, t);
+ }
+ else
+ {
+ logger.debug(message, t);
+ }
+ break;
+ case LogChute.ERROR_ID:
+ logger.error(message, t);
+ break;
+ default:
+ logger.debug(message, t);
+ break;
+ }
+ }
+
+ /**
+ * Checks whether the logger is enabled for the specified level
+ */
+ public boolean isLevelEnabled(int level)
+ {
+ switch (level)
+ {
+ case LogChute.DEBUG_ID:
+ return logger.isDebugEnabled();
+ case LogChute.INFO_ID:
+ return logger.isInfoEnabled();
+ case LogChute.TRACE_ID:
+ if (hasTrace)
+ {
+ return logger.isTraceEnabled();
+ }
+ else
+ {
+ return logger.isDebugEnabled();
+ }
+ case LogChute.WARN_ID:
+ return logger.isEnabledFor(Level.WARN);
+ case LogChute.ERROR_ID:
+ // can't be disabled in log4j
+ return logger.isEnabledFor(Level.ERROR);
+ default:
+ return true;
+ }
+ }
+
+ /**
+ * Also do a shutdown if the object is destroy()'d.
+ */
+ protected void finalize() throws Throwable
+ {
+ shutdown();
+ }
+
+ /** Close all destinations*/
+ public void shutdown()
+ {
+ if (appender != null)
+ {
+ logger.removeAppender(appender);
+ appender.close();
+ }
+ }
+
+}
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/Log4JLogSystem.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/Log4JLogSystem.java?rev=292918&r1=292917&r2=292918&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/Log4JLogSystem.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/Log4JLogSystem.java Fri Sep 30 21:36:58 2005
@@ -1,7 +1,5 @@
-package org.apache.velocity.runtime.log;
-
/*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
@@ -16,16 +14,7 @@
* limitations under the License.
*/
-import java.util.Enumeration;
-
-import org.apache.log4j.Logger;
-import org.apache.log4j.RollingFileAppender;
-import org.apache.log4j.PatternLayout;
-import org.apache.log4j.Level;
-import org.apache.log4j.Appender;
-
-import org.apache.velocity.runtime.RuntimeConstants;
-import org.apache.velocity.runtime.RuntimeServices;
+package org.apache.velocity.runtime.log;
/**
* Implementation of a simple log4j system that will either latch onto
@@ -37,151 +26,18 @@
*
* @author <a href="mailto:geirm@apache.org>Geir Magnusson Jr.</a>
* @author <a href="mailto:dlr@finemaltcoding.com>Daniel L. Rall</a>
+ * @author <a href="mailto:nbubna@apache.org>Nathan Bubna</a>
* @version $Id$
+ * @deprecated Use Log4JLogChute instead.
* @since Velocity 1.5
*/
-public class Log4JLogSystem implements LogSystem
+public class Log4JLogSystem extends Log4JLogChute implements LogSystem
{
- public static final String RUNTIME_LOG_LOG4J_LOGGER =
- "runtime.log.logsystem.log4j.logger";
-
- private RuntimeServices rsvc = null;
-
- /**
- * <a href="http://jakarta.apache.org/log4j/">Log4J</a>
- * logging API.
- */
- protected Logger logger = null;
-
/**
- * <a href="http://jakarta.apache.org/log4j/">Log4J</a>
- * logging API.
- */
- public Log4JLogSystem()
- {
- }
-
- public void init(RuntimeServices rs)
- {
- rsvc = rs;
-
- /*
- * first see if there is a category specified and just use that - it allows
- * the application to make us use an existing logger
- */
-
- String loggerName =
- (String) rsvc.getProperty(RUNTIME_LOG_LOG4J_LOGGER);
-
- if (loggerName != null)
- {
- logger = Logger.getLogger(loggerName);
-
- logVelocityMessage(0,
- "SimpleLog4JLogSystem using logger '"
- + loggerName + '\'');
-
- return;
- }
-
- /*
- * if not, use the file...
- */
-
- String logfile = rsvc.getString(RuntimeConstants.RUNTIME_LOG);
-
- /*
- * now init. If we can't, panic!
- */
- try
- {
- internalInit(logfile);
-
- logVelocityMessage(0,
- "Log4JLogSystem initialized using logfile '" + logfile + "'");
- }
- catch(Exception e)
- {
- System.err.println(
- "PANIC : error configuring Log4JLogSystem : " + e);
- }
- }
-
- /**
- * initializes the log system using the logfile argument
- */
- private void internalInit(String logfile)
- throws Exception
- {
- /*
- * do it by our classname to avoid conflicting with anything else
- * that might be used...
- */
-
- logger = Logger.getLogger(this.getClass().getName());
- logger.setAdditivity(false);
-
- /*
- * Priority is set for DEBUG becouse this implementation checks
- * log level.
- */
- logger.setLevel(Level.DEBUG);
-
- RollingFileAppender appender = new RollingFileAppender(
- new PatternLayout( "%d - %m%n"), logfile, true);
-
- appender.setMaxBackupIndex(1);
-
- appender.setMaximumFileSize(100000);
-
- logger.addAppender(appender);
- }
-
- /**
- * logs messages
- *
- * @param level severity level
- * @param message complete error message
+ * @deprecated Use log(level, message).
*/
public void logVelocityMessage(int level, String message)
{
- switch (level)
- {
- case LogSystem.WARN_ID:
- logger.warn(message);
- break;
- case LogSystem.INFO_ID:
- logger.info(message);
- break;
- case LogSystem.DEBUG_ID:
- logger.debug(message);
- break;
- case LogSystem.ERROR_ID:
- logger.error(message);
- break;
- default:
- logger.debug(message);
- break;
- }
- }
-
- /**
- * Also do a shutdown if the object is destroy()'d.
- */
- protected void finalize()
- throws Throwable
- {
- shutdown();
- }
-
- /** Close all destinations*/
- public void shutdown()
- {
- Enumeration appenders = logger.getAllAppenders();
- while (appenders.hasMoreElements())
- {
- Appender appender = (Appender)appenders.nextElement();
- appender.close();
- }
+ log(level, message);
}
}
Added: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/LogChute.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/LogChute.java?rev=292918&view=auto
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/LogChute.java (added)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/log/LogChute.java Fri Sep 30 21:36:58 2005
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.velocity.runtime.log;
+
+import org.apache.velocity.runtime.RuntimeServices;
+
+/**
+ * Base interface that logging systems need to implement. This
+ * is the blessed descendant of the old LogSystem interface.
+ *
+ * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
+ * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
+ * @author <a href="mailto:nbubna@apache.org">Nathan Bubna</a>
+ * @version $Id: LogChute.java 291585 2005-09-26 08:56:23Z henning $
+ */
+public interface LogChute
+{
+ /**
+ * ID for trace messages.
+ */
+ public final static int TRACE_ID = -1;
+
+ /**
+ * ID for debug messages.
+ */
+ public final static int DEBUG_ID = 0;
+
+ /**
+ * ID for info messages.
+ */
+ public final static int INFO_ID = 1;
+
+ /**
+ * ID for warning messages.
+ */
+ public final static int WARN_ID = 2;
+
+ /**
+ * ID for error messages.
+ */
+ public final static int ERROR_ID = 3;
+
+ /**
+ * Initializes this LogChute.
+ */
+ public void init(RuntimeServices rs) throws Exception;
+
+ /**
+ * Send a log message from Velocity.
+ */
+ public void log(int level, String message);
+
+ /**
+ * Send a log message from Velocity along with an exception or error
+ */
+ public void log(int level, String message, Throwable t);
+
+ /**
+ * Tell whether or not a log level is enabled.
+ */
+ public boolean isLevelEnabled(int level);
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org