From f9a8e45c9c79076228e30024319c6fb0eb4213d1 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Fri, 22 May 2009 02:54:42 +0000 Subject: [PATCH] 277403 reduced usage of system properties git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@256 7e9141cc-0065-0410-87d8-b60c137991c4 --- README.txt | 4 +- VERSION.txt | 1 + .../java/org/eclipse/jetty/server/Server.java | 26 +- .../java/org/eclipse/jetty/start/Main.java | 355 ++++++++++-------- .../java/org/eclipse/jetty/start/Monitor.java | 21 +- .../org/eclipse/jetty/start/start.config | 41 +- .../java/org/eclipse/jetty/util/log/Log.java | 27 +- .../org/eclipse/jetty/util/log/StdErrLog.java | 5 +- 8 files changed, 270 insertions(+), 210 deletions(-) diff --git a/README.txt b/README.txt index 18e5442db13..713c5715309 100644 --- a/README.txt +++ b/README.txt @@ -53,10 +53,10 @@ To see the available options To run with JSP support - java -DOPTIONS=Server,deploy,jsp -jar start.jar + java -jar start.jar OPTIONS=Server,deploy,jsp To run with JMX support - java -DOPTIONS=Server,deploy,jmx -jar start.jar etc/jetty-jmx.xml etc/jetty.xml + java -jar start.jar OPTIONS=Server,deploy,jmx etc/jetty-jmx.xml etc/jetty.xml diff --git a/VERSION.txt b/VERSION.txt index 4aa8134a266..0e305412be3 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -3,6 +3,7 @@ jetty-7.0.0.M3-SNAPSHOT + refactored configuration mechanism + added WebAppContext.setConfigurationDiscovered for servlet 3.0 features + 274251 Allow dispatch to welcome files that are servlets (configurable) + + 277403 Cleanup system property usage. jetty-7.0.0.M2 18 May 2009 + JETTY-937 Work around Sun JVM bugs diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java index c3facd5ab97..4aa027ab45f 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java @@ -529,7 +529,7 @@ public class Server extends HandlerWrapper implements Attributes */ private void createShutdownHook() { - if (!Boolean.getBoolean("JETTY_NO_SHUTDOWN_HOOK") && !hooked) + if (!hooked) { try { @@ -552,7 +552,8 @@ public class Server extends HandlerWrapper implements Attributes */ public boolean add(Server server) { - createShutdownHook(); + if (server.getStopAtShutdown()) + createShutdownHook(); return this.servers.add(server); } @@ -564,21 +565,11 @@ public class Server extends HandlerWrapper implements Attributes return this.servers.contains(server); } - /** - * Append all Servers from Collection - */ - public boolean addAll(Collection c) - { - createShutdownHook(); - return this.servers.addAll(c); - } - /** * Clear list of Servers. */ public void clear() { - createShutdownHook(); this.servers.clear(); } @@ -591,15 +582,6 @@ public class Server extends HandlerWrapper implements Attributes return this.servers.remove(server); } - /** - * Remove all Servers in Collection from list. - */ - public boolean removeAll(Collection c) - { - createShutdownHook(); - return this.servers.removeAll(c); - } - /** * Stop all Servers in list. */ @@ -611,7 +593,7 @@ public class Server extends HandlerWrapper implements Attributes while (it.hasNext()) { Server svr = (Server) it.next(); - if (svr == null) + if (svr == null || !svr.getStopAtShutdown()) continue; try { diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java index a6db54a417d..aef30922625 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java @@ -28,9 +28,11 @@ import java.security.Policy; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.Hashtable; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.StringTokenizer; @@ -43,61 +45,59 @@ import java.util.StringTokenizer; * format of each line in this file is: * *
+ * Each line contains entry in the format:
  * 
- * SUBJECT [ [!] CONDITION [AND|OR] ]*
+ *  SUBJECT [ [!] CONDITION [AND|OR] ]*
  * 
- * 
+ * where SUBJECT: + * ends with ".class" is the Main class to run. + * ends with ".xml" is a configuration file for the command line + * ends with "/" is a directory from which to add all jar and zip files. + * ends with "/*" is a directory from which to add all unconsidered jar and zip files. + * ends with "/**" is a directory from which to recursively add all unconsidered jar and zip files. + * Containing = are used to assign system properties. + * Containing ~= are used to assign start properties. + * all other subjects are treated as files to be added to the classpath. * - * where SUBJECT: + * ${name} is expanded to a start property + * $(name) is expanded to either a start property or a system property. + * The start property ${version} is defined as the version of the start.jar * - *
- * ends with ".class" is the Main class to run.
- * ends with ".xml" is a configuration file for the command line
- * ends with "/" is a directory from which add all jar and zip files from.
- * ends with "/*" is a directory from which add all unconsidered jar and zip files from.
- * Containing = are used to assign system properties.
- * all other subjects are treated as files to be added to the classpath.
- * 
+ * Files starting with "/" are considered absolute, all others are relative to + * the home directory. * - * Subjects may include system properties with $(propertyname) syntax. The $(version) property is - * defined as the maven version of the start.jar. File subjects starting with - * "/" are considered absolute, all others are relative to the home directory. - *

* CONDITION is one of: + * always + * never + * available classname - true if class on classpath + * property name - true if set as start property + * system name - true if set as system property + * exists file - true if file/dir exists + * java OPERATOR version - java version compared to literal + * nargs OPERATOR number - number of command line args compared to literal + * OPERATOR := one of "<",">","<=",">=","==","!=" * - *

+ * CONTITIONS can be combined with AND OR or !, with AND being the assume
+ * operator for a list of CONDITIONS.
  * 
- * always
- * never
- * available package.class 
- * java OPERATOR n.n 
- * nargs OPERATOR n
- * OPERATOR := one of "<",">"," <=",">=","==","!="
+ * Classpath operations are evaluated on the fly, so once a class or jar is
+ * added to the classpath, subsequent available conditions will see that class.
  * 
- * 
- * - * CONTITIONS can be combined with AND OR or !, with AND being the assume operator for a list of - * CONDITIONS. Classpath operations are evaluated on the fly, so once a class or jar is added to - * the classpath, subsequent available conditions will see that class. The system parameter - * CLASSPATH, if set is given to the start classloader before any paths from the configuration - * file. Programs started with start.jar may be stopped with the stop.jar, which connects via a - * local port to stop the server. The default port can be set with the STOP.PORT system property (a - * port of < 0 disables the stop mechanism). If the STOP.KEY system property is set, then a random - * key is generated and written to stdout. This key must be passed to the stop.jar. - *

* The configuration file may be divided into sections with option names like: - *

  * [ssl,default]
- * 
+ * * Clauses after a section header will only be included if they match one of the tags in the * options property. By default options are set to "default,*" or the OPTIONS property may * be used to pass in a list of tags, eg. : - *
- *  java -DOPTIONS=jetty,jsp,ssl -jar start.jar
- * 
+ * + * java -jar start.jar OPTIONS=jetty,jsp,ssl + * * The tag '*' is always appended to the options, so any section with the * tag is always * applied. * + * + * + * */ public class Main { @@ -105,38 +105,67 @@ public class Main ?Main.class.getPackage().getImplementationVersion() :"Unknown"; - static boolean _debug=System.getProperty("DEBUG",null)!=null; + public static boolean DEBUG=false; + + private Map _properties = new HashMap(); + + private String _classname=null; private Classpath _classpath=new Classpath(); - private String _config=System.getProperty("START","org/eclipse/jetty/start/start.config"); - private ArrayList _xml=new ArrayList(); + private boolean _showVersions=false; - private Set _options = new HashSet(); - + private List _xml=new ArrayList(); + private Set _options = new HashSet(); + + + /* + private String _config=System.getProperty("START","org/eclipse/jetty/start/start.config"); + */ + public static void main(String[] args) { try { - if (args.length>0&&args[0].equalsIgnoreCase("--help")) + Main main=new Main(); + List arguments = new ArrayList(Arrays.asList(args)); + + for (int i=0; i0&&args[0].equalsIgnoreCase("--stop")) - { - new Main().stop(); - } - else if (args.length>0&&(args[0].equalsIgnoreCase("--version")||args[0].equalsIgnoreCase("--info"))) - { - String[] nargs=new String[args.length-1]; - System.arraycopy(args,1,nargs,0,nargs.length); - Main main=new Main(); - main._showVersions=true; - main.start(nargs); - } - else - { - new Main().start(args); + String arg=arguments.get(i); + if (arg.equalsIgnoreCase("--help")) + { + usage(); + } + + if (arg.equalsIgnoreCase("--stop")) + { + int port = Integer.parseInt(main.getProperty("STOP.PORT","-1")); + String key = main.getProperty("STOP.KEY", null); + main.stop(port,key); + return; + } + + if (arg.equalsIgnoreCase("--version")||arg.equalsIgnoreCase("-v")||arg.equalsIgnoreCase("-info")) + { + arguments.remove(i--); + main._showVersions=true; + } + + if (arg.indexOf('=')>=0) + { + arguments.remove(i--); + String[] assign=arg.split("=",2); + + if (assign.length==2) + main.setProperty(assign[0],assign[1]); + else + main.setProperty(assign[0],null); + } } + + DEBUG=Boolean.parseBoolean(main.getProperty("DEBUG","false")); + main.start(arguments.toArray(new String[arguments.size()])); + } catch (Exception e) { @@ -144,10 +173,39 @@ public class Main usage(); } } + + private String getSystemProperty(String name) + { + if ("version".equalsIgnoreCase(name)) + return _version; + if (_properties.containsKey(name)) + return _properties.get(name); + return System.getProperty(name); + } + private String getProperty(String name) + { + if ("version".equalsIgnoreCase(name)) + return _version; + + return _properties.get(name); + } + + private String getProperty(String name, String dftValue) + { + if (_properties.containsKey(name)) + return _properties.get(name); + return dftValue; + } + + private void setProperty(String name, String value) + { + _properties.put(name,value); + } + private static void usage() { - System.err.println("Usage: java [-DDEBUG] [-DSTART=start.config] [-DOPTIONS=opts] [-Dmain.class=org.MyMain] -jar start.jar [--help|--stop|--version|--info] [config ...]"); + System.err.println("Usage: java -jar start.jar [--help|--stop|--version] [config ...]"); System.exit(1); } @@ -179,12 +237,12 @@ public class Main } catch (NoClassDefFoundError e) { - if (_debug) + if (DEBUG) System.err.println(e); } catch (ClassNotFoundException e) { - if (_debug) + if (DEBUG) System.err.println(e); } ClassLoader loader=_classpath.getClassLoader(); @@ -195,12 +253,12 @@ public class Main } catch (NoClassDefFoundError e) { - if (_debug) + if (DEBUG) System.err.println(e); } catch (ClassNotFoundException e) { - if (_debug) + if (DEBUG) System.err.println(e); } return false; @@ -220,7 +278,7 @@ public class Main //ignored } - if (_debug || _showVersions || invoked_class==null) + if (DEBUG || _showVersions || invoked_class==null) { if (invoked_class==null) System.err.println("ClassNotFound: "+classname); @@ -231,9 +289,7 @@ public class Main System.err.println(" "+elements[i].getAbsolutePath()); if (_showVersions || invoked_class==null) { - List opts = new ArrayList(_options); - Collections.sort(opts); - System.err.println("OPTIONS: "+opts); + System.err.println("OPTIONS: "+_options); usage(); } } @@ -262,13 +318,25 @@ public class Main if (i2<0) break; String name=s.substring(i1+2,i2); - String property; - if ("version".equalsIgnoreCase(name)) - property=_version; - else - property=System.getProperty(s.substring(i1+2,i2),""); + String property=getSystemProperty(name); s=s.substring(0,i1)+property+s.substring(i2+1); } + + i1=0; + i2=0; + while (s!=null) + { + i1=s.indexOf("${",i2); + if (i1<0) + break; + i2=s.indexOf("}",i1+2); + if (i2<0) + break; + String name=s.substring(i1+2,i2); + String property=getProperty(name); + s=s.substring(0,i1)+property+s.substring(i2+1); + } + return s; } @@ -279,7 +347,8 @@ public class Main Version java_version=new Version(System.getProperty("java.version")); Version ver=new Version(); // JAR's already processed - Hashtable done=new Hashtable(); + Set done=new HashSet(); + // Initial classpath String classpath=System.getProperty("CLASSPATH"); if (classpath!=null) @@ -289,13 +358,11 @@ public class Main _classpath.addComponent(tok.nextToken()); } - List section=null; - List options=null; - String o=System.getProperty("OPTIONS"); - if (o==null) - o="default"; + List section=null; + List options=null; + String o=getProperty("OPTIONS","default"); options=Arrays.asList((o.toString()+",*").split("[ ,]")); - ArrayList unsatisfiedOptions = new ArrayList(options); + List unsatisfied_options = new ArrayList(options); // Handle line by line String line=null; @@ -318,7 +385,7 @@ public class Main if (section!=null && Collections.disjoint(section,options)) continue; if (section!=null) - unsatisfiedOptions.removeAll(section); + unsatisfied_options.removeAll(section); try { StringTokenizer st=new StringTokenizer(line); @@ -372,11 +439,16 @@ public class Main } catch (Exception e) { - if (_debug) + if (DEBUG) e.printStackTrace(); } } else if (condition.equals("property")) + { + String property=getProperty(st.nextToken()); + eval=property!=null&&property.length()>0; + } + else if (condition.equals("system")) { String property=System.getProperty(st.nextToken()); eval=property!=null&&property.length()>0; @@ -408,20 +480,31 @@ public class Main not=false; } String file=expand(subject).replace('/',File.separatorChar); - if (_debug) + if (DEBUG) System.err.println((expression?"T ":"F ")+line); if (!expression) { - done.put(file,file); + done.add(file); continue; } + + // Handle the subject - if (subject.indexOf("=")>0) + if (subject.indexOf("~=")>0) { int i=file.indexOf("="); String property=file.substring(0,i); String value=file.substring(i+1); - if (_debug) + if (DEBUG) + System.err.println(" "+property+"~="+value); + setProperty(property,value); + } + else if (subject.indexOf("=")>0) + { + int i=file.indexOf("="); + String property=file.substring(0,i); + String value=file.substring(i+1); + if (DEBUG) System.err.println(" "+property+"="+value); System.setProperty(property,value); } @@ -444,11 +527,11 @@ public class Main // class directory File cd=new File(file); String d=cd.getCanonicalPath(); - if (!done.containsKey(d)) + if (!done.contains(d)) { - done.put(d,d); + done.add(d); boolean added=_classpath.addComponent(d); - if (_debug) + if (DEBUG) System.err.println((added?" CLASSPATH+=":" !")+d); } } @@ -458,7 +541,7 @@ public class Main File f=new File(file); if (f.exists()) _xml.add(f.getCanonicalPath()); - if (_debug) + if (DEBUG) System.err.println(" ARGS+="+f); } else if (subject.toLowerCase().endsWith(".class")) @@ -467,7 +550,7 @@ public class Main String cn=expand(subject.substring(0,subject.length()-6)); if (cn!=null&&cn.length()>0) { - if (_debug) + if (DEBUG) System.err.println(" CLASS="+cn); _classname=cn; } @@ -478,7 +561,7 @@ public class Main String cn=expand(subject.substring(0,subject.length()-5)); if (cn!=null&&cn.length()>0) { - if (_debug) + if (DEBUG) System.err.println(" PATH="+cn); _classpath.addClasspath(cn); } @@ -490,17 +573,17 @@ public class Main if(f.exists()) { String d=f.getCanonicalPath(); - if (!done.containsKey(d)) + if (!done.contains(d)) { - done.put(d,d); + done.add(d); boolean added=_classpath.addComponent(d); if (!added) { added=_classpath.addClasspath(expand(subject)); - if (_debug) + if (DEBUG) System.err.println((added?" CLASSPATH+=":" !")+d); } - else if (_debug) + else if (DEBUG) System.err.println((added?" CLASSPATH+=":" !")+d); } } @@ -513,60 +596,37 @@ public class Main } } - if (unsatisfiedOptions!=null && unsatisfiedOptions.size()>0) + if (unsatisfied_options!=null && unsatisfied_options.size()>0) { - String home = System.getProperty("jetty.home"); - String lib = System.getProperty("jetty.lib"); - File libDir = null; - if (lib!=null) - { - libDir = new File (lib); - } - else if (home != null) - { - libDir = new File (home, "lib"); - } - - for (int i=0; i< unsatisfiedOptions.size(); i++) - { - if (libDir != null) - { - File dir = new File (libDir, (String)unsatisfiedOptions.get(i)); - if (dir.exists()) - addJars(dir,done,true); - else - System.err.println("Unsatisfied option:"+unsatisfiedOptions.get(i)); - } - else - System.err.println("Unsatisfied option:"+unsatisfiedOptions.get(i)); - } + System.err.println("Unresolved options: "+unsatisfied_options); } } /* ------------------------------------------------------------ */ public void start(String[] args) { - ArrayList al=new ArrayList(); - for (int i=0; i table, boolean recurse) throws IOException { File[] entries=dir.listFiles(); @@ -693,11 +754,11 @@ public class Main if (name.endsWith(".jar")||name.endsWith(".zip")) { String jar=entry.getCanonicalPath(); - if (!table.containsKey(jar)) + if (!table.contains(jar)) { - table.put(jar,jar); + table.add(jar); boolean added=_classpath.addComponent(jar); - if (_debug) + if (DEBUG) System.err.println((added?" CLASSPATH+=":" !")+jar); } } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Monitor.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Monitor.java index 84f44f225b4..33ed3cfdd12 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Monitor.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Monitor.java @@ -32,13 +32,16 @@ import java.net.Socket; */ public class Monitor extends Thread { - private int _port = Integer.getInteger("STOP.PORT", -1).intValue(); - private String _key = System.getProperty("STOP.KEY", null); + private int _port; + private String _key; ServerSocket _socket; - Monitor() + Monitor(int port,String key) { + _port=port; + _key=key; + try { if(_port<0) @@ -55,12 +58,12 @@ public class Monitor extends Thread if (_key==null) { _key=Long.toString((long)(Long.MAX_VALUE*Math.random()+this.hashCode()+System.currentTimeMillis()),36); - System.out.println("-DSTOP.KEY="+_key); + System.out.println("STOP.KEY="+_key); } } catch(Exception e) { - if (Main._debug) + if (Main.DEBUG) e.printStackTrace(); else System.err.println(e.toString()); @@ -86,7 +89,7 @@ public class Monitor extends Thread continue; String cmd=lin.readLine(); - if (Main._debug) System.err.println("command="+cmd); + if (Main.DEBUG) System.err.println("command="+cmd); if ("stop".equals(cmd)) { try {socket.close();}catch(Exception e){e.printStackTrace();} @@ -101,7 +104,7 @@ public class Monitor extends Thread } catch(Exception e) { - if (Main._debug) + if (Main.DEBUG) e.printStackTrace(); else System.err.println(e.toString()); @@ -120,9 +123,9 @@ public class Monitor extends Thread /** Start a Monitor. * This static method starts a monitor that listens for admin requests. */ - public static void monitor() + public static void monitor(int port,String key) { - new Monitor(); + new Monitor(port,key); } } diff --git a/jetty-start/src/main/resources/org/eclipse/jetty/start/start.config b/jetty-start/src/main/resources/org/eclipse/jetty/start/start.config index 691fbe19573..1cd33746a51 100644 --- a/jetty-start/src/main/resources/org/eclipse/jetty/start/start.config +++ b/jetty-start/src/main/resources/org/eclipse/jetty/start/start.config @@ -1,8 +1,8 @@ # This file controls what file are to be put on classpath or command line. # # Format is as follows: -# Each line contains entry for one JAR file. -# Format of line: +# +# Each line contains entry in the format: # # SUBJECT [ [!] CONDITION [AND|OR] ]* # @@ -13,10 +13,12 @@ # ends with "/*" is a directory from which to add all unconsidered jar and zip files. # ends with "/**" is a directory from which to recursively add all unconsidered jar and zip files. # Containing = are used to assign system properties. +# Containing ~= are used to assign start properties. # all other subjects are treated as files to be added to the classpath. # -# Subjects may include system properties with $(propertyname) syntax. The -# property version is defined as the version of the start.jar +# ${name} is expanded to a start property +# $(name) is expanded to either a start property or a system property. +# The start property ${version} is defined as the version of the start.jar # # Files starting with "/" are considered absolute, all others are relative to # the home directory. @@ -25,7 +27,8 @@ # always # never # available classname # true if class on classpath -# property name # true if set +# property name # true if set as start property +# system name # true if set as system property # exists file # true if file/dir exists # java OPERATOR version # java version compared to literal # nargs OPERATOR number # number of command line args compared to literal @@ -33,20 +36,28 @@ # # CONTITIONS can be combined with AND OR or !, with AND being the assume # operator for a list of CONDITIONS. +# # Classpath operations are evaluated on the fly, so once a class or jar is # added to the classpath, subsequent available conditions will see that class. # +# The configuration file may be divided into sections with option names like: +# [ssl,default] +# +# Clauses after a section header will only be included if they match one of the tags in the +# options property. By default options are set to "default,*" or the OPTIONS property may +# be used to pass in a list of tags, eg. : +# +# java -jar start.jar OPTIONS=jetty,jsp,ssl +# +# The tag '*' is always appended to the options, so any section with the * tag is always +# applied. +# # add a property defined classpath -$(jetty.class.path).path always +${path}.path property path # add a property defined library directory -$(jetty.lib)/** exists $(jetty.lib) - -# find a maven repository -repository=./repository ! exists $(repository)/org/eclipse/jetty/jetty-start/$(version)/jetty-start-$(version).jar -repository=$(user.home)/.m2/repository ! exists $(repository)/org/eclipse/jetty/jetty-start/$(version)/jetty-start-$(version).jar -repository=./repository ! exists $(repository)/org/eclipse/jetty/jetty-start/$(version)/jetty-start-$(version).jar +${lib}/** exists ${jetty.lib} # Try different settings of jetty.home until the jetty.jar is found. jetty.home=. ! exists $(jetty.home)/start.jar @@ -57,7 +68,7 @@ jetty.home=. ! exists $(jetty.home)/start.ja # The main class to run org.eclipse.jetty.xml.XmlConfiguration.class -$(start.class).class +${start.class}.class property start.class # The default configuration files $(jetty.home)/etc/jetty.xml nargs == 0 @@ -119,9 +130,9 @@ $(jetty.home)/lib/slf4j/** $(jetty.home)/lib/jsp-2.1/** exists $(jetty.home)/lib/jsp-2.1 [All,plus] -$(jetty.home)/lib/jetty-jndi-$(version).jar ! available org.eclipse.jetty.jndi.ContextFactory +$(jetty.home)/lib/jetty-jndi-${version}.jar ! available org.eclipse.jetty.jndi.ContextFactory $(jetty.home)/lib/jetty-jndi/** exists $(jetty.home)/lib/jetty-jndi -$(jetty.home)/lib/jetty-plus-$(version).jar ! available org.eclipse.jetty.plus.jndi.NamingEntry +$(jetty.home)/lib/jetty-plus-${version}.jar ! available org.eclipse.jetty.plus.jndi.NamingEntry [All,annotations] $(jetty.home)/lib/jetty-annotations-$(version).jar ! available org.eclipse.jetty.annotations.AnnotationFinder diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/Log.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/Log.java index 4406d1fa9cc..e594ad92834 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/Log.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/Log.java @@ -26,9 +26,15 @@ import org.eclipse.jetty.util.Loader; * org.slf4j.Logger class is found on the classpath, the static log methods * are directed to a slf4j logger for "org.eclipse.log". Otherwise the logs * are directed to stderr. + *

+ * The "org.eclipse.jetty.util.log.class" system property can be used + * to select a specific logging implementation. + *

+ * If the system property org.eclipse.jetty.util.log.IGNORED is set, + * then ignored exceptions are logged in detail. * - * If the system property VERBOSE is set, then ignored exceptions are logged in detail. - * + * @see StdErrLog + * @see Slf4jLog */ public class Log { @@ -42,7 +48,6 @@ public class Log public final static String NOT_IMPLEMENTED= "NOT IMPLEMENTED "; public static String __logClass; - public static boolean __verbose; public static boolean __ignored; static @@ -52,8 +57,8 @@ public class Log public Boolean run() { __logClass = System.getProperty("org.eclipse.jetty.util.log.class","org.eclipse.jetty.util.log.Slf4jLog"); - __verbose = System.getProperty("VERBOSE",null)!=null; - __ignored = System.getProperty("IGNORED",null)!=null; return true; + __ignored = System.getProperty("org.eclipse.jetty.util.log.IGNORED",null)!=null; + return true; } }); } @@ -95,15 +100,16 @@ public class Log return __log!=null; } - private static void initStandardLogging(Throwable e) { + private static void initStandardLogging(Throwable e) + { Class log_class; + if(e != null && __ignored) + e.printStackTrace(); if (__log==null) { log_class= StdErrLog.class; __log=new StdErrLog(); __log.info("Logging to {} via {}",__log,log_class.getName()); - if(e != null && __verbose) - e.printStackTrace(); } } @@ -200,11 +206,6 @@ public class Log __log.warn(IGNORED,th); unwind(th); } - else if (__verbose) - { - __log.warn(IGNORED,th); - unwind(th); - } } public static void info(String msg) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java index cb3460fe983..bb5b633af5b 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java @@ -19,13 +19,14 @@ import org.eclipse.jetty.util.DateCache; /** StdErr Logging. * This implementation of the Logging facade sends all logs to StdErr with minimal formatting. * - * If the system property DEBUG is set, then debug logs are printed if stderr is being used. + * If the system property org.eclipse.jetty.util.log.DEBUG is set, + * then debug logs are printed if stderr is being used. * */ public class StdErrLog implements Logger { private static DateCache _dateCache; - private static boolean _debug = System.getProperty("DEBUG",null)!=null; + private static boolean _debug = System.getProperty("org.eclipse.jetty.util.log.DEBUG",null)!=null; private String _name; private boolean _hideStacks=false;