Issue #644 Modules for enabling logging

Separated modules for jetty logging
Added JCL
This commit is contained in:
Greg Wilkins 2016-06-17 14:56:21 +10:00
parent 79cd9add9f
commit d79b0a7acd
19 changed files with 160 additions and 33 deletions

View File

@ -11,7 +11,7 @@ etc/jetty-ssl.xml
etc/jetty-ssl-context.xml
[files]
https://raw.githubusercontent.com/eclipse/jetty.project/master/jetty-server/src/test/config/etc/keystore?id=${jetty.tag.version}|etc/keystore
basehome:modules/ssl/keystore|etc/keystore
[ini-template]
### TLS(SSL) Connector Configuration

View File

@ -113,24 +113,23 @@ public class BaseBuilder
Modules modules = startArgs.getAllModules();
// Select all the added modules to determine which ones are newly enabled
// TODO this does not look correct????
Set<String> enabled = new HashSet<>();
Set<String> startModules = new HashSet<>();
Set<String> newly_enabled = new HashSet<>();
if (!startArgs.getStartModules().isEmpty())
{
for (String name:startArgs.getStartModules())
startModules.addAll(modules.select(name,"--add-to-start[d]"));
enabled.addAll(startModules);
newly_enabled.addAll(modules.enable(name,"--add-to-start[d]"));
}
if (StartLog.isDebugEnabled())
StartLog.debug("start[d]=%s",startModules);
StartLog.debug("start[d]=%s",newly_enabled);
// Check the licenses
if (startArgs.isLicenseCheckRequired())
{
Licensing licensing = new Licensing();
for (String name : enabled)
for (String name : newly_enabled)
licensing.addModule(modules.get(name));
if (licensing.hasLicenses())
@ -152,7 +151,7 @@ public class BaseBuilder
AtomicReference<BaseBuilder.Config> builder = new AtomicReference<>();
AtomicBoolean modified = new AtomicBoolean();
if (!startModules.isEmpty())
if (!newly_enabled.isEmpty())
{
Path startd = getBaseHome().getBasePath("start.d");
Path startini = getBaseHome().getBasePath("start.ini");
@ -167,7 +166,7 @@ public class BaseBuilder
boolean useStartD=startArgs.isUseStartd() || Files.exists(startd);
builder.set(useStartD?new StartDirBuilder(this):new StartIniBuilder(this));
startModules.stream().map(n->modules.get(n)).forEach(module ->
newly_enabled.stream().map(n->modules.get(n)).forEach(module ->
{
try
{
@ -242,6 +241,7 @@ public class BaseBuilder
}
}
if (!FS.exists(file))
System.err.println("Failed to initialize: "+arg.uri+"|"+arg.location);
return modified;

View File

@ -97,8 +97,8 @@ public class Main
t.printStackTrace(System.err);
}
System.err.println();
System.err.println("Usage: java -jar start.jar [options] [properties] [configs]");
System.err.println(" java -jar start.jar --help # for more information");
System.err.println("Usage: java -jar $JETTY_HOME/start.jar [options] [properties] [configs]");
System.err.println(" java -jar $JETTY_HOME/start.jar --help # for more information");
if (test)
System.err.println("EXIT: "+exit);
@ -301,7 +301,7 @@ public class Main
for (String source : args.getSources(enabledModule))
{
String shortForm = baseHome.toShortForm(source);
modules.select(enabledModule,shortForm);
modules.enable(enabledModule,shortForm);
}
}
@ -350,10 +350,6 @@ public class Main
// 9) Resolve Property Files
args.resolvePropertyFiles(baseHome);
// ------------------------------------------------------------
// 10) Check enabled modules
args.getAllModules().checkEnabledModules();
return args;
}
@ -419,6 +415,9 @@ public class Main
else if (args.isDownload() || !args.getStartModules().isEmpty())
StartLog.info("Base directory was not modified");
// Check module dependencies
args.getAllModules().checkEnabledModules();
// Informational command line, don't run jetty
if (!args.isRun())
{

View File

@ -402,15 +402,24 @@ public class Module
public String toString()
{
StringBuilder str = new StringBuilder();
str.append(getName()).append('{');
str.append(getName());
char sep='{';
if (isDynamic())
{
str.append(sep).append("dynamic");
sep=',';
}
if (isEnabled())
{
str.append("enabled");
if (isTransitive())
str.append(",transitive");
str.append(sep).append("enabled");
sep=',';
}
else if (isTransitive())
str.append("transitive");
if (isTransitive())
{
str.append(sep).append("transitive");
sep=',';
}
if (sep!='{')
str.append('}');
return str.toString();
}

View File

@ -221,7 +221,12 @@ public class Modules implements Iterable<Module>
return _modules.stream().filter(m->{return m.isEnabled();}).collect(Collectors.toList());
}
public Set<String> select(String name, String enabledFrom)
/** Enable a module
* @param name The name of the module to enable
* @param enabledFrom The source the module was enabled from
* @return The set of modules newly enabled
*/
public Set<String> enable(String name, String enabledFrom)
{
Module module = get(name);
if (module==null)
@ -347,6 +352,7 @@ public class Modules implements Iterable<Module>
public void checkEnabledModules()
{
StringBuilder unsatisfied=new StringBuilder();
_modules.stream().filter(Module::isEnabled).forEach(m->
{
// Check dependencies
@ -354,9 +360,17 @@ public class Modules implements Iterable<Module>
{
Set<Module> providers =_provided.get(d);
if (providers.stream().filter(Module::isEnabled).count()==0)
throw new UsageException(-1,"Module %s requires %s from one of %s",m.getName(),d,providers);
{
if (unsatisfied.length()>0)
unsatisfied.append(',');
unsatisfied.append(m.getName());
System.err.printf("%nWARN: Module %s requires %s from one of %s%n",m.getName(),d,providers);
}
});
});
if (unsatisfied.length()>0)
throw new UsageException(-1,"Unsatisfied module dependencies: "+unsatisfied);
}
}

View File

@ -166,8 +166,8 @@ public class ModulesTest
modules.registerAll();
// Enable 2 modules
modules.select("base",TEST_SOURCE);
modules.select("optional",TEST_SOURCE);
modules.enable("base",TEST_SOURCE);
modules.enable("optional",TEST_SOURCE);
modules.sort();
// Collect active module list

View File

@ -133,6 +133,7 @@ public class TestUseCases
}
StartArgs args = main.processCommandLine(cmdLine);
args.getAllModules().checkEnabledModules();
BaseHome baseHome = main.getBaseHome();
ConfigurationAssert.assertConfiguration(baseHome,args,assertFile);
}

View File

@ -1 +1 @@
EX|UsageException: Module dependent requires alternate from one of
EX|UsageException: Unsatisfied module dependencies

View File

@ -0,0 +1,16 @@
[description]
Provides JCL implementation that routes logs into slf4j
[depends]
slf4j-api
[provides]
jcl-impl
jcl-api
[files]
maven://org.slf4j/jcl-over-slf4j/1.7.21|lib/slf4j/jcl-over-slf4j-1.7.21.jar
[lib]
lib/slf4j/jcl-over-slf4j-1.7.21.jar

View File

@ -0,0 +1,18 @@
[description]
Provides Apache Java Commons Logging API and implementation
[depends]
[provides]
jcl-api
jcl-impl
[files]
maven://commons-logging/commons-logging/1.1.3|lib/jcl/commons-logging-1.1.3.jar
[lib]
lib/jcl/commons-logging-1.1.3.jar
[license]
Log4j is released under the Apache 2.0 license.
http://www.apache.org/licenses/LICENSE-2.0.html

View File

@ -0,0 +1,12 @@
[description]
Enables Java util logging
[depends]
resources
[provide]
logging
[files]
basehome:modules/jetty-logging/jetty-logging.properties|resources/jetty-logging.properties

View File

@ -0,0 +1,12 @@
## Setup jetty logging implementation
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
## Levels are ALL, DEBUG, INFO, WARN, OFF
org.eclipse.jetty.LEVEL=INFO
#com.example.LEVEL=INFO
## Hide stacks traces in logs?
#com.example.STACKS=false
## Show the source file of a log location?
#com.example.SOURCE=false

View File

@ -0,0 +1,12 @@
[description]
Configure Jetty logging to use SLF4J
[depend]
slf4j-api
slf4j-impl
[provide]
logging
[exec]
-Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.Slf4jLog

View File

@ -0,0 +1,18 @@
[description]
Provides SLF4J bridge to apache java commons logging
[depend]
slf4j-api
jcl-api
[provide]
slf4j-impl
[files]
maven://org.slf4j/slf4j-jcl/1.7.21|lib/slf4j/slf4j-jcl-1.7.21.jar
[lib]
lib/slf4j/slf4j-jcl-1.7.21.jar
[exec]
-Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.Slf4jLog

View File

@ -0,0 +1,16 @@
[description]
Provides SLF4J Log4j implementation.
[depend]
slf4j-api
log4j-api
[provide]
slf4j-impl
[files]
maven://org.slf4j/slf4j-log4j12/1.7.21|lib/slf4j/slf4j-log4j12-1.7.21.jar
[lib]
lib/slf4j/slf4j-log4j12-1.7.21.jar

View File

@ -3,7 +3,7 @@ Redirects JVMs stderr and stdout to a log file,
including output from Jetty's default StdErrLog logging.
[xml]
etc/jetty-logging.xml
etc/stderrout-logging.xml
[files]
logs/