You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ce...@apache.org on 2002/07/31 11:25:15 UTC
cvs commit: jakarta-log4j/src/java/org/apache/log4j/xml XMLLayout.java
ceki 2002/07/31 02:25:14
Modified: . Tag: v1_2-branch build.xml
docs Tag: v1_2-branch HISTORY
src/java/org/apache/log4j Tag: v1_2-branch
AppenderSkeleton.java HTMLLayout.java
SimpleLayout.java TTCCLayout.java
src/java/org/apache/log4j/chainsaw Tag: v1_2-branch
EventDetails.java
src/java/org/apache/log4j/helpers Tag: v1_2-branch
Loader.java OptionConverter.java PatternParser.java
src/java/org/apache/log4j/lf5 Tag: v1_2-branch
LF5Appender.java
src/java/org/apache/log4j/net Tag: v1_2-branch
JMSAppender.java JMSSink.java SocketNode.java
SyslogAppender.java
src/java/org/apache/log4j/nt Tag: v1_2-branch
NTEventLogAppender.java
src/java/org/apache/log4j/spi Tag: v1_2-branch
LoggingEvent.java
src/java/org/apache/log4j/varia Tag: v1_2-branch
LevelMatchFilter.java LevelRangeFilter.java
src/java/org/apache/log4j/xml Tag: v1_2-branch
XMLLayout.java
Log:
- Addition of new options in JMSAppender and new command line arguments in
JMSSink. [*]
- Added new method getLoggerName() in LoggingEvent class. The
getLoggerName is the preferred way for accessing the logger
name. The public access categoryName field should not be accessed
directly. Similarly, added the getLevel method which is now the
preferred way of accessing the event's level. The public access
level field should not be accessd directly. The javadocs now mark
the categoryName and level fields as deprecated.
Modified existing appenders to comply with these new directives. [*]
- Log4j now will check if a system property called "log4j.ignoreTCL"
is set. If it is it will ignore the Thread Context ClassLoader when
loading classes. This solves the irrating "appender is not
appender" messages observed when log4j.jar is loaded by multiple
class loaders. [*]
Revision Changes Path
No revision
No revision
1.34.2.8 +3 -4 jakarta-log4j/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-log4j/build.xml,v
retrieving revision 1.34.2.7
retrieving revision 1.34.2.8
diff -u -r1.34.2.7 -r1.34.2.8
--- build.xml 19 Jun 2002 10:01:02 -0000 1.34.2.7
+++ build.xml 31 Jul 2002 09:25:12 -0000 1.34.2.8
@@ -17,7 +17,7 @@
<!-- prefixed with "env". -->
<property environment="env"/>
- <property name="version" value="1.2.5"/>
+ <property name="version" value="1.2.6"/>
<!-- The base directory relative to which most targets are built -->
<property name="base" value="."/>
@@ -383,9 +383,8 @@
header="<b>Log4j ${version}</b>"
bottom="Copyright 2000-2002 Apache Software Foundation.">
- <link offline="true"
- href="http://java.sun.com/products/jdk/1.2/docs/api"
- packageListLoc="${packaging.dir}"/>
+ <link href="http://java.sun.com/products/jdk/1.3/docs/api"/>
+ <link href="http://java.sun.com/j2ee/sdk_1.3/techdocs/api/"/>
<classpath refid="compile.classpath"/>
</javadoc>
</target>
No revision
No revision
1.97.2.10 +27 -3 jakarta-log4j/docs/HISTORY
Index: HISTORY
===================================================================
RCS file: /home/cvs/jakarta-log4j/docs/HISTORY,v
retrieving revision 1.97.2.9
retrieving revision 1.97.2.10
diff -u -r1.97.2.9 -r1.97.2.10
--- HISTORY 5 Jul 2002 11:23:49 -0000 1.97.2.9
+++ HISTORY 31 Jul 2002 09:25:12 -0000 1.97.2.10
@@ -5,7 +5,31 @@
client code.
[***] Changes requiring important modifications to existing client code.
- July 5th, 2002,
+
+ July 31st, 2002
+
+ - Release of version 1.2.6
+
+ - Addition of new options in JMSAppender and new command line arguments in
+ JMSSink. [*]
+
+ - Added new method getLoggerName() in LoggingEvent class. The
+ getLoggerName is the preferred way for accessing the logger
+ name. The public access categoryName field should not be accessed
+ directly. Similarly, added the getLevel method which is now the
+ preferred way of accessing the event's level. The public access
+ level field should not be accessd directly. The javadocs now mark
+ the categoryName and level fields as deprecated.
+
+ Modified existing appenders to comply with these new directives. [*]
+
+ - Log4j now will check if a system property called "log4j.ignoreTCL"
+ is set. If it is it will ignore the Thread Context ClassLoader when
+ loading classes. This solves the irrating "appender is not
+ appender" messages observed when log4j.jar is loaded by multiple
+ class loaders. [*]
+
+ July 5th, 2002
- Release of version 1.2.5
@@ -15,7 +39,7 @@
appender instances. This resolves bug #10185 submitted by Paul
Voutier. [*]
- June 12th, 2002,
+ June 12th, 2002
- Release of version 1.2.4
@@ -41,7 +65,7 @@
- Added missing LevelRangeFilter file. [*]
- May 24th, 2002,
+ May 24th, 2002
- Release of version 1.2.3
No revision
No revision
1.19.2.2 +1 -1 jakarta-log4j/src/java/org/apache/log4j/AppenderSkeleton.java
Index: AppenderSkeleton.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/AppenderSkeleton.java,v
retrieving revision 1.19.2.1
retrieving revision 1.19.2.2
diff -u -r1.19.2.1 -r1.19.2.2
--- AppenderSkeleton.java 11 Jun 2002 13:17:38 -0000 1.19.2.1
+++ AppenderSkeleton.java 31 Jul 2002 09:25:12 -0000 1.19.2.2
@@ -203,7 +203,7 @@
return;
}
- if(!isAsSevereAsThreshold(event.level)) {
+ if(!isAsSevereAsThreshold(event.getLevel())) {
return;
}
1.27.2.1 +7 -7 jakarta-log4j/src/java/org/apache/log4j/HTMLLayout.java
Index: HTMLLayout.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/HTMLLayout.java,v
retrieving revision 1.27
retrieving revision 1.27.2.1
diff -u -r1.27 -r1.27.2.1
--- HTMLLayout.java 25 Apr 2002 21:18:15 -0000 1.27
+++ HTMLLayout.java 31 Jul 2002 09:25:12 -0000 1.27.2.1
@@ -130,22 +130,22 @@
sbuf.append("</td>" + Layout.LINE_SEP);
sbuf.append("<td title=\"Level\">");
- if (event.level.equals(Level.DEBUG)) {
+ if (event.getLevel().equals(Level.DEBUG)) {
sbuf.append("<font color=\"#339933\">");
- sbuf.append(event.level);
+ sbuf.append(event.getLevel());
sbuf.append("</font>");
}
- else if(event.level.isGreaterOrEqual(Level.WARN)) {
+ else if(event.getLevel().isGreaterOrEqual(Level.WARN)) {
sbuf.append("<font color=\"#993300\"><strong>");
- sbuf.append(event.level);
+ sbuf.append(event.getLevel());
sbuf.append("</strong></font>");
} else {
- sbuf.append(event.level);
+ sbuf.append(event.getLevel());
}
sbuf.append("</td>" + Layout.LINE_SEP);
- sbuf.append("<td title=\"" + event.categoryName + " category\">");
- sbuf.append(Transform.escapeTags(event.categoryName));
+ sbuf.append("<td title=\"" + event.getLoggerName() + " category\">");
+ sbuf.append(Transform.escapeTags(event.getLoggerName()));
sbuf.append("</td>" + Layout.LINE_SEP);
if(locationInfo) {
1.10.2.1 +1 -1 jakarta-log4j/src/java/org/apache/log4j/SimpleLayout.java
Index: SimpleLayout.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/SimpleLayout.java,v
retrieving revision 1.10
retrieving revision 1.10.2.1
diff -u -r1.10 -r1.10.2.1
--- SimpleLayout.java 3 Apr 2002 22:18:14 -0000 1.10
+++ SimpleLayout.java 31 Jul 2002 09:25:12 -0000 1.10.2.1
@@ -49,7 +49,7 @@
String format(LoggingEvent event) {
sbuf.setLength(0);
- sbuf.append(event.level.toString());
+ sbuf.append(event.getLevel().toString());
sbuf.append(" - ");
sbuf.append(event.getRenderedMessage());
sbuf.append(LINE_SEP);
1.16.2.1 +2 -2 jakarta-log4j/src/java/org/apache/log4j/TTCCLayout.java
Index: TTCCLayout.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/TTCCLayout.java,v
retrieving revision 1.16
retrieving revision 1.16.2.1
diff -u -r1.16 -r1.16.2.1
--- TTCCLayout.java 9 May 2002 20:15:01 -0000 1.16
+++ TTCCLayout.java 31 Jul 2002 09:25:12 -0000 1.16.2.1
@@ -175,11 +175,11 @@
buf.append(event.getThreadName());
buf.append("] ");
}
- buf.append(event.level.toString());
+ buf.append(event.getLevel().toString());
buf.append(' ');
if(this.categoryPrefixing) {
- buf.append(event.categoryName);
+ buf.append(event.getLoggerName());
buf.append(' ');
}
No revision
No revision
1.1.2.1 +2 -2 jakarta-log4j/src/java/org/apache/log4j/chainsaw/EventDetails.java
Index: EventDetails.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/EventDetails.java,v
retrieving revision 1.1
retrieving revision 1.1.2.1
diff -u -r1.1 -r1.1.2.1
--- EventDetails.java 23 Mar 2002 07:51:26 -0000 1.1
+++ EventDetails.java 31 Jul 2002 09:25:13 -0000 1.1.2.1
@@ -73,8 +73,8 @@
EventDetails(LoggingEvent aEvent) {
this(aEvent.timeStamp,
- aEvent.level,
- aEvent.categoryName,
+ aEvent.getLevel(),
+ aEvent.getLoggerName(),
aEvent.getNDC(),
aEvent.getThreadName(),
aEvent.getRenderedMessage(),
No revision
No revision
1.17.2.3 +36 -30 jakarta-log4j/src/java/org/apache/log4j/helpers/Loader.java
Index: Loader.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/helpers/Loader.java,v
retrieving revision 1.17.2.2
retrieving revision 1.17.2.3
diff -u -r1.17.2.2 -r1.17.2.3
--- Loader.java 4 Jun 2002 22:42:29 -0000 1.17.2.2
+++ Loader.java 31 Jul 2002 09:25:13 -0000 1.17.2.3
@@ -27,7 +27,9 @@
// We conservatively assume that we are running under Java 1.x
static private boolean java1 = true;
-
+
+ static private boolean ignoreTCL = false;
+
static {
String prop = OptionConverter.getSystemProperty("java.version", null);
@@ -38,6 +40,10 @@
java1 = false;
}
}
+ String ignoreTCLProp = OptionConverter.getSystemProperty("log4j.ignoreTCL", null);
+ if(ignoreTCLProp != null) {
+ ignoreTCL = OptionConverter.toBoolean(ignoreTCLProp, true);
+ }
}
/* A cache for
@@ -63,38 +69,36 @@
</ol>
*/
- static
- public
- URL getResource(String resource) {
+ static public URL getResource(String resource) {
ClassLoader classLoader = null;
URL url = null;
try {
- if(!java1) {
- classLoader = getTCL();
- if(classLoader != null) {
- LogLog.debug("Trying to find ["+resource+"] using context classloader "
- +classLoader+".");
- url = classLoader.getResource(resource);
- if(url != null) {
- return url;
- }
- }
- }
-
- // We could not find resource. Ler us now try with the
- // classloader that loaded this class.
- classLoader = Loader.class.getClassLoader();
- if(classLoader != null) {
- LogLog.debug("Trying to find ["+resource+"] using "+classLoader
- +" class loader.");
- url = classLoader.getResource(resource);
- if(url != null) {
- return url;
- }
- }
+ if(!java1) {
+ classLoader = getTCL();
+ if(classLoader != null) {
+ LogLog.debug("Trying to find ["+resource+"] using context classloader "
+ +classLoader+".");
+ url = classLoader.getResource(resource);
+ if(url != null) {
+ return url;
+ }
+ }
+ }
+
+ // We could not find resource. Ler us now try with the
+ // classloader that loaded this class.
+ classLoader = Loader.class.getClassLoader();
+ if(classLoader != null) {
+ LogLog.debug("Trying to find ["+resource+"] using "+classLoader
+ +" class loader.");
+ url = classLoader.getResource(resource);
+ if(url != null) {
+ return url;
+ }
+ }
} catch(Throwable t) {
- LogLog.warn(TSTR, t);
+ LogLog.warn(TSTR, t);
}
// Last ditch attempt: get the resource from the class path. It
@@ -102,7 +106,7 @@
// loader which the parent of the system class loader. Hence the
// code below.
LogLog.debug("Trying to find ["+resource+
- "] using ClassLoader.getSystemResource().");
+ "] using ClassLoader.getSystemResource().");
return ClassLoader.getSystemResource(resource);
}
@@ -146,7 +150,9 @@
*
*/
static public Class loadClass (String clazz) throws ClassNotFoundException {
- if(java1) {
+ // Just call Class.forName(clazz) if we are running under JDK 1.1
+ // or if we are instructed to ignore the TCL.
+ if(java1 || ignoreTCL) {
return Class.forName(clazz);
} else {
try {
1.36.2.2 +4 -0 jakarta-log4j/src/java/org/apache/log4j/helpers/OptionConverter.java
Index: OptionConverter.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/helpers/OptionConverter.java,v
retrieving revision 1.36.2.1
retrieving revision 1.36.2.2
diff -u -r1.36.2.1 -r1.36.2.2
--- OptionConverter.java 22 May 2002 17:15:19 -0000 1.36.2.1
+++ OptionConverter.java 31 Jul 2002 09:25:13 -0000 1.36.2.2
@@ -310,6 +310,10 @@
if(!superClass.isAssignableFrom(classObj)) {
LogLog.error("A \""+className+"\" object is not assignable to a \""+
superClass.getName() + "\" variable.");
+ LogLog.error("The class \""+ superClass.getName()+"\" was loaded by ["
+ +superClass.getClassLoader()+"] whereas object of type\""
+ +classObj.getClass().getName() +"\" was loaded by ["
+ +classObj.getClass().getClassLoader()+"].");
return defaultValue;
}
return classObj.newInstance();
1.17.2.1 +2 -2 jakarta-log4j/src/java/org/apache/log4j/helpers/PatternParser.java
Index: PatternParser.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/helpers/PatternParser.java,v
retrieving revision 1.17
retrieving revision 1.17.2.1
diff -u -r1.17 -r1.17.2.1
--- PatternParser.java 24 Apr 2002 01:16:13 -0000 1.17
+++ PatternParser.java 31 Jul 2002 09:25:13 -0000 1.17.2.1
@@ -388,7 +388,7 @@
case THREAD_CONVERTER:
return event.getThreadName();
case LEVEL_CONVERTER:
- return event.level.toString();
+ return event.getLevel().toString();
case NDC_CONVERTER:
return event.getNDC();
case MESSAGE_CONVERTER: {
@@ -538,7 +538,7 @@
}
String getFullyQualifiedName(LoggingEvent event) {
- return event.categoryName;
+ return event.getLoggerName();
}
}
}
No revision
No revision
1.1.2.1 +3 -3 jakarta-log4j/src/java/org/apache/log4j/lf5/LF5Appender.java
Index: LF5Appender.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/lf5/LF5Appender.java,v
retrieving revision 1.1
retrieving revision 1.1.2.1
diff -u -r1.1 -r1.1.2.1
--- LF5Appender.java 26 Apr 2002 15:48:42 -0000 1.1
+++ LF5Appender.java 31 Jul 2002 09:25:13 -0000 1.1.2.1
@@ -88,11 +88,11 @@
*/
public void append(LoggingEvent event) {
// Retrieve the information from the log4j LoggingEvent.
- String category = event.categoryName;
+ String category = event.getLoggerName();
String logMessage = event.getRenderedMessage();
String nestedDiagnosticContext = event.getNDC();
String threadDescription = event.getThreadName();
- String level = event.level.toString();
+ String level = event.getLevel().toString();
long time = event.timeStamp;
LocationInfo locationInfo = event.getLocationInformation();
@@ -255,4 +255,4 @@
// Nested Top-Level Classes or Interfaces:
//--------------------------------------------------------------------------
-}
\ No newline at end of file
+}
No revision
No revision
1.13.2.1 +231 -31 jakarta-log4j/src/java/org/apache/log4j/net/JMSAppender.java
Index: JMSAppender.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/net/JMSAppender.java,v
retrieving revision 1.13
retrieving revision 1.13.2.1
diff -u -r1.13 -r1.13.2.1
--- JMSAppender.java 24 Apr 2002 01:16:12 -0000 1.13
+++ JMSAppender.java 31 Jul 2002 09:25:13 -0000 1.13.2.1
@@ -12,26 +12,99 @@
import org.apache.log4j.spi.ErrorCode;
import org.apache.log4j.helpers.LogLog;
-import javax.jms.*;
+import java.util.Properties;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.Topic;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSession;
+import javax.jms.Session;
+import javax.jms.ObjectMessage;
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
/**
- A simple appender based on JMS.
+ * A simple appender that publishes events to a JMS Topic. The events
+ * are serialized and transmitted as JMS message type {@link
+ * ObjectMessage}.
+
+ * <p>JMS {@link Topic topics} and {@link TopicConnectionFactory topic
+ * connection factories} are administered objects that are retrieved
+ * using JNDI messaging which in turn requires the retreival of a JNDI
+ * {@link Context}.
+
+ * <p>There are two common methods for retrieving a JNDI {@link
+ * Context}. If a file resource named <em>jndi.properties</em> is
+ * available to the JNDI API, it will use the information found
+ * therein to retrieve an initial JNDI context. To obtain an initial
+ * context, your code will simply call:
+
+ <pre>
+ InitialContext jndiContext = new InitialContext();
+ </pre>
+
+ * <p>Calling the no-argument <code>InitialContext()</code> method
+ * will also work from within Enterprise Java Beans (EJBs) because it
+ * is part of the EJB contract for application servers to provide each
+ * bean an environment naming context (ENC).
+
+ * <p>In the second approach, several predetermined properties are set
+ * and these properties are passed to the <code>InitialContext</code>
+ * contructor to connect to the naming service provider. For example,
+ * to connect to JBoss naming service one would write:
+
+<pre>
+ Properties env = new Properties( );
+ env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
+ env.put(Context.PROVIDER_URL, "jnp://hostname:1099");
+ env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
+ InitialContext jndiContext = new InitialContext(env);
+</pre>
+
+ * where <em>hostname</em> is the host where the JBoss applicaiton
+ * server is running.
+ *
+ * <p>To connect to the the naming service of Weblogic application
+ * server one would write:
+
+<pre>
+ Properties env = new Properties( );
+ env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
+ env.put(Context.PROVIDER_URL, "t3://localhost:7001");
+ InitialContext jndiContext = new InitialContext(env);
+</pre>
+
+ * <p>Other JMS providers will obviously require different values.
+ *
+ * The initial JNDI context can be obtained by calling the
+ * no-argument <code>InitialContext()</code> method in EJBs. Only
+ * clients running in a separate JVM need to be concerned about the
+ * <em>jndi.properties</em> file and calling {@link
+ * InitialContext#InitialContext()} or alternatively correctly
+ * setting the different properties before calling {@link
+ * InitialContext#InitialContext(java.util.Hashtable)} method.
- @author Ceki Gülcü
-*/
+
+ @author Ceki Gülcü */
public class JMSAppender extends AppenderSkeleton {
- TopicConnection topicConnection;
- TopicSession topicSession;
- TopicPublisher topicPublisher;
+ String securityPrincipalName;
+ String securityCredentials;
+ String initialContextFactoryName;
+ String urlPkgPrefixes;
+ String providerURL;
String topicBindingName;
String tcfBindingName;
+ String userName;
+ String password;
boolean locationInfo;
+ TopicConnection topicConnection;
+ TopicSession topicSession;
+ TopicPublisher topicPublisher;
+
public
JMSAppender() {
}
@@ -82,31 +155,76 @@
return locationInfo;
}
- public
- void activateOptions() {
+ /**
+ * Options are activated and become effective only after calling
+ * this method.*/
+ public void activateOptions() {
TopicConnectionFactory topicConnectionFactory;
try {
- Context ctx = new InitialContext();
- topicConnectionFactory = (TopicConnectionFactory) lookup(ctx, tcfBindingName);
- topicConnection = topicConnectionFactory.createTopicConnection();
- topicConnection.start();
+ Context jndi;
+ LogLog.debug("Getting initial context.");
+ if(initialContextFactoryName != null) {
+ Properties env = new Properties( );
+ env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactoryName);
+ if(providerURL != null) {
+ env.put(Context.PROVIDER_URL, providerURL);
+ } else {
+ LogLog.warn("You have set InitialContextFactoryName option but not the "
+ +"ProviderURL. This is likely to cause problems.");
+ }
+ if(urlPkgPrefixes != null) {
+ env.put(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
+ }
+
+ if(securityPrincipalName != null) {
+ env.put(Context.SECURITY_PRINCIPAL, securityPrincipalName);
+ if(securityCredentials != null) {
+ env.put(Context.SECURITY_CREDENTIALS, securityCredentials);
+ } else {
+ LogLog.warn("You have set SecurityPrincipalName option but not the "
+ +"SecurityCredentials. This is likely to cause problems.");
+ }
+ }
+ jndi = new InitialContext(env);
+ } else {
+ jndi = new InitialContext();
+ }
+
+ LogLog.debug("Looking up ["+tcfBindingName+"]");
+ topicConnectionFactory = (TopicConnectionFactory) lookup(jndi, tcfBindingName);
+ LogLog.debug("About to create TopicConnection.");
+ if(userName != null) {
+ LogLog.debug("--------User name: "+userName);
+ topicConnection = topicConnectionFactory.createTopicConnection(userName,
+ password);
+ } else {
+ topicConnection = topicConnectionFactory.createTopicConnection();
+ }
+
+ LogLog.debug("Creating TopicSession, non-transactional, "
+ +"in AUTO_ACKNOWLEDGE mode.");
topicSession = topicConnection.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
- Topic topic = (Topic) lookup(ctx, topicBindingName);
+ LogLog.debug("Looking up topic name ["+topicBindingName+"].");
+ Topic topic = (Topic) lookup(jndi, topicBindingName);
+
+ LogLog.debug("Creating TopicPublisher.");
topicPublisher = topicSession.createPublisher(topic);
+
+ LogLog.debug("Starting TopicConnection.");
+ topicConnection.start();
- ctx.close();
+ jndi.close();
} catch(Exception e) {
errorHandler.error("Error while activating options for appender named ["+name+
"].", e, ErrorCode.GENERIC_FAILURE);
}
}
- protected
- Object lookup(Context ctx, String name) throws NamingException {
+ protected Object lookup(Context ctx, String name) throws NamingException {
try {
return ctx.lookup(name);
} catch(NameNotFoundException e) {
@@ -115,8 +233,7 @@
}
}
- protected
- boolean checkEntryConditions() {
+ protected boolean checkEntryConditions() {
String fail = null;
if(this.topicConnection == null) {
@@ -138,9 +255,9 @@
/**
Close this JMSAppender. Closing releases all resources used by the
appender. A closed appender cannot be re-opened. */
- public
- synchronized // avoid concurrent append and close operations
- void close() {
+ public synchronized void close() {
+ // The synchronized modifier avoids concurrent append and close operations
+
if(this.closed)
return;
@@ -164,8 +281,7 @@
/**
This method called by {@link AppenderSkeleton#doAppend} method to
do most of the real appending work. */
- public
- void append(LoggingEvent event) {
+ public void append(LoggingEvent event) {
if(!checkEntryConditions()) {
return;
}
@@ -184,17 +300,101 @@
}
/**
- If true, the information sent to the remote subscriber will include
- location information. By default no location information is sent
- to the subscriber. */
- public
- void setLocationInfo(boolean locationInfo) {
+ * Returns the value of the <b>InitialContextFactoryName</b> option.
+ * See {@link #setInitialContextFactoryName} for more details on the
+ * meaning of this option.
+ * */
+ public String getInitialContextFactoryName() {
+ return initialContextFactoryName;
+ }
+
+ /**
+ * Setting the <b>InitialContextFactoryName</b> method will cause
+ * this <code>JMSAppender</code> instance to use the {@link
+ * InitialContext#InitialContext(Hashtable)} method instead of the
+ * no-argument constructor. If you set this option, you should also
+ * at least set the <b>ProviderURL</b> option.
+ *
+ * <p>See also {@link #setProviderURL(String)}.
+ * */
+ public void setInitialContextFactoryName(String initialContextFactoryName) {
+ this.initialContextFactoryName = initialContextFactoryName;
+ }
+
+ public String getProviderURL() {
+ return providerURL;
+ }
+
+ public void setProviderURL(String providerURL) {
+ this.providerURL = providerURL;
+ }
+
+ String getURLPkgPrefixes( ) {
+ return urlPkgPrefixes;;
+ }
+
+ public void setURLPkgPrefixes(String urlPkgPrefixes ) {
+ this.urlPkgPrefixes = urlPkgPrefixes;
+ }
+
+ public String getSecurityCredentials() {
+ return securityCredentials;
+ }
+
+ public void setSecurityCredentials(String securityCredentials) {
+ this.securityCredentials = securityCredentials;
+ }
+
+
+ public String getSecurityPrincipalName() {
+ return securityPrincipalName;
+ }
+
+ public void setSecurityPrincipalName(String securityPrincipalName) {
+ this.securityPrincipalName = securityPrincipalName;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ /**
+ * The user name to use when {@link
+ * TopicConnectionFactory#createTopicConnection(String, String)
+ * creating a topic session}. If you set this option, you should
+ * also set the <b>Password</b> option. See {@link
+ * #setPassword(String)}.
+ * */
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ /**
+ * The paswword to use when creating a topic session.
+ */
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+
+ /**
+ If true, the information sent to the remote subscriber will
+ include caller's location information. By default no location
+ information is sent to the subscriber. */
+ public void setLocationInfo(boolean locationInfo) {
this.locationInfo = locationInfo;
}
- public
- boolean requiresLayout() {
+ /**
+ * The JMSAppender sends serialized events and consequently does not
+ * require a layout.
+ * */
+ public boolean requiresLayout() {
return false;
}
}
1.12.2.1 +60 -40 jakarta-log4j/src/java/org/apache/log4j/net/JMSSink.java
Index: JMSSink.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/net/JMSSink.java,v
retrieving revision 1.12
retrieving revision 1.12.2.1
diff -u -r1.12 -r1.12.2.1
--- JMSSink.java 24 Apr 2002 01:16:12 -0000 1.12
+++ JMSSink.java 31 Jul 2002 09:25:13 -0000 1.12.2.1
@@ -8,7 +8,7 @@
package org.apache.log4j.net;
import org.apache.log4j.spi.LoggingEvent;
-import org.apache.log4j.Category;
+import org.apache.log4j.Logger;
import org.apache.log4j.LogManager;
import org.apache.log4j.spi.RendererSupport;
import org.apache.log4j.spi.LoggerRepository;
@@ -16,35 +16,52 @@
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.helpers.LogLog;
-import javax.jms.*;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.TopicConnection;
+import javax.jms.Topic;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicSubscriber;
+import javax.jms.Session;
+import javax.jms.TopicSession;
+import javax.jms.ObjectMessage;
+import javax.jms.JMSException;
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
+import java.util.Properties;
/**
- A simple application receiving the logging events sent by a JMSAppender.
+ * A simple application that consumes logging events sent by a {@link
+ * JMSAppender}.
+ *
+ *
+ * @author Ceki Gülcü
+ * */
+public class JMSSink implements javax.jms.MessageListener {
-
- @author Ceki Gülcü
-*/
-public class JMSSink {
+ static Logger logger = Logger.getLogger(JMSSink.class);
static public void main(String[] args) {
- if(args.length != 3) {
+ if(args.length != 5) {
usage("Wrong number of arguments.");
}
-
+
String tcfBindingName = args[0];
String topicBindingName = args[1];
- PropertyConfigurator.configure(args[2]);
+ String username = args[2];
+ String password = args[3];
+ PropertyConfigurator.configure(args[4]);
- LoggerRepository rep = LogManager.getLoggerRepository();
- if(rep instanceof RendererSupport) {
- ((RendererSupport) rep).setRenderer(Message.class, new MessageRenderer());
- }
+ new JMSSink(tcfBindingName, topicBindingName, username, password);
+ }
+
+ public JMSSink( String tcfBindingName, String topicBindingName, String username,
+ String password) {
+
try {
Context ctx = new InitialContext();
TopicConnectionFactory topicConnectionFactory;
@@ -52,7 +69,8 @@
tcfBindingName);
TopicConnection topicConnection =
- topicConnectionFactory.createTopicConnection();
+ topicConnectionFactory.createTopicConnection(username,
+ password);
topicConnection.start();
TopicSession topicSession = topicConnection.createTopicSession(false,
@@ -60,47 +78,49 @@
Topic topic = (Topic)ctx.lookup(topicBindingName);
- //TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic);
- TopicSubscriber topicSubscriber =
- topicSession.createDurableSubscriber(topic, "x");
-
-
- LoggingEvent event;
- Category remoteCategory;
+ TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic);
+
+ topicSubscriber.setMessageListener(this);
- while(true) {
- ObjectMessage msg = (ObjectMessage)topicSubscriber.receive();
- event = (LoggingEvent) msg.getObject();
- remoteCategory = Category.getInstance(event.categoryName);
- remoteCategory.callAppenders(event);
+ } catch(Exception e) {
+ logger.error("Could not read JMS message.", e);
+ }
+ }
- // dump the JMSMessage
- // remoteCategory.debug(msg);
+ public void onMessage(javax.jms.Message message) {
+ LoggingEvent event;
+ Logger remoteLogger;
- }
- } catch(Exception e) {
- LogLog.error("Could not read JMS message.", e);
+ try {
+ if(message instanceof ObjectMessage) {
+ ObjectMessage objectMessage = (ObjectMessage) message;
+ event = (LoggingEvent) objectMessage.getObject();
+ remoteLogger = Logger.getLogger(event.getLoggerName());
+ remoteLogger.callAppenders(event);
+ } else {
+ logger.warn("Received message is of type "+message.getJMSType()
+ +", was expecting ObjectMessage.");
+ }
+ } catch(JMSException jmse) {
+ logger.error("Exception thrown while processing incoming message.",
+ jmse);
}
}
- protected
- static
- Object lookup(Context ctx, String name) throws NamingException {
+ protected static Object lookup(Context ctx, String name) throws NamingException {
try {
return ctx.lookup(name);
} catch(NameNotFoundException e) {
- LogLog.error("Could not find name ["+name+"].");
+ logger.error("Could not find name ["+name+"].");
throw e;
}
}
-
- static
- void usage(String msg) {
+ static void usage(String msg) {
System.err.println(msg);
System.err.println("Usage: java " + JMSSink.class.getName()
- + " TopicConnectionFactoryBindingName TopicBindingName configFile");
+ + " TopicConnectionFactoryBindingName TopicBindingName username password configFile");
System.exit(1);
}
}
1.20.2.2 +3 -3 jakarta-log4j/src/java/org/apache/log4j/net/SocketNode.java
Index: SocketNode.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/net/SocketNode.java,v
retrieving revision 1.20.2.1
retrieving revision 1.20.2.2
diff -u -r1.20.2.1 -r1.20.2.2
--- SocketNode.java 19 Jun 2002 10:01:05 -0000 1.20.2.1
+++ SocketNode.java 31 Jul 2002 09:25:13 -0000 1.20.2.2
@@ -66,10 +66,10 @@
// read an event from the wire
event = (LoggingEvent) ois.readObject();
// get a logger from the hierarchy. The name of the logger is taken to be the name contained in the event.
- remoteLogger = hierarchy.getLogger(event.categoryName);
- event.logger = remoteLogger;
+ remoteLogger = hierarchy.getLogger(event.getLoggerName());
+ //event.logger = remoteLogger;
// apply the logger-level filter
- if(event.level.isGreaterOrEqual(remoteLogger.getEffectiveLevel())) {
+ if(event.getLevel().isGreaterOrEqual(remoteLogger.getEffectiveLevel())) {
// finally log the event as if was generated locally
remoteLogger.callAppenders(event);
}
1.15.2.2 +2 -2 jakarta-log4j/src/java/org/apache/log4j/net/SyslogAppender.java
Index: SyslogAppender.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/net/SyslogAppender.java,v
retrieving revision 1.15.2.1
retrieving revision 1.15.2.2
diff -u -r1.15.2.1 -r1.15.2.2
--- SyslogAppender.java 12 Jun 2002 13:55:32 -0000 1.15.2.1
+++ SyslogAppender.java 31 Jul 2002 09:25:13 -0000 1.15.2.2
@@ -228,7 +228,7 @@
public
void append(LoggingEvent event) {
- if(!isAsSevereAsThreshold(event.level))
+ if(!isAsSevereAsThreshold(event.getLevel()))
return;
// We must not attempt to append if sqw is null.
@@ -241,7 +241,7 @@
String buffer = (facilityPrinting? facilityStr : "") +
layout.format(event);
- sqw.setLevel(event.level.getSyslogEquivalent());
+ sqw.setLevel(event.getLevel().getSyslogEquivalent());
sqw.write(buffer);
String[] s = event.getThrowableStrRep();
No revision
No revision
1.15.2.2 +1 -1 jakarta-log4j/src/java/org/apache/log4j/nt/NTEventLogAppender.java
Index: NTEventLogAppender.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/nt/NTEventLogAppender.java,v
retrieving revision 1.15.2.1
retrieving revision 1.15.2.2
diff -u -r1.15.2.1 -r1.15.2.2
--- NTEventLogAppender.java 12 Jun 2002 13:55:33 -0000 1.15.2.1
+++ NTEventLogAppender.java 31 Jul 2002 09:25:14 -0000 1.15.2.2
@@ -110,7 +110,7 @@
}
}
// Normalize the log message level into the supported categories
- int nt_category = event.level.toInt();
+ int nt_category = event.getLevel().toInt();
// Anything above FATAL or below DEBUG is labeled as INFO.
//if (nt_category > FATAL || nt_category < DEBUG) {
No revision
No revision
1.31.2.4 +41 -13 jakarta-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java
Index: LoggingEvent.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java,v
retrieving revision 1.31.2.3
retrieving revision 1.31.2.4
diff -u -r1.31.2.3 -r1.31.2.4
--- LoggingEvent.java 11 Jun 2002 13:17:38 -0000 1.31.2.3
+++ LoggingEvent.java 31 Jul 2002 09:25:14 -0000 1.31.2.4
@@ -45,15 +45,34 @@
*
* <p>It is set by the LoggingEvent constructor or set by a remote
* entity after deserialization.
+ *
+ * @deprecated This field will be marked as private or be completely
+ * removed in future releases. Please do not use it.
* */
- transient public Category logger;
+ transient private Category logger;
- /** The category (logger) name. */
- public final String categoryName;
+ /**
+ * <p>The category (logger) name.
+ *
+ * @deprecated This field will be marked as private in future
+ * releases. Please do not access it directly. Use the {@link
+ * #getLoggerName} method instead.
- /** Level of logging event. Level cannot be serializable
- because it is a flyweight. Due to its special seralization it
- cannot be declared final either. */
+ * */
+ final public String categoryName;
+
+ /**
+ * Level of logging event. Level cannot be serializable because it
+ * is a flyweight. Due to its special seralization it cannot be
+ * declared final either.
+ *
+ * <p> This field should not be accessed directly. You shoud use the
+ * {@link #getLevel} method instead.
+ *
+ * @deprecated This field will be marked as private in future
+ * releases. Please do not access it directly. Use the {@link
+ * #getLevel} method instead.
+ * */
transient public Priority level;
/** The nested diagnostic context (NDC) of logging event. */
@@ -154,20 +173,31 @@
this.timeStamp = timeStamp;
}
-
-
/**
Set the location information for this logging event. The collected
information is cached for future use.
*/
- public
- LocationInfo getLocationInformation() {
+ public LocationInfo getLocationInformation() {
if(locationInfo == null) {
locationInfo = new LocationInfo(new Throwable(), fqnOfCategoryClass);
}
return locationInfo;
}
+ /**
+ * Return the level of this event. Use this form instead of directly
+ * accessing the <code>level</code> field. */
+ public Level getLevel() {
+ return (Level) level;
+ }
+
+ /**
+ * Return the name of the logger. Use this form instead of directly
+ * accessing the <code>categoryName</code> field.
+ */
+ public String getLoggerName() {
+ return categoryName;
+ }
/**
Return the message for this logging event.
@@ -267,9 +297,7 @@
/**
Returns the time when the application started, in milliseconds
elapsed since 01.01.1970. */
- public
- static
- long getStartTime() {
+ public static long getStartTime() {
return startTime;
}
No revision
No revision
1.5.2.2 +1 -1 jakarta-log4j/src/java/org/apache/log4j/varia/LevelMatchFilter.java
Index: LevelMatchFilter.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/varia/LevelMatchFilter.java,v
retrieving revision 1.5.2.1
retrieving revision 1.5.2.2
diff -u -r1.5.2.1 -r1.5.2.2
--- LevelMatchFilter.java 11 Jun 2002 13:17:38 -0000 1.5.2.1
+++ LevelMatchFilter.java 31 Jul 2002 09:25:14 -0000 1.5.2.2
@@ -79,7 +79,7 @@
}
boolean matchOccured = false;
- if(this.levelToMatch.equals(event.level)) {
+ if(this.levelToMatch.equals(event.getLevel())) {
matchOccured = true;
}
1.2.2.3 +2 -2 jakarta-log4j/src/java/org/apache/log4j/varia/LevelRangeFilter.java
Index: LevelRangeFilter.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/varia/LevelRangeFilter.java,v
retrieving revision 1.2.2.2
retrieving revision 1.2.2.3
diff -u -r1.2.2.2 -r1.2.2.3
--- LevelRangeFilter.java 11 Jun 2002 13:17:38 -0000 1.2.2.2
+++ LevelRangeFilter.java 31 Jul 2002 09:25:14 -0000 1.2.2.3
@@ -59,14 +59,14 @@
public
int decide(LoggingEvent event) {
if(this.levelMin != null) {
- if (event.level.isGreaterOrEqual(levelMin) == false) {
+ if (event.getLevel().isGreaterOrEqual(levelMin) == false) {
// level of event is less than minimum
return Filter.DENY;
}
}
if(this.levelMax != null) {
- if (event.level.toInt() > levelMax.toInt()) {
+ if (event.getLevel().toInt() > levelMax.toInt()) {
// level of event is greater than maximum
// Alas, there is no Level.isGreater method. and using
// a combo of isGreaterOrEqual && !Equal seems worse than
No revision
No revision
1.18.2.3 +2 -2 jakarta-log4j/src/java/org/apache/log4j/xml/XMLLayout.java
Index: XMLLayout.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/xml/XMLLayout.java,v
retrieving revision 1.18.2.2
retrieving revision 1.18.2.3
diff -u -r1.18.2.2 -r1.18.2.3
--- XMLLayout.java 11 Jun 2002 13:20:05 -0000 1.18.2.2
+++ XMLLayout.java 31 Jul 2002 09:25:14 -0000 1.18.2.3
@@ -100,11 +100,11 @@
// We yield to the \r\n heresy.
buf.append("<log4j:event logger=\"");
- buf.append(event.categoryName);
+ buf.append(event.getLoggerName());
buf.append("\" timestamp=\"");
buf.append(event.timeStamp);
buf.append("\" level=\"");
- buf.append(event.level);
+ buf.append(event.getLevel());
buf.append("\" thread=\"");
buf.append(event.getThreadName());
buf.append("\">\r\n");
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>