add logback integration

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1212 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Hugues Malphettes 2010-01-25 04:35:24 +00:00
parent 0b7850d179
commit c706695eca
10 changed files with 368 additions and 20 deletions

View File

@ -48,7 +48,7 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
private boolean _recursive = false;
private int _scanInterval = 10;
private Scanner _scanner;
private final Scanner.DiscreteListener _scannerListener = new Scanner.DiscreteListener()
{
public void fileAdded(String filename) throws Exception
@ -66,8 +66,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
{
Log.debug("changed ",filename);
App app = _appMap.remove(filename);
if (app != null)
_deploymentManager.removeApp(app);
app = ScanningAppProvider.this.createApp(filename);
if (app != null)
{

View File

@ -0,0 +1,19 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Jetty-OSGi-Logback integration
Fragment-Host: org.eclipse.jetty.osgi.boot
Bundle-SymbolicName: org.eclipse.jetty.osgi.boot.logback;singleton:=true
Bundle-Version: 7.0.1.qualifier
Bundle-Vendor: Mort Bay Consulting
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: ch.qos.logback.classic,
ch.qos.logback.classic.joran,
ch.qos.logback.core,
ch.qos.logback.core.joran,
ch.qos.logback.core.joran.spi,
ch.qos.logback.core.spi,
ch.qos.logback.core.util,
org.apache.commons.logging;resolution:=optional,
org.apache.log4j;resolution:=optional,
org.osgi.framework,
org.slf4j

View File

@ -0,0 +1,12 @@
This bundle is made to inject the logback dependencies along with the slf4j dependencies to support log4j and commons-logging.
It will read the configuration in the jettyhome/resources/logback-test.xml or jettyhome/resources/logback.xml folder.
It was tested with these bundles:
#this provides lg4j and commons-logging via slf4j
SLF4J = group("com.springsource.slf4j.api", "com.springsource.slf4j.org.apache.log4j", "com.springsource.slf4j.org.apache.commons.logging",
:under=>"org.slf4j", :version=>"1.5.6")
#logback is not exporting enough packages for us to be able to configure logback classic programatically.. on the springsource version they are fine...
LOGBACK = group("com.springsource.ch.qos.logback.core", "com.springsource.ch.qos.logback.classic",
:under=>"ch.qos.logback", :version=>"0.9.15")

View File

@ -0,0 +1,5 @@
source.. = src/main/java/
output.. = target/classes/
bin.includes = META-INF/,\
.
src.includes = META-INF/

View File

@ -0,0 +1,101 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.eclipse.jetty.osgi</groupId>
<artifactId>jetty-osgi-project</artifactId>
<version>7.0.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.jetty.osgi</groupId>
<artifactId>org.eclipse.jetty.osgi.boot.logback</artifactId>
<name>Jetty :: OSGi :: Boot Logback</name>
<description>Jetty OSGi Boot Logback bundle</description>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.osgi</groupId>
<artifactId>jetty-osgi-boot</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>osgi</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.osgi</groupId>
<artifactId>services</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-resources</phase>
<configuration>
<tasks>
<replace file="target/classes/META-INF/MANIFEST.MF"
token="Bundle-Version: 7.0.1.qualifier"
value="Bundle-Version: ${parsedVersion.osgiVersion}"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>artifact-jar</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
<execution>
<id>test-jar</id>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifestFile>target/classes/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>jetty-osgi</artifactId>
<version>7.0.1-SNAPSHOT</version>
<groupId>org.eclipse.jetty.osgi</groupId>
</parent>
<artifactId>org.eclipse.jetty.osgi.boot.logback</artifactId>
<packaging>eclipse-plugin</packaging>
</project>

View File

@ -0,0 +1,86 @@
// ========================================================================
// Copyright (c) 2009 Intalio, Inc.
// ------------------------------------------------------------------------
// 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.osgi.boot.logback;
import java.io.File;
import java.util.Map;
import org.eclipse.jetty.osgi.boot.internal.webapp.LibExtClassLoaderHelper;
import org.eclipse.jetty.osgi.boot.internal.webapp.OSGiWebappClassLoader;
import org.eclipse.jetty.osgi.boot.internal.webapp.LibExtClassLoaderHelper.IFilesInJettyHomeResourcesProcessor;
import org.eclipse.jetty.osgi.boot.logback.internal.LogbackInitializer;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
/**
* Pseudo fragment activator.
* Called by the main org.eclipse.jetty.osgi.boot bundle.
* Please note: this is not a real BundleActivator. Simply something called back by
* the host bundle.
* The fragment is in charge of placing a hook to configure logback
* when the files inside jettyhome/resources are parsed.
*/
public class FragmentActivator implements BundleActivator, IFilesInJettyHomeResourcesProcessor
{
/**
*
*/
public void start(BundleContext context) throws Exception
{
LibExtClassLoaderHelper.registeredFilesInJettyHomeResourcesProcessors.add(this);
//now let's make sure no log4j, no slf4j and no commons.logging
//get inserted as a library that is not an osgi library
OSGiWebappClassLoader.addClassThatIdentifiesAJarThatMustBeRejected("org.apache.commons.logging.Log");
OSGiWebappClassLoader.addClassThatIdentifiesAJarThatMustBeRejected("org.apache.log4j.Logger");
OSGiWebappClassLoader.addClassThatIdentifiesAJarThatMustBeRejected("org.slf4j.Logger");
//OSGiWebappClassLoader.addClassThatIdentifiesAJarThatMustBeRejected(java.util.logging.Logger.class);
}
/**
* Called when this bundle is stopped so the Framework can perform the
* bundle-specific activities necessary to stop the bundle. In general, this
* method should undo the work that the <code>BundleActivator.start</code>
* method started. There should be no active threads that were started by
* this bundle when this bundle returns. A stopped bundle must not call any
* Framework objects.
*
* <p>
* This method must complete and return to its caller in a timely manner.
*
* @param context The execution context of the bundle being stopped.
* @throws Exception If this method throws an exception, the
* bundle is still marked as stopped, and the Framework will remove
* the bundle's listeners, unregister all services registered by the
* bundle, and release all services used by the bundle.
*/
public void stop(BundleContext context) throws Exception
{
LibExtClassLoaderHelper.registeredFilesInJettyHomeResourcesProcessors.remove(this);
}
public void processFilesInResourcesFolder(File jettyHome, Map<String,File> files)
{
try
{
LogbackInitializer.processFilesInResourcesFolder(jettyHome, files);
}
catch (Throwable t)
{
t.printStackTrace();
}
}
}

View File

@ -0,0 +1,98 @@
// ========================================================================
// Copyright (c) 2009 Intalio, Inc.
// ------------------------------------------------------------------------
// 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.
// Contributors:
// Hugues Malphettes - initial API and implementation
// ========================================================================
package org.eclipse.jetty.osgi.boot.logback.internal;
import java.io.File;
import java.util.Map;
import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.JoranConfiguratorBase;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.util.StatusPrinter;
/**
* Setup logback eventually located in the config file inside jettyhome/resources
* All logback related code is done in this separate class for better debug
* and isolation when it does not load.
*/
public class LogbackInitializer {
/**
* @return true when we are currently being run by the pde in development mode.
*/
private static boolean isPDEDevelopment()
{
String eclipseCommands = System.getProperty("eclipse.commands");
// detect if we are being run from the pde: ie during development.
return eclipseCommands != null && eclipseCommands.indexOf("-dev") != -1
&& (eclipseCommands.indexOf("-dev\n") != -1
|| eclipseCommands.indexOf("-dev\r") != -1
|| eclipseCommands.indexOf("-dev ") != -1);
}
/**
* Follow the configuration for logback.
* unless the system propery was set in which case it
* was assume it was already setup.
*/
public static void processFilesInResourcesFolder(File jettyHome, Map<String,File> files)
{
String logbackConf = System.getProperty("logback.configurationFile");
if (logbackConf != null)
{
File confFile = new File(logbackConf);
if (confFile.exists())
{
//assume logback was configured by this one?
return;
}
}
File logConf = isPDEDevelopment() ? files.get("logback-dev.xml") : null;
if (logConf == null)
{
logConf = files.get("logback-test.xml");
}
if (logConf == null)
{
logConf = files.get("logback.xml");
}
if (logConf == null)
{
return;
}
// assume SLF4J is bound to logback in the current environment
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
try
{
JoranConfiguratorBase configurator = new JoranConfigurator();
configurator.setContext(lc);
lc.reset();
configurator.doConfigure(logConf.getAbsoluteFile().getAbsolutePath());
}
catch (JoranException je)
{
je.printStackTrace();
}
StatusPrinter.printIfErrorsOccured(lc);
}
}

View File

@ -153,21 +153,6 @@ public class OSGiAppProvider extends ScanningAppProvider implements AppProvider
getDeploymentManager().addApp(app);
}
// TODO: refactor the WebAppRegistrationHelper to add the creation of the
// context directly from here.
// unless the client code took care of the creation of the ContextHandler.
// public void addContext(String contextxml) throws Exception
// {
// // TODO apply configuration specific to this provider
// // TODO construct ContextHandler
// ContextHandler context=null;
// // wrap context as an App
// OSGiApp app = new
// OSGiApp(_manager,this,context.getDisplayName(),context);
// _apps.put(context,app);
// _manager.addApp(app);
// }
/**
* Called by the scanner of the context files directory. If we find the
* corresponding deployed App we reload it by returning the App. Otherwise

View File

@ -15,12 +15,14 @@
<osgi-services-version>3.1.200-v20070605</osgi-services-version>
<equinox-http-servlet-version>1.0.0-v20070606</equinox-http-servlet-version>
<jsp-2.1-glassfish-version>2.1.v20091210</jsp-2.1-glassfish-version>
<logback-version>0.9.18</logback-version>
<slf4j-version>1.5.10</slf4j-version>
</properties>
<modules>
<module>jetty-osgi-boot</module>
<module>jetty-osgi-boot-jsp</module>
<!-- once logback is ready for eclipse -->
<!-- module>jetty-osgi-boot-logback</module -->
<!-- logback is currently under CQs -->
<module>jetty-osgi-boot-logback</module>
<module>jetty-osgi-boot-warurl</module>
<module>jetty-osgi-httpservice</module>
<module>example-jetty-osgi</module>
@ -130,6 +132,36 @@
<version>${jsp-2.1-glassfish-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${slf4j-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback-version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>