You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-cvs@jakarta.apache.org by ce...@apache.org on 2001/01/22 11:57:29 UTC
cvs commit: jakarta-log4j/org/apache/log4j/xml XMLLayout.java
ceki 01/01/22 02:57:29
Modified: doc HISTORY
org/apache/log4j Category.java FileAppender.java
HTMLLayout.java SimpleLayout.java TTCCLayout.java
org/apache/log4j/helpers PatternParser.java
org/apache/log4j/net SocketNode.java SyslogAppender.java
org/apache/log4j/spi LoggingEvent.java
org/apache/log4j/varia StringMatchFilter.java
org/apache/log4j/xml XMLLayout.java
Log:
Changed LoggingEvent to let Appenders/Layouts to access the raw message object.
The old message field is now called renderedMessage. Also added a new category field.
Appender/Layout needed to be modified to reflect these changes.
Revision Changes Path
1.8 +5 -0 jakarta-log4j/doc/HISTORY
Index: HISTORY
===================================================================
RCS file: /home/cvs/jakarta-log4j/doc/HISTORY,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- HISTORY 2001/01/19 16:45:26 1.7
+++ HISTORY 2001/01/22 10:57:24 1.8
@@ -10,6 +10,11 @@
- Release of version 1.1 (the 21st major release)
+ - Appenders and Layouts now get to see the raw message object in LoggingEvent
+ not just its rendered form. The access modifiers of some LoggingEvent fields
+ were changed so that they can be accessed in less error-prone ways. Thanks to
+ Jim Cajalic and Anders Kristens for their valuable advice. [*]
+
- Improved the seach method for searching for the "log4j.properties" file in
the static initializer of Category class. Thanks to Calvin Chan for
supplying a better method. [*]
1.14 +24 -13 jakarta-log4j/org/apache/log4j/Category.java
Index: Category.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/Category.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- Category.java 2001/01/19 16:45:27 1.13
+++ Category.java 2001/01/22 10:57:25 1.14
@@ -66,8 +66,10 @@
static boolean emittedNoAppenderWarning = false;
static boolean emittedNoResourceBundleWarning = false;
- // default is a language reserved term, we exceptionally prefix with
- // an undescore.
+
+ /**
+ The hierarchy where categories are attached to by default.
+ */
static
public
final Hierarchy defaultHierarchy = new Hierarchy(new
@@ -77,7 +79,7 @@
protected ResourceBundle resourceBundle;
// Categories need to know what Hierarchy they are in
- protected Hierarchy myContext;
+ protected Hierarchy hierarchy;
/**
This string constant is set to <b>log4j.properties</b> the name
@@ -312,23 +314,21 @@
}
}
+
/**
- Log a message object with the <code>DEBUG</code> priority including
- the stack trace of the {@link Throwable} <code>t</code> passed as
- parameter.
+ Log an exception with the <code>DEBUG</code> priority including its
+ stack trace.
- <p>See {@link #debug(Object)} form for more detailed information.
-
- @param message the message object to log.
@param t the exception to log, including its stack trace. */
public
- void debug(Object message, Throwable t) {
+ void debug(Throwable t) {
if(disable >= Priority.DEBUG_INT)
return;
if(Priority.DEBUG.isGreaterOrEqual(this.getChainedPriority()))
- forcedLog(instanceFQN, Priority.DEBUG, message, t);
+ forcedLog(instanceFQN, Priority.DEBUG, null, t);
}
+
//public
//void dump() {
// System.out.println("Category " + name + " dump -----");
@@ -445,7 +445,7 @@
if(message instanceof String) {
s = (String) message;
} else {
- s = myContext.rendererMap.findAndRender(message);
+ s = hierarchy.rendererMap.findAndRender(message);
}
callAppenders(new LoggingEvent(fqn, this, priority, s, t));
}
@@ -542,6 +542,17 @@
return defaultHierarchy;
}
+
+ /**
+ Return the the {@link Hierarchy} where this <code>Category</code> instance is
+ attached.
+
+ @since 1.1 */
+ public
+ Hierarchy getHierarchy() {
+ return hierarchy;
+ }
+
/**
Retrieve a category with named as the <code>name</code>
@@ -937,7 +948,7 @@
category. Default package access is MANDATORY here. */
final
void setHierarchy(Hierarchy hierarchy) {
- this.myContext = hierarchy;
+ this.hierarchy = hierarchy;
}
/**
1.6 +4 -2 jakarta-log4j/org/apache/log4j/FileAppender.java
Index: FileAppender.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/FileAppender.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FileAppender.java 2000/12/26 21:42:46 1.5
+++ FileAppender.java 2001/01/22 10:57:25 1.6
@@ -432,8 +432,10 @@
event.throwable.printStackTrace(this.tp);
}
// in case we received this event from a remote client
- else if (event.throwableInformation != null) {
- this.qw.write(event.throwableInformation);
+ else {
+ String tInfo = event.getThrowableInformation();
+ if (tInfo != null)
+ this.qw.write(tInfo);
}
}
1.8 +1 -1 jakarta-log4j/org/apache/log4j/HTMLLayout.java
Index: HTMLLayout.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/HTMLLayout.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- HTMLLayout.java 2001/01/20 16:02:18 1.7
+++ HTMLLayout.java 2001/01/22 10:57:25 1.8
@@ -88,7 +88,7 @@
sbuf.append("<td>");
- sbuf.append(event.message);
+ sbuf.append(event.getRenderedMessage());
sbuf.append("</td>\r\n");
1.3 +1 -1 jakarta-log4j/org/apache/log4j/SimpleLayout.java
Index: SimpleLayout.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/SimpleLayout.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SimpleLayout.java 2000/12/14 21:07:20 1.2
+++ SimpleLayout.java 2001/01/22 10:57:25 1.3
@@ -47,7 +47,7 @@
sbuf.setLength(0);
sbuf.append(event.priority.toString());
sbuf.append(" - ");
- sbuf.append(event.message);
+ sbuf.append(event.getRenderedMessage());
sbuf.append(LINE_SEP);
return sbuf.toString();
}
1.4 +1 -1 jakarta-log4j/org/apache/log4j/TTCCLayout.java
Index: TTCCLayout.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/TTCCLayout.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TTCCLayout.java 2001/01/20 16:02:18 1.3
+++ TTCCLayout.java 2001/01/22 10:57:26 1.4
@@ -151,7 +151,7 @@
}
}
buf.append("- ");
- buf.append(event.message);
+ buf.append(event.getRenderedMessage());
buf.append(LINE_SEP);
return buf.toString();
}
1.4 +1 -1 jakarta-log4j/org/apache/log4j/helpers/PatternParser.java
Index: PatternParser.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/helpers/PatternParser.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PatternParser.java 2001/01/20 16:02:20 1.3
+++ PatternParser.java 2001/01/22 10:57:27 1.4
@@ -388,7 +388,7 @@
case NDC_CONVERTER:
return event.getNDC();
case MESSAGE_CONVERTER: {
- return event.message;
+ return event.getRenderedMessage();
}
default: return null;
}
1.6 +1 -0 jakarta-log4j/org/apache/log4j/net/SocketNode.java
Index: SocketNode.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/net/SocketNode.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SocketNode.java 2001/01/08 17:55:44 1.5
+++ SocketNode.java 2001/01/22 10:57:27 1.6
@@ -70,6 +70,7 @@
while(true) {
event = (LoggingEvent) ois.readObject();
remoteCategory = hierarchy.getInstance(event.categoryName);
+ event.category = remoteCategory;
if(event.priority.isGreaterOrEqual(remoteCategory.getChainedPriority())) {
remoteCategory.callAppenders(event);
}
1.3 +4 -2 jakarta-log4j/org/apache/log4j/net/SyslogAppender.java
Index: SyslogAppender.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/net/SyslogAppender.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SyslogAppender.java 2000/12/14 21:07:56 1.2
+++ SyslogAppender.java 2001/01/22 10:57:27 1.3
@@ -200,8 +200,10 @@
if(event.throwable != null)
event.throwable.printStackTrace(stp);
- else if (event.throwableInformation != null) {
- sqw.write(event.throwableInformation);
+ else {
+ String tInfo = event.getThrowableInformation();
+ if (tInfo != null)
+ this.sqw.write(tInfo);
}
}
1.5 +78 -33 jakarta-log4j/org/apache/log4j/spi/LoggingEvent.java
Index: LoggingEvent.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/spi/LoggingEvent.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- LoggingEvent.java 2001/01/20 16:02:21 1.4
+++ LoggingEvent.java 2001/01/22 10:57:28 1.5
@@ -22,36 +22,40 @@
// Contributors: Nelson Minar <ne...@monkey.org>
// Wolf Siberski
+// Anders Kristensen <ak...@dynamicsoft.com>
/**
- The internal representation of logging events. When a affirmative
- logging decision is made a <code>LoggingEvent</code> instance is
- created. This instance is passed around the different log4j
+ The internal representation of logging events. When an affirmative
+ decision is made to log then a <code>LoggingEvent</code> instance
+ is created. This instance is passed around to the different log4j
components.
<p>This class is of concern to those wishing to extend log4j.
@author Ceki Gülcü
- @author <a href=mailto:jim_cakalic@na.biomerieux.com>Jim Cakalic</a>
+ @author James P. Cakalic
@since 0.8.2 */
public class LoggingEvent implements java.io.Serializable {
private static long startTime = System.currentTimeMillis();
- ///** Category of logging event. Can not be shipped to remote hosts. */
- //transient public Category category;
-
-
/** Fully qualified name of the calling category class. */
transient public final String fqnOfCategoryClass;
+ /** The category of the logging event. The categoy field is not
+ serialized for performance reasons.
+
+ <p>It is set by the LoggingEvent constructor or set by a remote
+ entity after deserialization. */
+ transient public Category category;
+
/** The category name. */
- public String categoryName;
+ public final String categoryName;
/** Priority of logging event. Priority cannot be serializable
because it is a flyweight. Due to its special seralization it
- cannot be declated final either. */
+ cannot be declared final either. */
transient public Priority priority;
/** The nested diagnostic context (NDC) of logging event. */
@@ -65,23 +69,27 @@
/** The application supplied message of logging event. */
- public final String message;
+ transient private Object message;
+
+ /** The application supplied message rendered through the log4j
+ objet rendering mechanism.*/
+ private String renderedMessage;
+
/** The name of thread in which this logging event was generated. */
private String threadName;
/** The throwable associated with this logging event.
- This is field is transient because not all exception are
+ This is field is transient because not all exceptions are
serializable. More importantly, the stack information does not
survive serialization.
*/
transient public final Throwable throwable;
- /** This variable collects the info on a throwable. This variable
- will be shipped to
-
- */
- public String throwableInformation;
+ /** This variable contains the string form of the throwable. This
+ field will be serialized if need be.
+ */
+ private String throwableInformation;
/** The number of milliseconds elapsed from 1/1/1970 until logging event
was created. */
@@ -110,6 +118,7 @@
public LoggingEvent(String fqnOfCategoryClass, Category category,
Priority priority, String message, Throwable throwable) {
this.fqnOfCategoryClass = fqnOfCategoryClass;
+ this.category = category;
this.categoryName = category.getName();
this.priority = priority;
this.message = message;
@@ -117,13 +126,23 @@
timeStamp = System.currentTimeMillis();
}
+
/**
- Returns the time when the application started, in milliseconds
- elapsed since 01.01.1970. */
+ Return the message for this logging event.
+
+ <p>Before serialization, the returned object is the message
+ passed by the user to generate the logging event. After
+ serialization, the returned value equals the String form of the
+ message possibly after object rendering.
+
+ @since 1.1 */
public
- static
- long getStartTime() {
- return startTime;
+ Object getMessage() {
+ if(message != null) {
+ return message;
+ } else {
+ return getRenderedMessage();
+ }
}
public
@@ -135,8 +154,28 @@
return ndc;
}
-
+ public
+ String getRenderedMessage() {
+ if(renderedMessage == null && message != null) {
+ if(message instanceof String) {
+ renderedMessage = (String) message;
+ } else {
+ renderedMessage=
+ category.getHierarchy().getRendererMap().findAndRender(message);
+ }
+ }
+ return renderedMessage;
+ }
+ /**
+ Returns the time when the application started, in milliseconds
+ elapsed since 01.01.1970. */
+ public
+ static
+ long getStartTime() {
+ return startTime;
+ }
+
public
String getThreadName() {
if(threadName == null)
@@ -144,21 +183,27 @@
return threadName;
}
+
+ /**
+ Return the throwable's stack trace if any such information is
+ available. */
public
String getThrowableInformation() {
+
+ if(throwableInformation != null)
+ return throwableInformation;
+
+
if(throwable == null) {
return null;
- }
-
- if(throwableInformation == null ) {
+ } else {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
throwable.printStackTrace(pw);
throwableInformation = sw.toString();
+ return throwableInformation;
}
-
- return throwableInformation;
}
private
@@ -192,9 +237,9 @@
if(clazz == Priority.class) {
oos.writeObject(null);
} else {
- // writing the Class would be nicer, except that serialized
- // classed can not be read back by JDK 1.1.x. We have to resort
- // to this hack instead.
+ // writing directly the Class object would be nicer, except that
+ // serialized a Class object can not be read back by JDK
+ // 1.1.x. We have to resort to this hack instead.
oos.writeObject(clazz.getName());
}
}
@@ -219,7 +264,7 @@
priority = (Priority) m.invoke(null, PARAM_ARRAY);
}
} catch(Exception e) {
- LogLog.warn("Priority deserialization failed, reverting default.", e);
+ LogLog.warn("Priority deserialization failed, reverting to default.", e);
priority = Priority.toPriority(p);
}
}
@@ -230,7 +275,7 @@
throws java.io.IOException, ClassNotFoundException {
ois.defaultReadObject();
readPriority(ois);
-
+
// Make sure that no location info is available to Layouts
if(locationInfo == null)
locationInfo = new LocationInfo(null, null);
1.3 +11 -17 jakarta-log4j/org/apache/log4j/varia/StringMatchFilter.java
Index: StringMatchFilter.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/varia/StringMatchFilter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- StringMatchFilter.java 2000/12/14 21:08:34 1.2
+++ StringMatchFilter.java 2001/01/22 10:57:28 1.3
@@ -49,27 +49,21 @@
*/
public
int decide(LoggingEvent event) {
- if(event.message == null || stringToMatch == null)
+ String msg = event.getRenderedMessage();
+
+ if(msg == null || stringToMatch == null)
return Filter.NEUTRAL;
- // we've got a string message
- if(event.message instanceof String) {
- String msg = (String) event.message;
- // match
- if( msg.indexOf(stringToMatch) == -1 ) {
- return Filter.NEUTRAL;
- } else { // we've got a match
- if(acceptOnMatch) {
- return Filter.ACCEPT;
- } else {
- return Filter.DENY;
- }
+
+ if( msg.indexOf(stringToMatch) == -1 ) {
+ return Filter.NEUTRAL;
+ } else { // we've got a match
+ if(acceptOnMatch) {
+ return Filter.ACCEPT;
+ } else {
+ return Filter.DENY;
}
- } else { // we've got an non-string message
- return Filter.NEUTRAL;
}
-
-
}
public
1.5 +1 -1 jakarta-log4j/org/apache/log4j/xml/XMLLayout.java
Index: XMLLayout.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/xml/XMLLayout.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XMLLayout.java 2001/01/20 16:02:22 1.4
+++ XMLLayout.java 2001/01/22 10:57:29 1.5
@@ -93,7 +93,7 @@
buf.append("<log4j:message>");
- buf.append(event.message);
+ buf.append(event.getRenderedMessage());
buf.append("</log4j:message>\r\n");
String ndc = event.getNDC();