You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by jo...@apache.org on 2001/03/12 08:20:13 UTC
cvs commit: jakarta-velocity/src/java/org/apache/velocity/runtime Runtime.java RuntimeConstants.java
jon 01/03/11 23:20:13
Modified: src/java/org/apache/velocity/runtime Runtime.java
RuntimeConstants.java
Log:
changes for the new logging system
Revision Changes Path
1.93 +45 -65 jakarta-velocity/src/java/org/apache/velocity/runtime/Runtime.java
Index: Runtime.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/Runtime.java,v
retrieving revision 1.92
retrieving revision 1.93
diff -u -r1.92 -r1.93
--- Runtime.java 2001/03/06 19:26:24 1.92
+++ Runtime.java 2001/03/12 07:20:11 1.93
@@ -76,6 +76,7 @@
import org.apache.velocity.Template;
import org.apache.velocity.runtime.log.LogManager;
+import org.apache.velocity.runtime.log.LogSystem;
import org.apache.velocity.runtime.parser.Parser;
import org.apache.velocity.runtime.parser.ParseException;
@@ -172,7 +173,7 @@
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
* @author <a href="mailto:jlb@houseofdistraction.com">Jeff Bowden</a>
* @author <a href="mailto:geirm@optonline.net">Geir Magusson Jr.</a>
- * @version $Id: Runtime.java,v 1.92 2001/03/06 19:26:24 geirm Exp $
+ * @version $Id: Runtime.java,v 1.93 2001/03/12 07:20:11 jon Exp $
*/
public class Runtime implements RuntimeConstants
{
@@ -184,7 +185,7 @@
/**
* The Runtime logger.
*/
- private static Logger logger;
+ private static LogSystem logSystem = null;
/**
* The caching system used by the Velocity Runtime
@@ -495,8 +496,22 @@
* Initialize the logger. We will eventually move all
* logging into the logging manager.
*/
- logger = LogManager.createLogger(logFile);
+ if (logSystem == null)
+ logSystem = LogManager.createLogSystem(logFile);
+ /*
+ * Dump the pending messages
+ */
+ dumpPendingMessages();
+
+ Runtime.info("Log file being used is: " + new File(logFile).getAbsolutePath());
+ }
+
+ /*
+ * Dump the pending messages
+ */
+ private static void dumpPendingMessages()
+ {
if ( !pendingMessages.isEmpty())
{
/*
@@ -504,13 +519,13 @@
*/
for( Enumeration e = pendingMessages.elements(); e.hasMoreElements(); )
{
- logger.info( (String) e.nextElement());
+ Object[] data = (Object[]) e.nextElement();
+ log(((Integer) data[0]).intValue(), data[1]);
}
+ pendingMessages = new Vector();
}
-
- Runtime.info("Log file being used is: " + new File(logFile).getAbsolutePath());
}
-
+
/**
* This methods initializes all the directives
* that are used by the Velocity Runtime. The
@@ -706,23 +721,6 @@
}
/**
- * Handle logging.
- *
- * @param String message to log
- */
- private static void log(String message)
- {
- if (logger != null)
- {
- logger.info(message);
- }
- else
- {
- pendingMessages.addElement(message);
- }
- }
-
- /**
* 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
@@ -741,26 +739,35 @@
}
/**
- * Log a warning message.
+ * Handle logging.
*
- * @param Object message to log
+ * @param String message to log
*/
- public static void warn(Object message)
+ private static void log(int type, Object message)
{
- String out = null;
-
- if ( showStackTrace() &&
- (message instanceof Throwable || message instanceof Exception) )
+ if (logSystem != null)
{
- out = StringUtils.stackTrace((Throwable)message);
+ logSystem.setStackTrace(showStackTrace());
+ logSystem.log(type, message);
}
else
{
- out = message.toString();
+ Object[] data = new Object[2];
+ data[0] = new Integer(type);
+ data[1] = message;
+ pendingMessages.addElement(data);
}
-
- log(WARN + out);
}
+
+ /**
+ * Log a warning message.
+ *
+ * @param Object message to log
+ */
+ public static void warn(Object message)
+ {
+ log(LogSystem.WARN_ID, message);
+ }
/**
* Log an info message.
@@ -769,19 +776,7 @@
*/
public static void info(Object message)
{
- String out = null;
-
- if ( showStackTrace() &&
- ( message instanceof Throwable || message instanceof Exception) )
- {
- out = StringUtils.stackTrace((Throwable)message);
- }
- else
- {
- out = message.toString();
- }
-
- log(INFO + out);
+ log(LogSystem.INFO_ID, message);
}
/**
@@ -791,19 +786,7 @@
*/
public static void error(Object message)
{
- String out = null;
-
- if ( showStackTrace() &&
- ( message instanceof Throwable || message instanceof Exception ) )
- {
- out = StringUtils.stackTrace((Throwable)message);
- }
- else
- {
- out = message.toString();
- }
-
- log(ERROR + out);
+ log(LogSystem.ERROR_ID, message);
}
/**
@@ -813,10 +796,7 @@
*/
public static void debug(Object message)
{
- if (DEBUG_ON)
- {
- log(DEBUG + message.toString());
- }
+ log(LogSystem.DEBUG_ID, message);
}
/**
1.17 +0 -25 jakarta-velocity/src/java/org/apache/velocity/runtime/RuntimeConstants.java
Index: RuntimeConstants.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/RuntimeConstants.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- RuntimeConstants.java 2001/03/05 11:45:11 1.16
+++ RuntimeConstants.java 2001/03/12 07:20:13 1.17
@@ -200,31 +200,6 @@
*/
/**
- * Prefix for warning messages.
- */
- final static String WARN = " [warn] ";
-
- /**
- * Prefix for info messages.
- */
- final static String INFO = " [info] ";
-
- /**
- * Prefix for debug messages.
- */
- final static String DEBUG = " [debug] ";
-
- /**
- * Prefix for error messages.
- */
- final static String ERROR = " [error] ";
-
- /**
- * Turn Runtime debugging on with this field.
- */
- final static boolean DEBUG_ON = true;
-
- /**
* Default Runtime properties.
*/
final static String DEFAULT_RUNTIME_PROPERTIES =