From a1b55ec925966a1755e434d4a7ca21abbe7c0d00 Mon Sep 17 00:00:00 2001
From: "Craig R. McClanahan"
Date: Mon, 1 Mar 2004 02:12:48 +0000
Subject: [PATCH] Factor the actual writing out of log() into a new write()
method so that subclasses can easily specialize this function, without having
to specialize the creation of the message to be written.
PR: Bugzilla #27135
Submitted by: Aaron Hamid
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@139016 13f79535-47bb-0310-9956-ffa450edef68
---
.../commons/logging/impl/SimpleLog.java | 28 ++++++++++++++++---
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git a/src/java/org/apache/commons/logging/impl/SimpleLog.java b/src/java/org/apache/commons/logging/impl/SimpleLog.java
index 6da80b0..82968ef 100644
--- a/src/java/org/apache/commons/logging/impl/SimpleLog.java
+++ b/src/java/org/apache/commons/logging/impl/SimpleLog.java
@@ -64,7 +64,7 @@ import org.apache.commons.logging.LogConfigurationException;
* @author Rod Waldhoff
* @author Robert Burrell Donkin
*
- * @version $Id: SimpleLog.java,v 1.17 2004/02/28 23:00:57 craigmcc Exp $
+ * @version $Id: SimpleLog.java,v 1.18 2004/03/01 02:12:48 craigmcc Exp $
*/
public class SimpleLog implements Log, Serializable {
@@ -250,7 +250,11 @@ public class SimpleLog implements Log, Serializable {
/**
* Do the actual logging.
* This method assembles the message
- * and then prints to System.err.
+ * and then calls write() to cause it to be written.
+ *
+ * @param type One of the LOG_LEVE_XXX constants defining the log level
+ * @param message The message itself (typically a String)
+ * @param t The exception whose stack trace should be logged
*/
protected void log(int type, Object message, Throwable t) {
// Use a string buffer for better performance
@@ -301,8 +305,24 @@ public class SimpleLog implements Log, Serializable {
buf.append(sw.toString());
}
- // Print to System.err
- System.err.println(buf.toString());
+ // Print to the appropriate destination
+ write(buf);
+
+ }
+
+
+ /**
+ * Write the content of the message accumulated in the specified
+ * StringBuffer to the appropriate output destination. The
+ * default implementation writes to System.err.
+ *
+ * @param buffer A StringBuffer containing the accumulated
+ * text to be logged
+ */
+ protected void write(StringBuffer buffer) {
+
+ System.err.println(buffer.toString());
+
}