Author: sdeboy Date: Mon Aug 6 23:49:27 2007 New Revision: 563406 URL: http://svn.apache.org/viewvc?view=rev&rev=563406 Log: - added logger.dtd to support processing of java.util.logging dtd-formatted events - added locationInfo support to multicastappender (note: no support for MDC or event properties in XMLLayout/1.2 log4j.dtd, so application/hostname properties won't be sent for udp/multicastappender)
- updated logfilepatternreceiver to support tailing over VFS (VFSlogfilepatternreceiver commit will follow shortly) tested udpappender/receiver, socketappender/receiver, logfilepatternreceiver, xmlsocketreceiver receiving events from java.util.logging sockethandler Modified: logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/net/MulticastAppender.java logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/net/UDPAppender.java logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java Modified: logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/net/MulticastAppender.java URL: http://svn.apache.org/viewvc/logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/net/MulticastAppender.java?view=diff&rev=563406&r1=563405&r2=563406 ============================================================================== --- logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/net/MulticastAppender.java (original) +++ logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/net/MulticastAppender.java Mon Aug 6 23:49:27 2007 @@ -68,6 +68,8 @@ int port = DEFAULT_PORT; MulticastSocket outSocket; private String encoding; + + private boolean locationInfo = false; public MulticastAppender() { super(false); @@ -158,6 +160,10 @@ return; } + if(locationInfo) { + event.getLocationInformation(); + } + if (outSocket != null) { //if the values already exist, don't set (useful when forwarding from a simplesocketserver if ( @@ -169,6 +175,11 @@ event.setProperty(Constants.APPLICATION_KEY, application); } } + + if(locationInfo) { + event.getLocationInformation(); + } + try { StringBuffer buf = new StringBuffer(layout.format(event)); @@ -183,9 +194,6 @@ DatagramPacket dp = new DatagramPacket(payload, payload.length, address, port); outSocket.send(dp); - //remove these properties, in case other appenders need to set them to different values - event.setProperty(Constants.HOSTNAME_KEY, null); - event.setProperty(Constants.APPLICATION_KEY, null); } catch (IOException e) { outSocket = null; LogLog.warn("Detected problem with Multicast connection: " + e); @@ -215,6 +223,22 @@ */ public String getRemoteHost() { return remoteHost; + } + + /** + The <b>LocationInfo</b> option takes a boolean value. If true, + the information sent to the remote host will include location + information. By default no location information is sent to the server. + */ + public void setLocationInfo(boolean locationInfo) { + this.locationInfo = locationInfo; + } + + /** + * Returns value of the <b>LocationInfo</b> option. + */ + public boolean getLocationInfo() { + return locationInfo; } /** Modified: logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/net/UDPAppender.java URL: http://svn.apache.org/viewvc/logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/net/UDPAppender.java?view=diff&rev=563406&r1=563405&r2=563406 ============================================================================== --- logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/net/UDPAppender.java (original) +++ logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/net/UDPAppender.java Mon Aug 6 23:49:27 2007 @@ -218,9 +218,6 @@ DatagramPacket dp = new DatagramPacket(payload, payload.length, address, port); outSocket.send(dp); - //remove these properties, in case other appenders need to set them to different values - event.setProperty(Constants.HOSTNAME_KEY, null); - event.setProperty(Constants.APPLICATION_KEY, null); } catch (IOException e) { outSocket = null; LogLog.warn("Detected problem with UDP connection: " + e); Modified: logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java URL: http://svn.apache.org/viewvc/logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java?view=diff&rev=563406&r1=563405&r2=563406 ============================================================================== --- logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java (original) +++ logging/log4j/companions/receivers/trunk/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java Mon Aug 6 23:49:27 2007 @@ -190,9 +190,10 @@ private String regexp; private Reader reader; + private Pattern regexpPattern; private String timestampPatternText; - private boolean useCurrentThread; +private boolean useCurrentThread; public LogFilePatternReceiver() { keywords.add(TIMESTAMP); @@ -262,6 +263,26 @@ } /** + * When true, this property uses the current Thread to perform the import, + * otherwise when false (the default), a new Thread is created and started to manage + * the import. + * @return + */ + public final boolean isUseCurrentThread() { + return useCurrentThread; + } + + /** + * Sets whether the current Thread or a new Thread is created to perform the import, + * the default being false (new Thread created). + * + * @param useCurrentThread + */ + public final void setUseCurrentThread(boolean useCurrentThread) { + this.useCurrentThread = useCurrentThread; + } + + /** * Accessor * * @return log format @@ -418,56 +439,48 @@ * @param unbufferedReader * @throws IOException */ - protected void process(Reader unbufferedReader) throws IOException { - BufferedReader bufferedReader = new BufferedReader(unbufferedReader); + protected void process(BufferedReader bufferedReader) throws IOException { - Perl5Compiler compiler = new Perl5Compiler(); - Pattern regexpPattern = null; - try { - regexpPattern = compiler.compile(regexp); - } catch (MalformedPatternException mpe) { - throw new RuntimeException("Bad pattern: " + regexp); - } + Perl5Matcher eventMatcher = new Perl5Matcher(); + String line; + while ((line = bufferedReader.readLine()) != null) { + if (eventMatcher.matches(line, regexpPattern)) { + //build an event from the previous match (held in current map) + LoggingEvent event = buildEvent(); + if (event != null) { + if (passesExpression(event)) { + doPost(event); + } + } + currentMap.putAll(processEvent(eventMatcher.getMatch())); + } else { + //getLogger().debug("line doesn't match pattern - must be ") + //may be an exception or additional message lines + additionalLines.add(line); + } + } - Perl5Matcher eventMatcher = new Perl5Matcher(); - String line = null; - getLogger().debug("tailing file: " + tailing); - do { - while ((line = bufferedReader.readLine()) != null) { - if (eventMatcher.matches(line, regexpPattern)) { - //build an event from the previous match (held in current map) - LoggingEvent event = buildEvent(); - if (event != null) { + //process last event if one exists + LoggingEvent event = buildEvent(); + if (event != null) { if (passesExpression(event)) { - doPost(event); + doPost(event); } - } - currentMap.putAll(processEvent(eventMatcher.getMatch())); - } else { - //getLogger().debug("line doesn't match pattern - must be ") - //may be an exception or additional message lines - additionalLines.add(line); + getLogger().debug("no further lines to process in " + fileURL); } - } + } - //process last event if one exists - LoggingEvent event = buildEvent(); - if (event != null) { - if (passesExpression(event)) { - doPost(event); - } - getLogger().debug("no further lines to process in " + fileURL); - } - try { - synchronized (this) { - wait(2000); + /** + * create the regular expression pattern using the input regular expression + */ + protected void createPattern() { + Perl5Compiler compiler = new Perl5Compiler(); + try { + regexpPattern = compiler.compile(regexp); + } catch (MalformedPatternException mpe) { + throw new RuntimeException("Bad pattern: " + regexp); } - } catch (InterruptedException ie) { - } - } while (tailing); - getLogger().debug("processing " + fileURL + " complete"); - shutdown(); - } + } /** * Helper method that supports the evaluation of the expression @@ -802,57 +815,51 @@ * Read and process the log file. */ public void activateOptions() { - Runnable runnable = new Runnable() { - public void run() { - initialize(); - while (reader == null) { - getLogger().info("attempting to load file: " + getFileURL()); - try { - reader = new InputStreamReader(new URL(getFileURL()).openStream()); - } catch (FileNotFoundException fnfe) { - getLogger().info("file not available - will try again in 10 seconds"); - synchronized(this) { - try { - wait(10000); - } catch (InterruptedException ie){} - } - } catch (IOException ioe) { - getLogger().warn("unable to load file", ioe); - return; - } - } - try { - process(reader); - } catch (IOException ioe) { - //io exception - probably shut down - getLogger().info("stream closed"); + Runnable runnable = new Runnable() { + public void run() { + initialize(); + while (reader == null) { + getLogger().info("attempting to load file: " + getFileURL()); + try { + reader = new InputStreamReader(new URL(getFileURL()).openStream()); + } catch (FileNotFoundException fnfe) { + getLogger().info("file not available - will try again in 10 seconds"); + synchronized (this) { + try { + wait(10000); + } catch (InterruptedException ie) {} + } + } catch (IOException ioe) { + getLogger().warn("unable to load file", ioe); + return; + } + } + try { + BufferedReader bufferedReader = new BufferedReader(reader); + createPattern(); + do { + getLogger().debug("tailing file: " + tailing); + process(bufferedReader); + try { + synchronized (this) { + wait(2000); + } + } catch (InterruptedException ie) { + } + } while (tailing); + + } catch (IOException ioe) { + //io exception - probably shut down + getLogger().info("stream closed"); + } + getLogger().debug("processing " + fileURL + " complete"); + shutdown(); + } + }; + if(useCurrentThread) { + runnable.run(); + }else { + new Thread(runnable, "LogFilePatternReceiver-"+getName()).start(); } - } - }; - if(useCurrentThread) { - runnable.run(); - }else { - new Thread(runnable, "LogFilePatternReceiver-"+getName()).start(); - } - } - - /** - * When true, this property uses the current Thread to perform the import, - * otherwise when false (the default), a new Thread is created and started to manage - * the import. - * @return - */ - public final boolean isUseCurrentThread() { - return useCurrentThread; - } - - /** - * Sets whether the current Thread or a new Thread is created to perform the import, - * the default being false (new Thread created). - * - * @param useCurrentThread - */ - public final void setUseCurrentThread(boolean useCurrentThread) { - this.useCurrentThread = useCurrentThread; } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]