Issue #644 Modules for enabling logging

This commit is contained in:
Greg Wilkins 2016-06-16 20:31:52 +10:00
parent bb73aea67b
commit 2fbf466393
25 changed files with 297 additions and 36 deletions

View File

@ -5,6 +5,7 @@ Enables the core Jetty server on the classpath.
jvm
ext
resources
logging
[lib]
lib/servlet-api-3.1.jar

View File

@ -28,10 +28,10 @@ import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import org.eclipse.jetty.start.builders.StartDirBuilder;
import org.eclipse.jetty.start.builders.StartIniBuilder;
import org.eclipse.jetty.start.fileinits.BaseHomeFileInitializer;
import org.eclipse.jetty.start.fileinits.MavenLocalRepoFileInitializer;
import org.eclipse.jetty.start.fileinits.TestFileInitializer;
import org.eclipse.jetty.start.fileinits.UriFileInitializer;
@ -71,6 +71,9 @@ public class BaseBuilder
// Establish FileInitializers
if (args.isTestingModeEnabled())
{
// Copy from basehome
fileInitializers.add(new BaseHomeFileInitializer(baseHome));
// No downloads performed
fileInitializers.add(new TestFileInitializer());
}
@ -90,6 +93,9 @@ public class BaseBuilder
fileInitializers.add(new MavenLocalRepoFileInitializer(baseHome));
}
// Copy from basehome
fileInitializers.add(new BaseHomeFileInitializer(baseHome));
// Normal URL downloads
fileInitializers.add(new UriFileInitializer(baseHome));
}
@ -215,14 +221,12 @@ public class BaseBuilder
*/
private boolean processFileResource(FileArg arg, Path file) throws IOException
{
// now on copy/download paths (be safe above all else)
if (!file.startsWith(baseHome.getBasePath()))
throw new IOException("For security reasons, Jetty start is unable to process maven file resource not in ${jetty.base} - " + file);
if (startArgs.isDownload() && (arg.uri != null))
{
// now on copy/download paths (be safe above all else)
if (!file.startsWith(baseHome.getBasePath()))
{
throw new IOException("For security reasons, Jetty start is unable to process maven file resource not in ${jetty.base} - " + file);
}
// make the directories in ${jetty.base} that we need
boolean modified = FS.ensureDirectoryExists(file.getParent());
@ -238,7 +242,9 @@ public class BaseBuilder
}
}
return false;
System.err.println("Failed to initialize: "+arg.uri+"|"+arg.location);
return modified;
}
else
{

View File

@ -44,10 +44,11 @@ public class FileArg
final String LN = System.lineSeparator();
err.append("Unrecognized [file] argument: ").append(uriLocation);
err.append(LN).append("Valid Syntaxes: ");
err.append(LN).append(" <relative-path> - eg: resources/");
err.append(LN).append(" or <absolute-path> - eg: /var/run/jetty.pid");
err.append(LN).append(" or <uri>|<relative-path> - eg: http://machine/my.conf|resources/my.conf");
err.append(LN).append(" or <uri>|<absolute-path> - eg: http://machine/glob.dat|/opt/run/glob.dat");
err.append(LN).append(" <relative-path> - eg: resources/");
err.append(LN).append(" or <absolute-path> - eg: /var/run/jetty.pid");
err.append(LN).append(" or <uri>|<rel-path> - eg: http://machine/my.conf|resources/my.conf");
err.append(LN).append(" or <uri>|<abs-path> - eg: http://machine/glob.dat|/opt/run/glob.dat");
err.append(LN).append("Known uri schemes: http, maven, home");
throw new IllegalArgumentException(err.toString());
}
if (parts.length == 2)

View File

@ -402,16 +402,16 @@ public class Module
public String toString()
{
StringBuilder str = new StringBuilder();
str.append("Module[").append(getName());
str.append(getName()).append('{');
if (isEnabled())
{
str.append(",enabled");
str.append("enabled");
if (isTransitive())
str.append(",transitive");
}
if (isTransitive())
{
str.append(",transitive");
}
str.append(']');
else if (isTransitive())
str.append("transitive");
str.append('}');
return str.toString();
}

View File

@ -205,7 +205,15 @@ public class Modules implements Iterable<Module>
module.getDepends().forEach(add);
module.getOptional().forEach(add);
}
sort.sort(_modules);
try
{
sort.sort(_modules);
}
catch (IllegalStateException e)
{
System.err.println(sort.dump());
throw e;
}
}
public List<Module> getEnabled()
@ -251,7 +259,7 @@ public class Modules implements Iterable<Module>
}
}
else
throw new UsageException("Capability %s already enabled by %s for %s",name,p.getName(),module.getName());
throw new UsageException("%s provides %s, which is already provided by %s enabled in %s",module.getName(),name,p.getName(),p.getEnableSources());
}
});
}

View File

@ -0,0 +1,61 @@
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.start.fileinits;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import org.eclipse.jetty.start.BaseHome;
import org.eclipse.jetty.start.FS;
import org.eclipse.jetty.start.FileInitializer;
/**
* Copy a file found in {@link BaseHome} from a URI of the form
* "basehome:some/path"
* {@link FileInitializer}
*/
public class BaseHomeFileInitializer implements FileInitializer
{
private final BaseHome _basehome;
public BaseHomeFileInitializer(BaseHome basehome)
{
_basehome=basehome;
}
@Override
public boolean init(URI uri, Path file, String fileRef) throws IOException
{
if (!"basehome".equalsIgnoreCase(uri.getScheme()) || uri.getSchemeSpecificPart().startsWith("/"))
return false;
Path source = _basehome.getPath(uri.getSchemeSpecificPart());
if (FS.exists(source) && !FS.exists(file))
{
FS.ensureDirectoryExists(file.getParent());
Files.copy(source,file);
return true;
}
return false;
}
}

View File

@ -1,2 +1,2 @@
EX|UsageException
EX|default already enabled by alternate
EX|default, which is already provided by alternate

View File

@ -0,0 +1,2 @@
DOWNLOAD|basehome:modules/demo/demo-config.xml|etc/demo-config.xml
EXISTS|etc/demo-config.xml

View File

@ -0,0 +1 @@
--add-to-startd=demo

View File

@ -0,0 +1,3 @@
[files]
basehome:modules/demo/demo-config.xml|etc/demo-config.xml

View File

@ -0,0 +1,8 @@
[description]
Enables Java util logging
[provide]
logging
[exec]
-Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.JavaUtilLog

View File

@ -0,0 +1,16 @@
[description]
Provides Apache Log4j 1.2 bridge to Log4j 2.
[depends]
log4j2-impl
[provides]
log4j-api
log4j-impl
[files]
maven://org.apache.logging.log4j/log4j-1.2-api/2.6.1|lib/log4j/log4j-1.2-api-2.6.1.jar
[lib]
lib/log4j/log4j-1.2-api-2.6.1.jar

View File

@ -0,0 +1,20 @@
[description]
Provides Apache Log4j 1.2
[depends]
resources
[provides]
log4j-api
log4j-impl
[files]
basehome:modules/log4j/log4j.properties|resources/log4j.properties
maven://log4j/log4j/1.2.17|lib/log4j/log4j-1.2.17.jar
[lib]
lib/log4j/log4j-1.2.17.jar
[license]
Log4j is released under the Apache 2.0 license.
http://www.apache.org/licenses/LICENSE-2.0.html

View File

@ -1,6 +1,4 @@
# This is not needed by Jetty - but it helps with many web apps.
log4j.rootLogger=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender

View File

@ -0,0 +1,14 @@
[description]
Provides Apache Log4j 2 API.
Requires a log4j 2 implementation module
Use slf4j-log4j module to link jetty logging
[files]
maven://org.apache.logging.log4j/log4j-api/2.6.1|lib/log4j/log4j-api-2.6.1.jar
[lib]
lib/log4j/log4j-api-2.6.1.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,16 @@
[description]
Provides Apache Log4j 2 Core.
[depends]
log4j2-api
[provides]
log4j2-impl
[files]
basehome:modules/log4j2/log4j2.properties|resources/log4j2.properties
maven://org.apache.logging.log4j/log4j-core/2.6.1|lib/log4j/log4j-core-2.6.1.jar
[lib]
lib/log4j/log4j-core-2.6.1.jar

View File

@ -0,0 +1,17 @@
[description]
Provides Apache Log4j 2 implementation that routes
logs into slf4j
[depends]
log4j2-api
slf4j-api
[provides]
log4j2-impl
[files]
maven://org.apache.logging.log4j/log4j-to-slf4j/2.6.1|lib/log4j/log4j-to-slf4j-2.6.1.jar
[lib]
lib/log4j/log4j-slf4j-to-2.6.1.jar

View File

@ -0,0 +1,11 @@
status = error
name = PropertiesConfig
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %m%n
rootLogger.level = info
rootLogger.appenderRef.stdout.ref = STDOUT

View File

@ -13,16 +13,6 @@ lib/logging/**.jar
resources/
[ini-template]
## Logging Configuration
## Configure jetty logging for default internal behavior STDERR output
# -Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
## Configure jetty logging for slf4j
# -Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.Slf4jLog
## Configure jetty logging for java.util.logging
# -Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.JavaUtilLog
## Logging directory (relative to $jetty.base)
# jetty.logging.dir=logs

View File

@ -0,0 +1,36 @@
[description]
Provides SLF4J API. Requires a slf4j implementation (eg slf4j-simple)
otherwise a noop implementation is used.
[provides
logging
[files]
maven://org.slf4j/slf4j-api/1.7.21|lib/slf4j/slf4j-api-1.7.21.jar
[lib]
lib/slf4j/slf4j-api-1.7.21.jar
[license]
SLF4J is distributed under the MIT License.
Copyright (c) 2004-2013 QOS.ch
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

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

View File

@ -17,8 +17,10 @@
//
package org.eclipse.jetty.util;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
@ -28,6 +30,10 @@ import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.util.component.Dumpable;
import org.eclipse.jetty.util.component.DumpableCollection;
/**
* Topological sort a list or array.
@ -45,7 +51,7 @@ import java.util.TreeSet;
*
* @param <T> The type to be sorted. It must be able to be added to a {@link HashSet}
*/
public class TopologicalSort<T>
public class TopologicalSort<T> implements Dumpable
{
private final Map<T,Set<T>> _dependencies = new HashMap<>();
@ -182,4 +188,17 @@ public class TopologicalSort<T>
{
return "TopologicalSort "+_dependencies;
}
@Override
public String dump()
{
return ContainerLifeCycle.dump(this);
}
@Override
public void dump(Appendable out, String indent) throws IOException
{
out.append(String.format("TopologicalSort@%x%n",hashCode()));
ContainerLifeCycle.dump(out, indent,_dependencies.entrySet());
}
}

View File

@ -183,7 +183,7 @@ public class Log
}
if (LOG!=null)
LOG.info(String.format("Logging initialized @%dms",Uptime.getUptime()));
LOG.info(String.format("Logging initialized @%dms to %s",Uptime.getUptime(),LOG.getClass().getName()));
}
}