[Jukebox-cvs] CVS update: J4/src/java/gnu/j4/core AbstractSyslog.java PatternFilter.java SwitchFilte
Brought to you by:
vtt
From: CVS B. <vt...@fr...> - 2000-09-13 19:23:48
|
User: vt Date: 00/09/13 12:23:33 Modified: src/java/gnu/j4/core BasicSyslog.java JmxSyslog.java LogMultiplexor.java Makefile.am RegexpFacilityFilter.java RexFacilityFilter.java SwitchFacilityFilter.java Syslog.java SyslogFacilityFilter.java UdpSyslog.java Added: src/java/gnu/j4/core AbstractSyslog.java PatternFilter.java SwitchFilter.java SyslogFilter.java Log: Reworked the configuration model, cleaned up the implementation. Most probably, a lot of other code will break now, but the configuration should stay the same, I guess. To be continued... Revision Changes Path 1.17 +10 -94 J4/src/java/gnu/j4/core/BasicSyslog.java CVSWEB Options: ------------------- CVSWeb: Annotate this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/BasicSyslog.java?annotate=1.17&cvsroot=jukebox4 CVSWeb: View this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/BasicSyslog.java?rev=1.17&content-type=text/x-cvsweb-markup&cvsroot=jukebox4 CVSWeb: Diff to previous version: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/BasicSyslog.java.diff?r1=1.17&r2=1.16&cvsroot=jukebox4 ----------------------------------- Index: BasicSyslog.java =================================================================== RCS file: /usr/local/cvs/J4/src/java/gnu/j4/core/BasicSyslog.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- BasicSyslog.java 2000/08/24 20:35:50 1.16 +++ BasicSyslog.java 2000/09/13 19:23:33 1.17 @@ -43,11 +43,11 @@ * something less complicated, at least for the production versions. * @author Copyright © <a href="mailto:vt...@fr...">Vadim Tkachenko</a> 1995-1998 - * @version $Id: BasicSyslog.java,v 1.16 2000/08/24 20:35:50 vt Exp $ + * @version $Id: BasicSyslog.java,v 1.17 2000/09/13 19:23:33 vt Exp $ * @since Jukebox v4 * @see LogConfigKeywords */ -public class BasicSyslog implements Syslog, LogLevels, LogConfigKeywords { +public class BasicSyslog extends AbstractSyslog { /** * Default timestamp format. @@ -59,20 +59,6 @@ public static final String DEFAULT_DATEFORMAT = "HH:mm:ss:SSS"; /** - * Configuration. - * - * Loaded using the {@link gnu.j4.config.Configuration#createChain - * Configuration#createChain} method, so it's possible to have global, - * user and local config settings. - * - * <p> - * - * The configuration settings are duplicated in this object so we don't - * waste time looking for them logging every single message. - */ - protected Configuration conf; - - /** * Object used to format the timestamp for the output. * * @see LogConfigKeywords#DATEFORMAT_CF @@ -80,11 +66,6 @@ protected SimpleDateFormat dateFormatter; /** - * Facility filter. - */ - protected SyslogFacilityFilter filter = null; - - /** * <code>true</code> if we should display a delay. */ protected boolean shouldDisplayDelay = false; @@ -159,44 +140,10 @@ } - Class filterClass = null; - - try { - String filterClassName = conf.getString(SYSLOG_FILTER_CLASS, "gnu.j4.core.SwitchFacilityFilter"); - - filterClass = Class.forName( filterClassName ); - filter = (SyslogFacilityFilter)filterClass.newInstance(); - filter.init(getConfigFileName()); - - } catch ( ClassNotFoundException cnfex ) { - createDefaultFilter(cnfex); - } catch ( IllegalAccessException iaex ) { - createDefaultFilter(iaex); - } catch ( InstantiationException iex ) { - createDefaultFilter(iex); - } catch ( Throwable t ) { - - System.out.println("Unrecoverable exception, expect further problems:"); - t.printStackTrace(); - - } finally { - logMessage(new LogRecord(Thread.currentThread(), - this, LOG_INFO, Logger.LOG_LOGGER, - "Using "+filter.getClass().getName(), null)); - } - shouldDisplayDelay = conf.getBoolean(DATEFORMAT_DELAY_CF, true); shouldDisplayOwnership = conf.getBoolean(FORMAT_OWNERSHIP_CF, true); } - private void createDefaultFilter(Throwable t) { - filter = new SwitchFacilityFilter(); - filter.init(getConfigFileName()); - logMessage(new LogRecord(Thread.currentThread(), - this, LOG_ERR, "SyslogFilter", - "Can't create the filter, reverting to default", t)); - } - /** * Return the <code>basename(1)</code> of the log configuration file. * @@ -209,53 +156,17 @@ /** * Log the message. * - * - * The resulting string message is first checked against the {@link - * #filter filter}, then, if not rejected, composed and passed to the - * {@link #write write} method to be written to the - * <code>System.out</code>. So if you like the format but want to - * redirect the log output, go to {@link #write write}. - * * @param lr Message to write. */ - public final void logMessage( LogRecord lr ) { - if ( !filter( lr ) ) { - return; - } + public final void write(LogRecord lr) { StringBuffer buffer = new StringBuffer(); - composeMessage( buffer,lr ); - write( buffer.toString() ); + composeMessage(buffer, lr); + write(buffer.toString()); } /** - * This method is intended to provide a level and channel filter. - * - - * Result is used in the {@link #logMessage logMessage} to determine - * whether to actually log this message or not. - - * @param lr Log record to check. - * @return true if the configuration allows this message to be written into the log. - */ - public boolean filter( LogRecord lr ) { - - if ( lr == null ) { - - // VT: FIXME: consider logging this through the normal channels - - (new Error( "null log record, you may want to check what's going on" )).printStackTrace(); - } - - if ( !filter.isEnabled(lr.ll, lr.facility) ) { - return false; - } - - return true; - } - - /** * Compose the string representation of the log record. * @param lr Log record to compose the message from. * @return The log line. @@ -483,5 +394,10 @@ */ public void write( String message ) { System.out.println( message ); + } + + protected void start() { + } + protected void stop() { } } 1.6 +56 -1 J4/src/java/gnu/j4/core/JmxSyslog.java CVSWEB Options: ------------------- CVSWeb: Annotate this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/JmxSyslog.java?annotate=1.6&cvsroot=jukebox4 CVSWeb: View this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/JmxSyslog.java?rev=1.6&content-type=text/x-cvsweb-markup&cvsroot=jukebox4 CVSWeb: Diff to previous version: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/JmxSyslog.java.diff?r1=1.6&r2=1.5&cvsroot=jukebox4 ----------------------------------- Index: JmxSyslog.java =================================================================== RCS file: /usr/local/cvs/J4/src/java/gnu/j4/core/JmxSyslog.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- JmxSyslog.java 2000/06/21 18:10:05 1.5 +++ JmxSyslog.java 2000/09/13 19:23:33 1.6 @@ -21,6 +21,7 @@ import javax.management.NotificationFilter; import javax.management.NotificationListener; +import gnu.j4.config.Configuration; import gnu.j4.jmx.*; /** @@ -30,7 +31,7 @@ * When invoked, becomes a wrapper for the actual log agent. * * @author Copyright © <a href="mailto:vt...@fr...">Vadim Tkachenko</a> 2000 - * @version $Id: JmxSyslog.java,v 1.5 2000/06/21 18:10:05 vt Exp $ + * @version $Id: JmxSyslog.java,v 1.6 2000/09/13 19:23:33 vt Exp $ * @since Jukebox 2.0p5 */ public class JmxSyslog extends NotificationBroadcasterSupport implements Syslog, DynamicMBean, NotificationBroadcaster { @@ -260,4 +261,58 @@ throw new Error("Not Implemented"); } */ + + public void configure(Configuration conf) { + + // Hmm? + } + + private String configurationRoot; + + public final void setConfigurationRoot(String configurationRoot) { + + if ( configurationRoot != null ) { + + throw new IllegalStateException("You cannot reset the configuration root. Destroy this one and instantiate new."); + } + + this.configurationRoot = configurationRoot; + } + + public final String getConfigurationRoot() { + + return configurationRoot; + } + + /** + * True if enabled. + * + * @see #open + * @see #close + */ + private boolean enabled = false; + + public void open() { + + try { + +// start(); + enabled = true; + + } catch ( Throwable t ) { + + // Well, this is very unfortunate. It is not possible to display + // the error through the normal logging channel, the only option + // left is write it to stderr. + + System.err.println(getConfigurationRoot() + ": can't open, cause:"); + t.printStackTrace(); + } + } + + public void close() { + + enabled = false; +// stop(); + } } 1.2 +33 -47 J4/src/java/gnu/j4/core/LogMultiplexor.java CVSWEB Options: ------------------- CVSWeb: Annotate this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/LogMultiplexor.java?annotate=1.2&cvsroot=jukebox4 CVSWeb: View this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/LogMultiplexor.java?rev=1.2&content-type=text/x-cvsweb-markup&cvsroot=jukebox4 CVSWeb: Diff to previous version: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/LogMultiplexor.java.diff?r1=1.2&r2=1.1&cvsroot=jukebox4 ----------------------------------- Index: LogMultiplexor.java =================================================================== RCS file: /usr/local/cvs/J4/src/java/gnu/j4/core/LogMultiplexor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- LogMultiplexor.java 2000/09/13 00:02:35 1.1 +++ LogMultiplexor.java 2000/09/13 19:23:33 1.2 @@ -1,7 +1,7 @@ package gnu.j4.core; import java.util.Enumeration; -import java.util.Vector; +import java.util.Hashtable; import gnu.j4.config.Configurable; import gnu.j4.config.Configuration; @@ -11,43 +11,32 @@ * * Provides an ability to log to multiple atomic logging devices. * + * <p> + * + * It is not recommended to have filter installed in the multiplexor, + * because the different media has different properties where it gets to + * usability (for example, it is not advisable to enable all the levels + * for the console log, though it's perfectly OK to do so for the file + * log). + * + * <p> + * + * However, this provides an excellent quick start easily configurable + * solution and/or generic debug filter. + * * @author Copyright © <a href="mailto:vt...@fr...">Vadim Tkachenko</a> 2000 - * @version $Id: LogMultiplexor.java,v 1.1 2000/09/13 00:02:35 vt Exp $ + * @version $Id: LogMultiplexor.java,v 1.2 2000/09/13 19:23:33 vt Exp $ * @since Jukebox v4 2.0.p10 * @see LogConfigKeywords */ -public class LogMultiplexor implements Syslog, LogLevels, LogConfigKeywords { +public class LogMultiplexor extends AbstractSyslog { /** - * Master configuration. - */ - protected Configuration conf; - - /** * Collection of the logging devices attached to the multiplexor. */ - private Vector targets = new Vector(); + private Hashtable targets = new Hashtable(); - /** - * The log filter. - * - * It is not recommended to have filter installed in the multiplexor, - * because the different media has different properties where it gets to - * usability (for example, it is not advisable to enable all the levels - * for the console log, though it's perfectly OK to do so for the file - * log). - * - * <p> - * - * However, this provides an excellent quick start easily configurable - * solution and/or generic debug filter. - */ - private SyslogFacilityFilter filter = null; - public LogMultiplexor() { - - conf = Configuration.createChain(getConfigFileName()); - configurationChanged(); } /** @@ -55,16 +44,21 @@ */ public void configurationChanged() { - Vector currentNames = new Vector(); - + // VT: FIXME: For now, I'll just kill off all the existing devices + // and reinitialize them, if required. + for ( Enumeration e = targets.elements(); e.hasMoreElements(); ) { - currentNames.addElement(((Configurable)e.nextElement()).getConfigurationRoot()); + Syslog target = (Syslog)targets.get(e.nextElement()); + + target.close(); } // Now that we've collected the names, let's figure out who to kill // and who to leave alone. The configuration has been changed by // now. + + } /** @@ -85,27 +79,19 @@ */ public void add(Syslog syslog) { - targets.addElement(syslog); + targets.put(syslog.getConfigurationRoot(), syslog); } - public void logMessage(LogRecord message) { + public void write(LogRecord message) { - if ( filter == null || filter.isEnabled(message.ll, message.facility) ) { + for ( Enumeration e = targets.elements(); e.hasMoreElements(); ) { - for ( Enumeration e = targets.elements(); e.hasMoreElements(); ) { - - ((Syslog)e.nextElement()).logMessage(message); - } + ((Syslog)e.nextElement()).logMessage(message); } } - - /** - * Return the <code>basename(1)</code> of the log configuration file. - * - * @return {@link LogConfigKeywords#LOG_CF_FILE LogConfigKeywords#LOG_CF_FILE}. - */ - protected String getConfigFileName() { - return LOG_CF_FILE; - } + protected void start() { + } + protected void stop() { + } } 1.19 +7 -4 J4/src/java/gnu/j4/core/Makefile.am CVSWEB Options: ------------------- CVSWeb: Annotate this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/Makefile.am?annotate=1.19&cvsroot=jukebox4 CVSWeb: View this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/Makefile.am?rev=1.19&content-type=text/x-cvsweb-markup&cvsroot=jukebox4 CVSWeb: Diff to previous version: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/Makefile.am.diff?r1=1.19&r2=1.18&cvsroot=jukebox4 ----------------------------------- Index: Makefile.am =================================================================== RCS file: /usr/local/cvs/J4/src/java/gnu/j4/core/Makefile.am,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- Makefile.am 2000/09/13 00:02:35 1.18 +++ Makefile.am 2000/09/13 19:23:33 1.19 @@ -1,9 +1,12 @@ -# $Id: Makefile.am,v 1.18 2000/09/13 00:02:35 vt Exp $ +# $Id: Makefile.am,v 1.19 2000/09/13 19:23:33 vt Exp $ EXTRA_DIST = package.html noinst_PROGRAMS = package BASE_FILES = ANSI.java \ + SyslogFilter.java\ + AbstractSyslogFilter.java \ + AbstractSyslog.java \ AnsiSyslog.java \ BasicSyslog.java \ FileSyslog.java \ @@ -18,10 +21,10 @@ SerializableLogRecord.java \ SimpleQueue.java \ Syslog.java \ - SwitchFacilityFilter.java \ - SyslogFacilityFilter.java \ + SwitchFilter.java \ TimedOutException.java \ - LogMultiplexor.java + LogMultiplexor.java \ + PatternFilter.java JAVA2_FILES = UdpSyslog.java 1.7 +13 -89 J4/src/java/gnu/j4/core/RegexpFacilityFilter.java CVSWEB Options: ------------------- CVSWeb: Annotate this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/RegexpFacilityFilter.java?annotate=1.7&cvsroot=jukebox4 CVSWeb: View this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/RegexpFacilityFilter.java?rev=1.7&content-type=text/x-cvsweb-markup&cvsroot=jukebox4 CVSWeb: Diff to previous version: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/RegexpFacilityFilter.java.diff?r1=1.7&r2=1.6&cvsroot=jukebox4 ----------------------------------- Index: RegexpFacilityFilter.java =================================================================== RCS file: /usr/local/cvs/J4/src/java/gnu/j4/core/RegexpFacilityFilter.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- RegexpFacilityFilter.java 2000/08/04 23:21:46 1.6 +++ RegexpFacilityFilter.java 2000/09/13 19:23:33 1.7 @@ -21,104 +21,28 @@ * required to use this filter, see the documentation for details. * * @author Copyright © <a href="mailto:vt...@fr...">Vadim Tkachenko</a> 1995-1998 - * @version $Id: RegexpFacilityFilter.java,v 1.6 2000/08/04 23:21:46 vt Exp $ + * @version $Id: RegexpFacilityFilter.java,v 1.7 2000/09/13 19:23:33 vt Exp $ */ -public class RegexpFacilityFilter extends SyslogFacilityFilter implements LogConfigKeywords { +public class RegexpFacilityFilter extends PatternFilter { - /** - * Collection of preprocessed patterns to match. - * - * The patterns are specified with the keyword defined by {@link - * LogConfigKeywords#SYSLOG_REX_PATTERN SYSLOG_REX_PATTERN}. - */ - protected Vector patternSet = new Vector(); + protected Pattern createPattern(boolean include, String pattern) throws Throwable { - public void init(String confName) { - super.init(confName); - - Configuration defaultCfg = new Configuration(); - - Vector defaultPattern = new Vector(); - - defaultPattern.addElement(".*"); - defaultPattern.addElement("-\\.DEBUG"); - defaultCfg.put(SYSLOG_REX_PATTERN, defaultPattern); - - conf = Configuration.createChain(confName, defaultCfg); - - try { - - Vector stringPatternSet = conf.getVector(SYSLOG_REX_PATTERN); - - for ( Enumeration e = stringPatternSet.elements(); e.hasMoreElements(); ) { - - String raw = e.nextElement().toString(); - - // First character is '-' (exclude) or '+' or anything else (include). - - boolean include = true; - int patternIndex = 0; - - if ( raw.charAt(0) == '-' ) { - include = false; - patternIndex = 1; - } else if ( raw.charAt(0) == '+' ) { - patternIndex = 1; - } - - String sPattern = raw.substring(patternIndex, raw.length()-1); - RE pattern = new RE(sPattern); - Pattern p = new Pattern(include, pattern); - -// System.err.println("Pattern: " + sPattern); - patternSet.addElement(p); - } - - } catch ( RESyntaxException resex ) { - throw new Error( resex.toString() ); - } + return new RegexpPattern(include, pattern); } - /** - * Find out if the combination of the log level and facility is enabled. - * - * @param ll Log level. - * @param facility Log facility. - * @return true if the given combination is allowed to be written. - */ - public boolean isEnabled( LogLevel ll, String facility ) { - - // First of all, let's glue the level and facility together - - String target = (facility == null)?"NULL_FACILITY":facility - + "." - + ((ll == null)?"NO_LEVEL":ll.toString()); -// System.err.println("Search: " + target); - - boolean include = false; - - for ( Enumeration e = patternSet.elements(); e.hasMoreElements(); ) { + protected class RegexpPattern extends Pattern { + + private RE pattern; - Pattern p = (Pattern)e.nextElement(); + protected RegexpPattern(boolean include, String pattern) throws Throwable { - if ( p.pattern.match(target) ) { + super(include); + this.pattern = new RE(pattern); + } -// System.err.println("Match (" + p.include + "): "+ match.toString()); - include = p.include; - } + protected boolean match(String pattern) { - } -// System.err.println("Final: " + target + ": " + include ); - return include; - } - - protected class Pattern { - boolean include = true; - RE pattern = null; - - private Pattern(boolean include, RE pattern) { - this.include = include; - this.pattern = pattern; + return this.pattern.match(pattern); } } } 1.2 +28 -92 J4/src/java/gnu/j4/core/RexFacilityFilter.java CVSWEB Options: ------------------- CVSWeb: Annotate this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/RexFacilityFilter.java?annotate=1.2&cvsroot=jukebox4 CVSWeb: View this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/RexFacilityFilter.java?rev=1.2&content-type=text/x-cvsweb-markup&cvsroot=jukebox4 CVSWeb: Diff to previous version: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/RexFacilityFilter.java.diff?r1=1.2&r2=1.1&cvsroot=jukebox4 ----------------------------------- Index: RexFacilityFilter.java =================================================================== RCS file: /usr/local/cvs/J4/src/java/gnu/j4/core/RexFacilityFilter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- RexFacilityFilter.java 2000/08/04 23:21:46 1.1 +++ RexFacilityFilter.java 2000/09/13 19:23:33 1.2 @@ -19,110 +19,46 @@ * documentation for details. * * @author Copyright © <a href="mailto:vt...@fr...">Vadim Tkachenko</a> 1995-1998 - * @version $Id: RexFacilityFilter.java,v 1.1 2000/08/04 23:21:46 vt Exp $ + * @version $Id: RexFacilityFilter.java,v 1.2 2000/09/13 19:23:33 vt Exp $ */ -public class RexFacilityFilter extends SyslogFacilityFilter implements LogConfigKeywords { +public class RexFacilityFilter extends PatternFilter { - /** - * Collection of preprocessed patterns to match. - * - * The patterns are specified with the keyword defined by {@link - * LogConfigKeywords#SYSLOG_REX_PATTERN SYSLOG_REX_PATTERN}. - */ - protected Vector patternSet = new Vector(); - - public void init(String confName) { - super.init(confName); - - Configuration defaultCfg = new Configuration(); - - Vector defaultPattern = new Vector(); +// Rex pattern = Rex.build(sPattern); + +// int length = target.length(); +// char buf[] = new char[length]; - defaultPattern.addElement(".*"); - defaultPattern.addElement("-\\.DEBUG"); - defaultCfg.put(SYSLOG_REX_PATTERN, defaultPattern); +// target.getChars(0, length, buf, 0); - conf = Configuration.createChain(confName, defaultCfg); +// RexResult match = p.pattern.match(buf, 0, length); - try { - - Vector stringPatternSet = conf.getVector(SYSLOG_REX_PATTERN); - - for ( Enumeration e = stringPatternSet.elements(); e.hasMoreElements(); ) { - - String raw = e.nextElement().toString(); - - // First character is '-' (exclude) or '+' or anything else (include). - - boolean include = true; - int patternIndex = 0; +// if ( match != null ) { - if ( raw.charAt(0) == '-' ) { - include = false; - patternIndex = 1; - } else if ( raw.charAt(0) == '+' ) { - patternIndex = 1; - } - - String sPattern = raw.substring(patternIndex, raw.length()-1); - Rex pattern = Rex.build(sPattern); - Pattern p = new Pattern(include, pattern); - -// System.err.println("Pattern: " + sPattern); - patternSet.addElement(p); - } - - } catch ( RegExprSyntaxException resex ) { - throw new Error( resex.toString() ); - } - } + protected Pattern createPattern(boolean include, String pattern) throws Throwable { - /** - * Find out if the combination of the log level and facility is enabled. - * - * @param ll Log level. - * @param facility Log facility. - * @return true if the given combination is allowed to be written. - */ - public boolean isEnabled( LogLevel ll, String facility ) { + return new RexPattern(include, pattern); + } - // First of all, let's glue the level and facility together - - String target = (facility == null)?"NULL_FACILITY":facility - + "." - + ((ll == null)?"NO_LEVEL":ll.toString()); -// System.err.println("Search: " + target); - - int length = target.length(); - char buf[] = new char[length]; - - target.getChars(0, length, buf, 0); - - boolean include = false; - - for ( Enumeration e = patternSet.elements(); e.hasMoreElements(); ) { + protected class RexPattern extends Pattern { + + private Rex pattern; - Pattern p = (Pattern)e.nextElement(); - RexResult match = p.pattern.match(buf, 0, length); + protected RexPattern(boolean include, String pattern) throws Throwable { - if ( match != null ) { + super(include); + this.pattern = Rex.build(pattern); + } -// System.err.println("Match (" + p.include + "): "+ match.toString()); - include = p.include; - } + protected boolean match(String pattern) { - } -// System.err.println("Final: " + target + ": " + include ); - return include; - } - - protected class Pattern { - boolean include = true; - Rex pattern = null; - - private Pattern(boolean include, Rex pattern) { - this.include = include; - this.pattern = pattern; + int length = pattern.length(); + char buf[] = new char[length]; + + pattern.getChars(0, length, buf, 0); + + return (this.pattern.match(buf, 0, length) != null ) + ? true + : false; } } } 1.5 +2 -2 J4/src/java/gnu/j4/core/SwitchFacilityFilter.java CVSWEB Options: ------------------- CVSWeb: Annotate this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/SwitchFacilityFilter.java?annotate=1.5&cvsroot=jukebox4 CVSWeb: View this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/SwitchFacilityFilter.java?rev=1.5&content-type=text/x-cvsweb-markup&cvsroot=jukebox4 CVSWeb: Diff to previous version: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/SwitchFacilityFilter.java.diff?r1=1.5&r2=1.4&cvsroot=jukebox4 ----------------------------------- Index: SwitchFacilityFilter.java =================================================================== RCS file: /usr/local/cvs/J4/src/java/gnu/j4/core/SwitchFacilityFilter.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- SwitchFacilityFilter.java 1999/09/28 22:04:08 1.4 +++ SwitchFacilityFilter.java 2000/09/13 19:23:33 1.5 @@ -46,9 +46,9 @@ * list, one of the messages on December 29 1998. * * @author Copyright © <a href="mailto:vt...@fr...">Vadim Tkachenko</a> 1995-1998 - * @version $Id: SwitchFacilityFilter.java,v 1.4 1999/09/28 22:04:08 vt Exp $ + * @version $Id: SwitchFacilityFilter.java,v 1.5 2000/09/13 19:23:33 vt Exp $ */ -public class SwitchFacilityFilter extends SyslogFacilityFilter { +public class SwitchFacilityFilter extends AbstractSyslogFilter { public void init(String confName) { super.init(confName); 1.4 +7 -2 J4/src/java/gnu/j4/core/Syslog.java CVSWEB Options: ------------------- CVSWeb: Annotate this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/Syslog.java?annotate=1.4&cvsroot=jukebox4 CVSWeb: View this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/Syslog.java?rev=1.4&content-type=text/x-cvsweb-markup&cvsroot=jukebox4 CVSWeb: Diff to previous version: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/Syslog.java.diff?r1=1.4&r2=1.3&cvsroot=jukebox4 ----------------------------------- Index: Syslog.java =================================================================== RCS file: /usr/local/cvs/J4/src/java/gnu/j4/core/Syslog.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- Syslog.java 1999/06/29 04:35:34 1.3 +++ Syslog.java 2000/09/13 19:23:33 1.4 @@ -1,5 +1,7 @@ package gnu.j4.core; +import gnu.j4.config.Configurable; + /** * Syslog facility. * @@ -18,9 +20,9 @@ * shouldn't do it the second time. * * @author Copyright © <a href="mailto:vt...@fr...">Vadim Tkachenko</a> 1995-1998 - * @version $Id: Syslog.java,v 1.3 1999/06/29 04:35:34 vt Exp $ + * @version $Id: Syslog.java,v 1.4 2000/09/13 19:23:33 vt Exp $ */ -public interface Syslog { +public interface Syslog extends Configurable { /** * Log facility to use for all the classes implementing this interface. @@ -34,4 +36,7 @@ * @param message Message to log. */ public void logMessage( LogRecord message ); + + public void open(); + public void close(); } 1.4 +10 -16 J4/src/java/gnu/j4/core/SyslogFacilityFilter.java CVSWEB Options: ------------------- CVSWeb: Annotate this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/SyslogFacilityFilter.java?annotate=1.4&cvsroot=jukebox4 CVSWeb: View this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/SyslogFacilityFilter.java?rev=1.4&content-type=text/x-cvsweb-markup&cvsroot=jukebox4 CVSWeb: Diff to previous version: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/SyslogFacilityFilter.java.diff?r1=1.4&r2=1.3&cvsroot=jukebox4 ----------------------------------- Index: SyslogFacilityFilter.java =================================================================== RCS file: /usr/local/cvs/J4/src/java/gnu/j4/core/SyslogFacilityFilter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- SyslogFacilityFilter.java 1999/06/29 04:35:34 1.3 +++ SyslogFacilityFilter.java 2000/09/13 19:23:33 1.4 @@ -7,24 +7,18 @@ * * Allows the log facilities to be filtered from the output. * + * @deprecated Use {@link SyslogFilter SyslogFilter} instead. Left here only + * for compatibility purposes. Will go away in the next release. + * * @author Copyright © <a href="mailto:vt...@fr...">Vadim Tkachenko</a> 1995-1999 - * @version $Id: SyslogFacilityFilter.java,v 1.3 1999/06/29 04:35:34 vt Exp $ + * @version $Id: SyslogFacilityFilter.java,v 1.4 2000/09/13 19:23:33 vt Exp $ */ -public abstract class SyslogFacilityFilter implements LogLevels, LogConfigKeywords { - - protected String confName; - protected Configuration conf; - - public void init(String confName) { - this.confName = confName; - } - +public abstract class SyslogFacilityFilter extends AbstractSyslogFilter { + /** - * Find out if the combination of the log level and facility is enabled. - * - * @param ll Log level. - * @param facility Log facility. - * @return true if the given combination is allowed to be written. + * @deprecated The configuration model doesn't use the configuration + * file name anymore. */ - public abstract boolean isEnabled(LogLevel ll, String facility); + public void init(String confName) { + } } 1.11 +1 -22 J4/src/java/gnu/j4/core/UdpSyslog.java CVSWEB Options: ------------------- CVSWeb: Annotate this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/UdpSyslog.java?annotate=1.11&cvsroot=jukebox4 CVSWeb: View this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/UdpSyslog.java?rev=1.11&content-type=text/x-cvsweb-markup&cvsroot=jukebox4 CVSWeb: Diff to previous version: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/UdpSyslog.java.diff?r1=1.11&r2=1.10&cvsroot=jukebox4 ----------------------------------- Index: UdpSyslog.java =================================================================== RCS file: /usr/local/cvs/J4/src/java/gnu/j4/core/UdpSyslog.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- UdpSyslog.java 2000/07/08 04:58:38 1.10 +++ UdpSyslog.java 2000/09/13 19:23:33 1.11 @@ -48,7 +48,7 @@ * href="http://www.digitalfocus.com/faq" target="_top">The Java Developer * Archive: How Do I...</a> by Jeremy Cooper * @author <a href="mailto:vt...@fr...">Vadim Tkachenko</a> - * @version $Id: UdpSyslog.java,v 1.10 2000/07/08 04:58:38 vt Exp $ + * @version $Id: UdpSyslog.java,v 1.11 2000/09/13 19:23:33 vt Exp $ */ public class UdpSyslog extends BasicSyslog { @@ -249,27 +249,6 @@ buffer.append( Integer.toString( localPort ) ); buffer.append( "] " ); super.composeMessage( buffer,lr ); - } - - /** - * Decide which messages to log. - * - * This method overrides the behavior of its {@link BasicSyslog#filter - * parent class' method}. - * - * @return If the facility starts with {@link #SYSLOG_STD_PREFIX - * SYSLOG_STD_PREFIX}, true. Otherwise, say what the parent says. - * @see #isLevelEnabled - */ - public boolean filter( LogRecord lr ) { - - if ( lr.facility != null - && lr.facility.toLowerCase().startsWith( SYSLOG_STD_PREFIX ) ) { - - // Let the syslogd sort it out - return true; - } - return super.filter( lr ); } /** 1.1 J4/src/java/gnu/j4/core/AbstractSyslog.java CVSWEB Options: ------------------- CVSWeb: Annotate this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/AbstractSyslog.java?annotate=1.1&cvsroot=jukebox4 CVSWeb: View this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/AbstractSyslog.java?rev=1.1&content-type=text/x-cvsweb-markup&cvsroot=jukebox4 ----------------------------------- Index: AbstractSyslog.java =================================================================== package gnu.j4.core; import gnu.j4.config.Configurable; import gnu.j4.config.Configuration; /** * This class provides the implementation for the common features of all the * syslogs, such as configuration support, start/stop control and filtering * facility. * * @author Copyright © <a href="mailto:vt...@fr...">Vadim Tkachenko</a> 2000 * @version $Id: AbstractSyslog.java,v 1.1 2000/09/13 19:23:33 vt Exp $ * @since Jukebox v4 2.0.p10 */ abstract public class AbstractSyslog implements Syslog, LogLevels, LogConfigKeywords { /** * True if enabled. * * @see #open * @see #close */ private boolean enabled = false; /** * Facility filter. * * May be <code>null</code>, in this case no filtering happens at all. */ private SyslogFilter filter = null; /** * The configuration root. * * This attribute is immutable, once set, cannot be changed. */ private String configurationRoot; /** * Master configuration. */ protected Configuration conf; public AbstractSyslog() { } public AbstractSyslog(String configurationRoot, Configuration conf) { this.configurationRoot = configurationRoot; configure(conf); } public final void setConfigurationRoot(String configurationRoot) { if ( configurationRoot != null ) { throw new IllegalStateException("You cannot reset the configuration root. Destroy this one and instantiate new."); } this.configurationRoot = configurationRoot; } public final String getConfigurationRoot() { return configurationRoot; } public void configure(Configuration conf) { this.conf = conf; // Configure the filter String filterConfigurationRoot = configurationRoot + ".filter"; String filterClassName = conf.getString(configurationRoot + ".classname"); if ( filterClassName != null ) { try { Class filterClass = Class.forName( filterClassName ); filter = (SyslogFilter)filterClass.newInstance(); filter.setConfigurationRoot(filterConfigurationRoot); filter.configure(conf); } catch ( Throwable t ) { System.err.println("Unrecoverable exception, filter is not set:"); t.printStackTrace(); } finally { logMessage(new LogRecord(Thread.currentThread(), this, LOG_INFO, Logger.LOG_LOGGER, "Using "+filter.getClass().getName(), null)); } } } public void open() { try { start(); enabled = true; } catch ( Throwable t ) { // Well, this is very unfortunate. It is not possible to display // the error through the normal logging channel, the only option // left is write it to stderr. System.err.println(getConfigurationRoot() + ": can't open, cause:"); t.printStackTrace(); } } public void close() { enabled = false; stop(); } /** * Only the subclasses have a business to know if we're enabled or not. * * @return <code>true</code> if we're enabled. */ protected boolean isEnabled() { return enabled; } public final void logMessage(LogRecord lr) { if ( !enabled ) { return; } if ( lr == null ) { // VT: FIXME: consider logging this through the normal channels (new Error( "null log record, you may want to check what's going on" )).printStackTrace(); } if ( filter == null || filter.isEnabled(lr) ) { write(lr); } } abstract protected void start(); abstract protected void stop(); abstract protected void write(LogRecord lr); } 1.1 J4/src/java/gnu/j4/core/PatternFilter.java CVSWEB Options: ------------------- CVSWeb: Annotate this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/PatternFilter.java?annotate=1.1&cvsroot=jukebox4 CVSWeb: View this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/PatternFilter.java?rev=1.1&content-type=text/x-cvsweb-markup&cvsroot=jukebox4 ----------------------------------- Index: PatternFilter.java =================================================================== package gnu.j4.core; import java.util.Enumeration; import java.util.Vector; import gnu.j4.config.Configuration; /** * Syslog facility filter based on the regular expression pattern matching. * * <p> * * This filter is much more powerful than the {@link SwitchFacilityFilter * SwitchFacilityFilter}, but it may bear more overhead. Not necessarily, * but quite probably. * * <a href="http://jakarta.apache.org/regexp/">Jakarta Regexp</a> package is * required to use this filter, see the documentation for details. * * @author Copyright © <a href="mailto:vt...@fr...">Vadim Tkachenko</a> 1995-1998 * @version $Id: PatternFilter.java,v 1.1 2000/09/13 19:23:33 vt Exp $ */ abstract public class PatternFilter extends AbstractSyslogFilter { /** * Collection of preprocessed patterns to match. * * The patterns are specified with the keyword defined by {@link * LogConfigKeywords#SYSLOG_REX_PATTERN SYSLOG_REX_PATTERN}. */ protected Vector patternSet = new Vector(); public void configure(Configuration conf) { this.conf = (Configuration)conf.clone(); Configuration defaultConf = new Configuration(); Vector defaultPattern = new Vector(); defaultPattern.addElement(".*"); defaultPattern.addElement("-\\.DEBUG"); defaultConf.put(SYSLOG_REX_PATTERN, defaultPattern); this.conf.setDefaultConfiguration(defaultConf); try { Vector stringPatternSet = this.conf.getVector(SYSLOG_REX_PATTERN); for ( Enumeration e = stringPatternSet.elements(); e.hasMoreElements(); ) { String raw = e.nextElement().toString(); // First character is '-' (exclude) or '+' or anything else (include). boolean include = true; int patternIndex = 0; if ( raw.charAt(0) == '-' ) { include = false; patternIndex = 1; } else if ( raw.charAt(0) == '+' ) { patternIndex = 1; } String pattern = raw.substring(patternIndex, raw.length()-1); Pattern p = createPattern(include, pattern); // System.err.println("Pattern: " + sPattern); patternSet.addElement(p); } } catch ( Throwable t ) { throw new Error(t.toString()); } } /** * Find out if the combination of the log level and facility is enabled. * * @param lr Log record to analyze. * * @return true if the given combination is allowed to be written. */ public boolean isEnabled(LogRecord lr) { if ( lr == null ) { // The hell with it, I'll enable return true; } // First of all, let's glue the level and facility together String target = (lr.facility == null)?"NULL_FACILITY":lr.facility + "." + ((lr.ll == null)?"NO_LEVEL":lr.ll.toString()); // System.err.println("Search: " + target); boolean include = false; for ( Enumeration e = patternSet.elements(); e.hasMoreElements(); ) { Pattern p = (Pattern)e.nextElement(); if ( p.match(target) ) { // System.err.println("Match (" + p.include + "): "+ match.toString()); include = p.include; } } // System.err.println("Final: " + target + ": " + include ); return include; } abstract protected Pattern createPattern(boolean include, String pattern) throws Throwable; abstract protected class Pattern { boolean include = true; protected Pattern(boolean include) { this.include = include; } abstract protected boolean match(String pattern); } } 1.1 J4/src/java/gnu/j4/core/SwitchFilter.java CVSWEB Options: ------------------- CVSWeb: Annotate this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/SwitchFilter.java?annotate=1.1&cvsroot=jukebox4 CVSWeb: View this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/SwitchFilter.java?rev=1.1&content-type=text/x-cvsweb-markup&cvsroot=jukebox4 ----------------------------------- Index: SwitchFilter.java =================================================================== package gnu.j4.core; import gnu.j4.config.Configuration; /** * Syslog facility filter based on switching on and off individual levels * and facilities. * * This approach has certain advantages and disadvantages to it. * * <dl> * <dt>Advantages * * <dd> * * The implementation is relatively simple and performance is good. * * <dt>Disadvantages * * <dd> * * The granularity is not as good as it seems at the first glance. Imagine * you're developing a new module in the big system (having its own * facility), and you suddenly require the debug output to be switched on. * As a side effect, you have the debug output of all other facilities * switched on, and tremendous amount of log output to plow through. * * </dl> * * This module should work well in the production environment. * * <h3>Note on channels enabled by default</h3> * * Since the channel is not of an enumerated type and it's not possible to * check its value at the compile time, I'd rather bear some performance * penalties and have all the channels enabled by default rather than spend * minutes, hours and days trying to understand why particular log/debug * message doesn't appear in the log, though by all means it should have. * People make typos, nobody's perfect. Thus, if you make a typo, the log * message would still be there, and if you disable a channel and wonder why * the message is still there, you'll find out sooner ;-) * * <p> * * Walking proof: <a href="http://java.apache.org">Apache JServ</a> user * list, one of the messages on December 29 1998. * * @author Copyright © <a href="mailto:vt...@fr...">Vadim Tkachenko</a> 1995-1998 * @version $Id: SwitchFilter.java,v 1.1 2000/09/13 19:23:33 vt Exp $ */ public class SwitchFilter extends AbstractSyslogFilter { public void configure(Configuration conf) { this.conf = conf; } /** * Find out if the combination of the log level and facility is enabled. * * @param lr Log record. * * @return <code>true</code> if the given combination is allowed to be * written. */ public boolean isEnabled(LogRecord lr) { if ( !isLevelEnabled(lr.ll) ) { return false; } if ( !isFacilityEnabled(lr.facility) ) { return false; } return true; } /** * Is the log level enabled? * <p> * * By default, all levels are enabled. * * <p> * * There is no way to find out if the log level enabled outside of this * package. This is strictly the logging system's business, nobody * else's. * * @param ll Log level to check. * * @return true if this log level is enabled by {@link #conf * configuration}. */ public boolean isLevelEnabled(LogLevel ll) { if ( ll == null ) { // logMessage( new LogRecord( Thread.currentThread(), // this,LOG_WARNING,LOG_SYSLOG, // "no log level specified for the next record",null ) ); return true; } return conf.getBoolean(SYSLOG_LEVEL + ll.toString(), true); } /** * Is the facility enabled? * <p> * * All the facilities are enabled by default. * <p> * * There is no way to find out if the log facility enabled outside of * this package. This is strictly the logging system's business, nobody * else's. * * @param channel Facility name. * @return true if the facility is enabled by {@link #conf * configuration}. */ public boolean isFacilityEnabled(String channel) { return conf.getBoolean(SYSLOG_CHANNEL + channel, true); } } 1.1 J4/src/java/gnu/j4/core/SyslogFilter.java CVSWEB Options: ------------------- CVSWeb: Annotate this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/SyslogFilter.java?annotate=1.1&cvsroot=jukebox4 CVSWeb: View this file: http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/J4/src/java/gnu/j4/core/SyslogFilter.java?rev=1.1&content-type=text/x-cvsweb-markup&cvsroot=jukebox4 ----------------------------------- Index: SyslogFilter.java =================================================================== package gnu.j4.core; import gnu.j4.config.Configurable; /** * Syslog facility filter. * * Allows the log facilities to be filtered from the output. * * @author Copyright © <a href="mailto:vt...@fr...">Vadim Tkachenko</a> 1995-2000 * @version $Id: SyslogFilter.java,v 1.1 2000/09/13 19:23:33 vt Exp $ * @since Jukebox v4 2.0p10 */ public interface SyslogFilter extends Configurable, LogLevels, LogConfigKeywords { /** * Find out if we should pass this record down the chain. * * @param lr Log record to analyze. * * @return <code>true</code> if the filter configuration allows this * record to be passed to the log device further down the chain. */ public boolean isEnabled(LogRecord lr); } |