ceki 2004/11/20 07:13:05
Modified: src/java/org/apache/log4j/db DBReceiver.java
DBReceiverJob.java
tests/input/net socketServer2.properties
socketServer4.properties socketServer3.properties
socketServer1.properties socketServer5.properties
socketServer6.properties socketServer8.properties
socketServer7.properties
src/java/org/apache/log4j/helpers FileWatchdog.java
SyslogWriter.java
src/java/org/apache/log4j/varia FallbackErrorHandler.java
LevelMatchFilter.java
src/java/org/apache/log4j/xml SAXErrorHandler.java
src/java/org/apache/log4j/spi Filter.java
tests/src/java/org/apache/log4j/net ShortSocketServer.java
src/java/org/apache/log4j/net JMSAppender.java
tests/src/java/org/apache/log4j/varia
ErrorHandlerTestCase.java
Log:
LogLog related changes
Revision Changes Path
1.13 +1 -2
logging-log4j/src/java/org/apache/log4j/db/DBReceiver.java
Index: DBReceiver.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/db/DBReceiver.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- DBReceiver.java 19 Nov 2004 15:20:06 -0000 1.12
+++ DBReceiver.java 20 Nov 2004 15:13:04 -0000 1.13
@@ -17,7 +17,6 @@
package org.apache.log4j.db;
import org.apache.log4j.LogManager;
-import org.apache.log4j.helpers.LogLog;
import org.apache.log4j.plugins.Pauseable;
import org.apache.log4j.plugins.Receiver;
import org.apache.log4j.scheduler.Scheduler;
@@ -81,7 +80,7 @@
* @see org.apache.log4j.plugins.Plugin#shutdown()
*/
public void shutdown() {
- LogLog.info("removing receiverJob from the Scheduler.");
+ getLogger().info("removing receiverJob from the Scheduler.");
Scheduler scheduler = LogManager.getSchedulerInstance();
scheduler.delete(receiverJob);
1.6 +3 -4
logging-log4j/src/java/org/apache/log4j/db/DBReceiverJob.java
Index: DBReceiverJob.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/db/DBReceiverJob.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DBReceiverJob.java 20 Nov 2004 12:47:06 -0000 1.5
+++ DBReceiverJob.java 20 Nov 2004 15:13:04 -0000 1.6
@@ -19,7 +19,6 @@
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.helpers.Constants;
-import org.apache.log4j.helpers.LogLog;
import org.apache.log4j.scheduler.Job;
import org.apache.log4j.spi.LoggerRepository;
import org.apache.log4j.spi.LoggingEvent;
@@ -40,7 +39,7 @@
*/
class DBReceiverJob implements Job {
- static final Logger logger = Logger.getLogger(DBReceiverJob.class);
+ Logger logger = Logger.getLogger(DBReceiverJob.class);
long lastId = 0;
@@ -51,7 +50,7 @@
}
public void execute() {
- LogLog.info("DBReceiverJob.execute() called");
+ logger.info("DBReceiverJob.execute() called");
Connection connection = null;
@@ -137,7 +136,7 @@
statement.close();
statement = null;
} catch (SQLException sqle) {
- LogLog.error("*************Problem receiving events", sqle);
+ logger.error("*************Problem receiving events", sqle);
} finally {
closeConnection(connection);
}
1.2 +5 -0 logging-log4j/tests/input/net/socketServer2.properties
Index: socketServer2.properties
===================================================================
RCS file: /home/cvs/logging-log4j/tests/input/net/socketServer2.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- socketServer2.properties 27 May 2004 12:16:57 -0000 1.1
+++ socketServer2.properties 20 Nov 2004 15:13:04 -0000 1.2
@@ -7,3 +7,8 @@
log4j.appender.A.layout=org.apache.log4j.PatternLayout
log4j.appender.A.layout.ConversionPattern=%5p %x [%t] %C (%F:%L) %m%n
+# Prevent internal log4j DEBUG messages from polluting the output.
+log4j.logger.org.apache.log4j.PropertyConfigurator=INFO
+log4j.logger.org.apache.log4j.config.PropertySetter=INFO
+log4j.logger.org.apache.log4j.FileAppender=INFO
+log4j.logger.org.apache.log4j.net.ShortSocketServer=INFO
\ No newline at end of file
1.2 +3 -0 logging-log4j/tests/input/net/socketServer4.properties
Index: socketServer4.properties
===================================================================
RCS file: /home/cvs/logging-log4j/tests/input/net/socketServer4.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- socketServer4.properties 27 May 2004 12:16:57 -0000 1.1
+++ socketServer4.properties 20 Nov 2004 15:13:04 -0000 1.2
@@ -6,3 +6,6 @@
log4j.appender.A.Append=false
log4j.appender.A.layout=org.apache.log4j.PatternLayout
log4j.appender.A.layout.ConversionPattern=%5p %x %X{key1}%X{key4} [%t] %c{1}
- %m%n
+
+# Prevent internal log4j DEBUG messages from polluting the output.
+log4j.logger.org.apache.log4j.net.ShortSocketServer=INFO
\ No newline at end of file
1.2 +3 -0 logging-log4j/tests/input/net/socketServer3.properties
Index: socketServer3.properties
===================================================================
RCS file: /home/cvs/logging-log4j/tests/input/net/socketServer3.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- socketServer3.properties 27 May 2004 12:16:57 -0000 1.1
+++ socketServer3.properties 20 Nov 2004 15:13:04 -0000 1.2
@@ -6,3 +6,6 @@
log4j.appender.A.Append=false
log4j.appender.A.layout=org.apache.log4j.PatternLayout
log4j.appender.A.layout.ConversionPattern=%5p %x [%t] %C (%F:%L) %m%n
+
+# Prevent internal log4j DEBUG messages from polluting the output.
+log4j.logger.org.apache.log4j.net.ShortSocketServer=INFO
\ No newline at end of file
1.3 +1 -0 logging-log4j/tests/input/net/socketServer1.properties
Index: socketServer1.properties
===================================================================
RCS file: /home/cvs/logging-log4j/tests/input/net/socketServer1.properties,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- socketServer1.properties 20 Nov 2004 13:05:40 -0000 1.2
+++ socketServer1.properties 20 Nov 2004 15:13:04 -0000 1.3
@@ -11,3 +11,4 @@
log4j.logger.org.apache.log4j.PropertyConfigurator=INFO
log4j.logger.org.apache.log4j.config.PropertySetter=INFO
log4j.logger.org.apache.log4j.FileAppender=INFO
+log4j.logger.org.apache.log4j.net.ShortSocketServer=INFO
\ No newline at end of file
1.2 +3 -0 logging-log4j/tests/input/net/socketServer5.properties
Index: socketServer5.properties
===================================================================
RCS file: /home/cvs/logging-log4j/tests/input/net/socketServer5.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- socketServer5.properties 27 May 2004 12:16:57 -0000 1.1
+++ socketServer5.properties 20 Nov 2004 15:13:04 -0000 1.2
@@ -6,3 +6,6 @@
log4j.appender.A.Append=false
log4j.appender.A.layout=org.apache.log4j.PatternLayout
log4j.appender.A.layout.ConversionPattern=%5p %x %X{key1}%X{key5} [%t] %c{1}
- %m%n
+
+# Prevent internal log4j DEBUG messages from polluting the output.
+log4j.logger.org.apache.log4j.net.ShortSocketServer=INFO
\ No newline at end of file
1.2 +3 -0 logging-log4j/tests/input/net/socketServer6.properties
Index: socketServer6.properties
===================================================================
RCS file: /home/cvs/logging-log4j/tests/input/net/socketServer6.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- socketServer6.properties 27 May 2004 12:16:57 -0000 1.1
+++ socketServer6.properties 20 Nov 2004 15:13:04 -0000 1.2
@@ -6,3 +6,6 @@
log4j.appender.A.Append=false
log4j.appender.A.layout=org.apache.log4j.PatternLayout
log4j.appender.A.layout.ConversionPattern=%5p %x %X{hostID} %X{key6} [%t]
%c{1} - %m%n
+
+# Prevent internal log4j DEBUG messages from polluting the output.
+log4j.logger.org.apache.log4j.net.ShortSocketServer=INFO
\ No newline at end of file
1.2 +3 -0 logging-log4j/tests/input/net/socketServer8.properties
Index: socketServer8.properties
===================================================================
RCS file: /home/cvs/logging-log4j/tests/input/net/socketServer8.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- socketServer8.properties 27 May 2004 12:16:57 -0000 1.1
+++ socketServer8.properties 20 Nov 2004 15:13:04 -0000 1.2
@@ -6,3 +6,6 @@
log4j.appender.A.Append=false
log4j.appender.A.layout=org.apache.log4j.PatternLayout
log4j.appender.A.layout.ConversionPattern=%5p %x %X{hostID} %X{key8} [%t]
%c{1} - %m%n
+
+# Prevent internal log4j DEBUG messages from polluting the output.
+log4j.logger.org.apache.log4j.net.ShortSocketServer=INFO
\ No newline at end of file
1.2 +3 -0 logging-log4j/tests/input/net/socketServer7.properties
Index: socketServer7.properties
===================================================================
RCS file: /home/cvs/logging-log4j/tests/input/net/socketServer7.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- socketServer7.properties 27 May 2004 12:16:57 -0000 1.1
+++ socketServer7.properties 20 Nov 2004 15:13:04 -0000 1.2
@@ -6,3 +6,6 @@
log4j.appender.A.Append=false
log4j.appender.A.layout=org.apache.log4j.PatternLayout
log4j.appender.A.layout.ConversionPattern=%5p %x %X{hostID} %X{key7} [%t]
%c{1} - %m%n
+
+# Prevent internal log4j DEBUG messages from polluting the output.
+log4j.logger.org.apache.log4j.net.ShortSocketServer=INFO
\ No newline at end of file
1.6 +41 -36
logging-log4j/src/java/org/apache/log4j/helpers/FileWatchdog.java
Index: FileWatchdog.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/helpers/FileWatchdog.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FileWatchdog.java 5 May 2003 20:42:55 -0000 1.5
+++ FileWatchdog.java 20 Nov 2004 15:13:04 -0000 1.6
@@ -1,17 +1,27 @@
/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
+ * Copyright 1999,2004 The Apache Software Foundation.
*
- * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
- * the LICENSE file.
+ * 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.
*/
// Contributors: Mathias Bogaert
-
package org.apache.log4j.helpers;
import java.io.File;
-import org.apache.log4j.helpers.LogLog;
+
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+
/**
Check every now and then that a certain file has not changed. If it
@@ -21,28 +31,27 @@
@author Ceki Gülcü
@since version 0.9.1 */
public abstract class FileWatchdog extends Thread {
-
/**
The default delay between every file modification check, set to 60
seconds. */
- static final public long DEFAULT_DELAY = 60000;
+ public static final long DEFAULT_DELAY = 60000;
/**
The name of the file to observe for changes.
*/
protected String filename;
+
+ private Logger logger = LogManager.getLogger(SyslogWriter.class);
/**
The delay to observe between every check. By default set [EMAIL
PROTECTED]
#DEFAULT_DELAY}. */
- protected long delay = DEFAULT_DELAY;
-
+ protected long delay = DEFAULT_DELAY;
File file;
- long lastModif = 0;
+ long lastModif = 0;
boolean warnedAlready = false;
boolean interrupted = false;
- protected
- FileWatchdog(String filename) {
+ protected FileWatchdog(String filename) {
this.filename = filename;
file = new File(filename);
setDaemon(true);
@@ -52,49 +61,45 @@
/**
Set the delay to observe between each check of the file changes.
*/
- public
- void setDelay(long delay) {
+ public void setDelay(long delay) {
this.delay = delay;
}
- abstract
- protected
- void doOnChange();
+ protected abstract void doOnChange();
- protected
- void checkAndConfigure() {
+ protected void checkAndConfigure() {
boolean fileExists;
try {
fileExists = file.exists();
- } catch(SecurityException e) {
- LogLog.warn("Was not allowed to read check file existance, file:["+
- filename+"].");
+ } catch (SecurityException e) {
+ logger.warn(
+ "Was not allowed to read check file existance, file:[" + filename
+ + "].");
interrupted = true; // there is no point in continuing
return;
}
- if(fileExists) {
+ if (fileExists) {
long l = file.lastModified(); // this can also throw a
SecurityException
- if(l > lastModif) { // however, if we reached this point this
- lastModif = l; // is very unlikely.
- doOnChange();
- warnedAlready = false;
+ if (l > lastModif) { // however, if we reached this point this
+ lastModif = l; // is very unlikely.
+ doOnChange();
+ warnedAlready = false;
}
} else {
- if(!warnedAlready) {
- LogLog.debug("["+filename+"] does not exist.");
- warnedAlready = true;
+ if (!warnedAlready) {
+ logger.debug("[" + filename + "] does not exist.");
+ warnedAlready = true;
}
}
}
- public
- void run() {
- while(!interrupted) {
+ public void run() {
+ while (!interrupted) {
try {
Thread.sleep(delay);
- } catch(InterruptedException e) {
- // no interruption expected
+ } catch (InterruptedException e) {
+ // no interruption expected
}
checkAndConfigure();
}
1.7 +7 -2
logging-log4j/src/java/org/apache/log4j/helpers/SyslogWriter.java
Index: SyslogWriter.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/helpers/SyslogWriter.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SyslogWriter.java 20 Nov 2004 14:33:53 -0000 1.6
+++ SyslogWriter.java 20 Nov 2004 15:13:04 -0000 1.7
@@ -25,6 +25,9 @@
import java.net.SocketException;
import java.net.UnknownHostException;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+
/**
SyslogWriter is a wrapper around the java.net.DatagramSocket class
@@ -38,13 +41,15 @@
private InetAddress address;
private DatagramSocket ds;
+ private Logger logger = LogManager.getLogger(SyslogWriter.class);
+
public SyslogWriter(String syslogHost) {
this.syslogHost = syslogHost;
try {
this.address = InetAddress.getByName(syslogHost);
} catch (UnknownHostException e) {
- LogLog.error(
+ logger.error(
"Could not find " + syslogHost + ". All logging will FAIL.", e);
}
@@ -52,7 +57,7 @@
this.ds = new DatagramSocket();
} catch (SocketException e) {
e.printStackTrace();
- LogLog.error(
+ logger.error(
"Could not instantiate DatagramSocket to " + syslogHost
+ ". All logging will FAIL.", e);
}
1.9 +13 -14
logging-log4j/src/java/org/apache/log4j/varia/FallbackErrorHandler.java
Index: FallbackErrorHandler.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/varia/FallbackErrorHandler.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- FallbackErrorHandler.java 26 May 2004 17:19:37 -0000 1.8
+++ FallbackErrorHandler.java 20 Nov 2004 15:13:04 -0000 1.9
@@ -17,8 +17,8 @@
package org.apache.log4j.varia;
import org.apache.log4j.Appender;
+import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
-import org.apache.log4j.helpers.LogLog;
import org.apache.log4j.spi.ErrorHandler;
import org.apache.log4j.spi.LoggingEvent;
@@ -42,6 +42,7 @@
Appender backup;
Appender primary;
Vector loggers;
+ private Logger logger = LogManager.getLogger(FallbackErrorHandler.class);
public FallbackErrorHandler() {
}
@@ -61,7 +62,7 @@
loggers that we need to search for in case of appender failure.
*/
public void addLogger(Logger logger) {
- LogLog.debug("FB: Adding logger [" + logger.getName() + "].");
+ logger.debug("FB: Adding logger [" + logger.getName() + "].");
if (loggers == null) {
loggers = new Vector();
@@ -91,23 +92,21 @@
*/
public void error(
String message, Exception e, int errorCode, LoggingEvent event) {
- LogLog.debug("FB: The following error reported: " + message, e);
- LogLog.debug("FB: INITIATING FALLBACK PROCEDURE.");
+ logger.debug("FB: The following error reported: " + message, e);
+ logger.debug("FB: INITIATING FALLBACK PROCEDURE.");
for (int i = 0; i < loggers.size(); i++) {
Logger l = (Logger) loggers.elementAt(i);
- LogLog.debug(
- "FB: Searching for [" + primary.getName() + "] in logger ["
- + l.getName() + "].");
+ logger.debug(
+ "FB: Searching for [{}] in logger [{}].", primary.getName(),
l.getName());
//if(l.isAttached(primary)) {
- LogLog.debug(
+ logger.debug(
"FB: Replacing [" + primary.getName() + "] by [" + backup.getName()
+ "] in logger [" + l.getName() + "].");
l.removeAppender(primary);
- LogLog.debug(
- "FB: Adding appender [" + backup.getName() + "] to logger "
- + l.getName());
+ logger.debug(
+ "FB: Adding appender [{}] to logger {}", backup.getName(),
l.getName());
l.addAppender(backup);
}
}
@@ -135,8 +134,8 @@
The appender to which this error handler is attached.
*/
public void setAppender(Appender primary) {
- LogLog.debug(
- "FB: Setting primary appender to [" + primary.getName() + "].");
+ logger.debug(
+ "FB: Setting primary appender to [{}].", primary.getName());
this.primary = primary;
}
@@ -144,7 +143,7 @@
Set the backup appender.
*/
public void setBackupAppender(Appender backup) {
- LogLog.debug("FB: Setting backup appender to [" + backup.getName() +
"].");
+ logger.debug("FB: Setting backup appender to [{}].", backup.getName());
this.backup = backup;
}
}
1.9 +0 -7
logging-log4j/src/java/org/apache/log4j/varia/LevelMatchFilter.java
Index: LevelMatchFilter.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/varia/LevelMatchFilter.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- LevelMatchFilter.java 19 May 2004 13:15:44 -0000 1.8
+++ LevelMatchFilter.java 20 Nov 2004 15:13:04 -0000 1.9
@@ -17,7 +17,6 @@
package org.apache.log4j.varia;
import org.apache.log4j.Level;
-import org.apache.log4j.helpers.LogLog;
import org.apache.log4j.helpers.OptionConverter;
import org.apache.log4j.spi.Filter;
import org.apache.log4j.spi.LoggingEvent;
@@ -50,7 +49,6 @@
public void setLevelToMatch(String level) {
levelToMatch = OptionConverter.toLevel(level, null);
- LogLog.debug("***Level to match set to " + levelToMatch);
}
public String getLevelToMatch() {
@@ -82,14 +80,9 @@
return Filter.NEUTRAL;
}
- LogLog.debug(
- "*** levelToMatch is " + levelToMatch + ", event.level is "
- + event.getLevel());
-
boolean matchOccured = false;
if (this.levelToMatch.equals(event.getLevel())) {
- LogLog.debug("**********matchOccured");
matchOccured = true;
}
1.3 +31 -22
logging-log4j/src/java/org/apache/log4j/xml/SAXErrorHandler.java
Index: SAXErrorHandler.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/xml/SAXErrorHandler.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SAXErrorHandler.java 12 Oct 2001 07:05:12 -0000 1.2
+++ SAXErrorHandler.java 20 Nov 2004 15:13:04 -0000 1.3
@@ -1,37 +1,46 @@
/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
+ * Copyright 1999,2004 The Apache Software Foundation.
*
- * This software is published under the terms of the Apache Software
- * License version 1.1, a copy of which has been included with this
- * distribution in the LICENSE.txt file. */
+ * 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.log4j.xml;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXParseException;
-import org.apache.log4j.helpers.LogLog;
-public class SAXErrorHandler implements ErrorHandler {
- public
- void error(SAXParseException ex) {
- LogLog.error("Parsing error on line "+ex.getLineNumber()+" and column "
- +ex.getColumnNumber());
- LogLog.error(ex.getMessage(), ex.getException());
+public class SAXErrorHandler implements ErrorHandler {
+ Logger logger = LogManager.getLogger(SAXErrorHandler.class);
+
+ public void error(SAXParseException ex) {
+ logger.error(
+ "Parsing error on line " + ex.getLineNumber() + " and column "
+ + ex.getColumnNumber());
+ logger.error(ex.getMessage(), ex.getException());
//LogLog.error("pid="+ex.getPublicId()+" sid="+ex.getSystemId());
}
-
- public
- void fatalError(SAXParseException ex) {
+
+ public void fatalError(SAXParseException ex) {
error(ex);
}
-
- public
- void warning(SAXParseException ex) {
- LogLog.warn("Parsing error on line "+ex.getLineNumber()+" and column "
- +ex.getColumnNumber());
- LogLog.warn(ex.getMessage(), ex.getException());
- }
-
+ public void warning(SAXParseException ex) {
+ logger.warn(
+ "Parsing error on line " + ex.getLineNumber() + " and column "
+ + ex.getColumnNumber());
+ logger.warn(ex.getMessage(), ex.getException());
+ }
}
1.7 +17 -0 logging-log4j/src/java/org/apache/log4j/spi/Filter.java
Index: Filter.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/spi/Filter.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Filter.java 27 Feb 2004 16:47:34 -0000 1.6
+++ Filter.java 20 Nov 2004 15:13:04 -0000 1.7
@@ -16,6 +16,8 @@
package org.apache.log4j.spi;
+//import org.apache.log4j.LogManager;
+//import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent;
@@ -111,4 +113,19 @@
public Filter getNext() {
return next;
}
+
+ /**
+ * Return an instance specific logger to be used by the Filter itself.
+ * This logger is not intended to be used by Mrs. Piggy, our proverbial
user,
+ * hence the protected keyword.
+ *
+ * @return instance specific logger
+ */
+// protected Logger getLogger() {
+// if(logger == null) {
+// logger = LogManager.getLogger(this.getClass().getName());
+// }
+// return logger;
+// }
+
}
1.6 +20 -20
logging-log4j/tests/src/java/org/apache/log4j/net/ShortSocketServer.java
Index: ShortSocketServer.java
===================================================================
RCS file:
/home/cvs/logging-log4j/tests/src/java/org/apache/log4j/net/ShortSocketServer.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ShortSocketServer.java 15 May 2004 15:23:51 -0000 1.5
+++ ShortSocketServer.java 20 Nov 2004 15:13:05 -0000 1.6
@@ -1,41 +1,41 @@
/*
* Copyright 1999,2004 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.log4j.net;
-import java.net.ServerSocket;
-import java.net.Socket;
+package org.apache.log4j.net;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.MDC;
import org.apache.log4j.PropertyConfigurator;
-import org.apache.log4j.helpers.LogLog;
import org.apache.log4j.net.SocketNode;
+import java.net.ServerSocket;
+import java.net.Socket;
+
/**
* This SocketServer exits after certain number of connections from a
* client. This number is determined the totalsTest parameter, that is
* the first argument on the commmand line. The second argument,
* prefix, determines the prefix of the configuration file to
- * use.
- *
- * Each run of the server will use a different properties file. For the i-th
+ * use.
+ *
+ * Each run of the server will use a different properties file. For the i-th
* run, the path to the file is (prefix+i+".properties").
- *
+ *
* There is strong coupling between this class and SocketServerTestCase. When
* a test case in SocketServerTestCase tears down its envrionment, it will
* close its SocketAppender which will cause the SocketNode thread to die,
@@ -44,10 +44,9 @@
*
* @author Ceki Gulcu */
public class ShortSocketServer {
- static Logger cat = Logger.getLogger(ShortSocketServer.class);
+ static Logger logger = Logger.getLogger(ShortSocketServer.class);
- public static void main(String[] args)
- throws Exception {
+ public static void main(String[] args) throws Exception {
int totalTests = 0;
String prefix = null;
@@ -58,7 +57,7 @@
usage("Wrong number of arguments.");
}
- LogLog.debug("Listening on port " + SocketServerTestCase.PORT);
+ logger.debug("Listening on port " + SocketServerTestCase.PORT);
ServerSocket serverSocket = new ServerSocket(SocketServerTestCase.PORT);
@@ -66,11 +65,11 @@
for (int i = 1; i <= totalTests; i++) {
PropertyConfigurator.configure(prefix + i + ".properties");
- LogLog.debug("Waiting to accept a new client.");
+ logger.debug("Waiting to accept a new client.");
Socket socket = serverSocket.accept();
- LogLog.debug("Connected to client at " + socket.getInetAddress());
- LogLog.debug("Starting new socket node.");
+ logger.debug("Connected to client at " + socket.getInetAddress());
+ logger.debug("Starting new socket node.");
SocketNode sn = new SocketNode(socket,
LogManager.getLoggerRepository());
Thread t = new Thread(sn);
@@ -80,10 +79,11 @@
}
}
-
static void usage(String msg) {
System.err.println(msg);
- System.err.println("Usage: java " + ShortSocketServer.class.getName() +
" totalTests configFilePrefix");
+ System.err.println(
+ "Usage: java " + ShortSocketServer.class.getName()
+ + " totalTests configFilePrefix");
System.exit(1);
}
}
1.16 +126 -118
logging-log4j/src/java/org/apache/log4j/net/JMSAppender.java
Index: JMSAppender.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/net/JMSAppender.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- JMSAppender.java 20 May 2004 15:38:00 -0000 1.15
+++ JMSAppender.java 20 Nov 2004 15:13:05 -0000 1.16
@@ -1,30 +1,41 @@
/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
+ * Copyright 1999,2004 The Apache Software Foundation.
*
- * This software is published under the terms of the Apache Software
- * License version 1.1, a copy of which has been included with this
- * distribution in the LICENSE.txt file. */
+ * 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.log4j.net;
import org.apache.log4j.AppenderSkeleton;
-import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.spi.ErrorCode;
-import org.apache.log4j.helpers.LogLog;
+import org.apache.log4j.spi.LoggingEvent;
import java.util.Properties;
+
+import javax.jms.ObjectMessage;
+import javax.jms.Session;
+import javax.jms.Topic;
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.InitialContext;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
+
/**
* A simple appender that publishes events to a JMS Topic. The events
* are serialized and transmitted as JMS message type [EMAIL PROTECTED]
@@ -44,12 +55,12 @@
<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,
@@ -77,7 +88,7 @@
</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
@@ -89,7 +100,6 @@
@author Ceki Gülcü */
public class JMSAppender extends AppenderSkeleton {
-
String securityPrincipalName;
String securityCredentials;
String initialContextFactoryName;
@@ -100,13 +110,11 @@
String userName;
String password;
boolean locationInfo;
-
- TopicConnection topicConnection;
+ TopicConnection topicConnection;
TopicSession topicSession;
- TopicPublisher topicPublisher;
+ TopicPublisher topicPublisher;
- public
- JMSAppender() {
+ public JMSAppender() {
}
/**
@@ -114,16 +122,14 @@
string value. Its value will be used to lookup the appropriate
<code>TopicConnectionFactory</code> from the JNDI context.
*/
- public
- void setTopicConnectionFactoryBindingName(String tcfBindingName) {
+ public void setTopicConnectionFactoryBindingName(String tcfBindingName) {
this.tcfBindingName = tcfBindingName;
}
/**
Returns the value of the <b>TopicConnectionFactoryBindingName</b>
option.
*/
- public
- String getTopicConnectionFactoryBindingName() {
+ public String getTopicConnectionFactoryBindingName() {
return tcfBindingName;
}
@@ -132,26 +138,22 @@
string value. Its value will be used to lookup the appropriate
<code>Topic</code> from the JNDI context.
*/
- public
- void setTopicBindingName(String topicBindingName) {
+ public void setTopicBindingName(String topicBindingName) {
this.topicBindingName = topicBindingName;
}
/**
Returns the value of the <b>TopicBindingName</b> option.
*/
- public
- String getTopicBindingName() {
+ public String getTopicBindingName() {
return topicBindingName;
}
-
/**
* Returns value of the <b>LocationInfo</b> property which determines
whether
- * caller's location info is sent to the remote subscriber.
+ * caller's location info is sent to the remote subscriber.
* */
- public
- boolean getLocationInfo() {
+ public boolean getLocationInfo() {
return locationInfo;
}
@@ -159,75 +161,80 @@
* Options are activated and become effective only after calling
* this method.*/
public void activateOptions() {
- TopicConnectionFactory topicConnectionFactory;
+ TopicConnectionFactory topicConnectionFactory;
try {
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);
+ getLogger().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 {
+ getLogger().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 {
+ getLogger().warn(
+ "You have set SecurityPrincipalName option but not the "
+ + "SecurityCredentials. This is likely to cause problems.");
+ }
+ }
+ jndi = new InitialContext(env);
} else {
- jndi = new InitialContext();
+ jndi = new InitialContext();
}
- LogLog.debug("Looking up ["+tcfBindingName+"]");
- topicConnectionFactory = (TopicConnectionFactory) lookup(jndi,
tcfBindingName);
- LogLog.debug("About to create TopicConnection.");
- if(userName != null) {
- topicConnection =
topicConnectionFactory.createTopicConnection(userName,
-
password);
+ getLogger().debug("Looking up [" + tcfBindingName + "]");
+ topicConnectionFactory =
+ (TopicConnectionFactory) lookup(jndi, tcfBindingName);
+ getLogger().debug("About to create TopicConnection.");
+ if (userName != null) {
+ topicConnection =
+ topicConnectionFactory.createTopicConnection(userName, password);
} else {
- topicConnection = topicConnectionFactory.createTopicConnection();
+ topicConnection = topicConnectionFactory.createTopicConnection();
}
- LogLog.debug("Creating TopicSession, non-transactional, "
- +"in AUTO_ACKNOWLEDGE mode.");
- topicSession = topicConnection.createTopicSession(false,
-
Session.AUTO_ACKNOWLEDGE);
+ getLogger().debug(
+ "Creating TopicSession, non-transactional, "
+ + "in AUTO_ACKNOWLEDGE mode.");
+ topicSession =
+ topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
- LogLog.debug("Looking up topic name ["+topicBindingName+"].");
+ getLogger().debug("Looking up topic name [" + topicBindingName + "].");
Topic topic = (Topic) lookup(jndi, topicBindingName);
- LogLog.debug("Creating TopicPublisher.");
+ getLogger().debug("Creating TopicPublisher.");
topicPublisher = topicSession.createPublisher(topic);
-
- LogLog.debug("Starting TopicConnection.");
+
+ getLogger().debug("Starting TopicConnection.");
topicConnection.start();
jndi.close();
- } catch(Exception e) {
- errorHandler.error("Error while activating options for appender named
["+name+
- "].", e, ErrorCode.GENERIC_FAILURE);
+ } 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 {
try {
return ctx.lookup(name);
- } catch(NameNotFoundException e) {
- LogLog.error("Could not find name ["+name+"].");
+ } catch (NameNotFoundException e) {
+ getLogger().error("Could not find name [" + name + "].");
throw e;
}
}
@@ -235,16 +242,16 @@
protected boolean checkEntryConditions() {
String fail = null;
- if(this.topicConnection == null) {
+ if (this.topicConnection == null) {
fail = "No TopicConnection";
- } else if(this.topicSession == null) {
+ } else if (this.topicSession == null) {
fail = "No TopicSession";
- } else if(this.topicPublisher == null) {
+ } else if (this.topicPublisher == null) {
fail = "No TopicPublisher";
}
- if(fail != null) {
- errorHandler.error(fail +" for JMSAppender named ["+name+"].");
+ if (fail != null) {
+ errorHandler.error(fail + " for JMSAppender named [" + name + "].");
return false;
} else {
return true;
@@ -256,21 +263,24 @@
appender. A closed appender cannot be re-opened. */
public synchronized void close() {
// The synchronized modifier avoids concurrent append and close
operations
-
- if(this.closed)
+ if (this.closed) {
return;
+ }
- LogLog.debug("Closing appender ["+name+"].");
+ getLogger().debug("Closing appender [" + name + "].");
this.closed = true;
try {
- if(topicSession != null)
- topicSession.close();
- if(topicConnection != null)
- topicConnection.close();
- } catch(Exception e) {
- LogLog.error("Error while closing JMSAppender ["+name+"].", e);
+ if (topicSession != null) {
+ topicSession.close();
+ }
+ if (topicConnection != null) {
+ topicConnection.close();
+ }
+ } catch (Exception e) {
+ getLogger().error("Error while closing JMSAppender [" + name + "].",
e);
}
+
// Help garbage collection
topicPublisher = null;
topicSession = null;
@@ -281,20 +291,21 @@
This method called by [EMAIL PROTECTED] AppenderSkeleton#doAppend}
method to
do most of the real appending work. */
public void append(LoggingEvent event) {
- if(!checkEntryConditions()) {
+ if (!checkEntryConditions()) {
return;
}
try {
ObjectMessage msg = topicSession.createObjectMessage();
- if(locationInfo) {
- event.getLocationInformation();
+ if (locationInfo) {
+ event.getLocationInformation();
}
msg.setObject(event);
topicPublisher.publish(msg);
- } catch(Exception e) {
- errorHandler.error("Could not publish message in JMSAppender
["+name+"].", e,
- ErrorCode.GENERIC_FAILURE);
+ } catch (Exception e) {
+ errorHandler.error(
+ "Could not publish message in JMSAppender [" + name + "].", e,
+ ErrorCode.GENERIC_FAILURE);
}
}
@@ -304,16 +315,16 @@
* meaning of this option.
* */
public String getInitialContextFactoryName() {
- return initialContextFactoryName;
+ return initialContextFactoryName;
}
-
+
/**
* Setting the <b>InitialContextFactoryName</b> method will cause
* this <code>JMSAppender</code> instance to use the [EMAIL PROTECTED]
* 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 [EMAIL PROTECTED] #setProviderURL(String)}.
* */
public void setInitialContextFactoryName(String initialContextFactoryName)
{
@@ -321,32 +332,31 @@
}
public String getProviderURL() {
- return providerURL;
+ return providerURL;
}
public void setProviderURL(String providerURL) {
this.providerURL = providerURL;
}
- String getURLPkgPrefixes( ) {
+ String getURLPkgPrefixes() {
return urlPkgPrefixes;
}
- public void setURLPkgPrefixes(String urlPkgPrefixes ) {
+ public void setURLPkgPrefixes(String urlPkgPrefixes) {
this.urlPkgPrefixes = urlPkgPrefixes;
}
-
+
public String getSecurityCredentials() {
- return securityCredentials;
+ return securityCredentials;
}
public void setSecurityCredentials(String securityCredentials) {
this.securityCredentials = securityCredentials;
}
-
-
+
public String getSecurityPrincipalName() {
- return securityPrincipalName;
+ return securityPrincipalName;
}
public void setSecurityPrincipalName(String securityPrincipalName) {
@@ -354,7 +364,7 @@
}
public String getUserName() {
- return userName;
+ return userName;
}
/**
@@ -369,28 +379,26 @@
}
public String getPassword() {
- return password;
+ return password;
}
/**
- * The paswword to use when creating a topic session.
+ * 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. Due to performance concerns, by default
no
- * location information is sent to the subscriber.
+ /**
+ * If true, the information sent to the remote subscriber will include
+ * caller's location information. Due to performance concerns, by default
no
+ * location information is sent to the subscriber.
* */
public void setLocationInfo(boolean locationInfo) {
this.locationInfo = locationInfo;
}
-
- /**
+ /**
* The JMSAppender sends serialized events and consequently does not
* require a layout.
* */
1.9 +1 -3
logging-log4j/tests/src/java/org/apache/log4j/varia/ErrorHandlerTestCase.java
Index: ErrorHandlerTestCase.java
===================================================================
RCS file:
/home/cvs/logging-log4j/tests/src/java/org/apache/log4j/varia/ErrorHandlerTestCase.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ErrorHandlerTestCase.java 26 May 2004 18:19:53 -0000 1.8
+++ ErrorHandlerTestCase.java 20 Nov 2004 15:13:05 -0000 1.9
@@ -29,8 +29,6 @@
import org.apache.log4j.util.LineNumberFilter;
import org.apache.log4j.util.SunReflectFilter;
import org.apache.log4j.util.Transformer;
-import org.apache.log4j.xml.DOMConfigurator;
-
public class ErrorHandlerTestCase extends TestCase {
static String TEMP = "output/temp";
@@ -60,7 +58,7 @@
}
public void test1() throws Exception {
- DOMConfigurator.configure("input/xml/fallback1.xml");
+
org.apache.log4j.xml.DOMConfigurator.configure("input/xml/fallback1.xml");
common();
ControlFilter cf =
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]