Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
NEXUS-5118: Initial imple
Browse files Browse the repository at this point in the history
Goal is to make "bundle packaging" (which is basically Jetty + Nexus WAR)
use same LogBack instance (as we had problems reported by users in 2.0).

Changes:
* jetty.xml - umarked "server level" logback as hidden to make it really shared
* extracted custom appender into new module nexus-logging-extras-appender that is put top level
* nexus-logging-extras got component implementation for EventTarget
* logback-events.xml changed to use new appender
* bundle assembly changed that exclude all logging relevant JARs from Nexus WAR as they are _provided_ on top level from now on

This is WIP, not yet functional.
  • Loading branch information
cstamas committed Sep 4, 2012
1 parent e7c7ff3 commit 349670d
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 7 deletions.
55 changes: 55 additions & 0 deletions nexus/nexus-logging-extras-appender/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!--
Sonatype Nexus (TM) Open Source Version
Copyright (c) 2007-2012 Sonatype, Inc.
All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
Eclipse Foundation. All other trademarks are the property of their respective owners.
-->
<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">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.sonatype.nexus</groupId>
<artifactId>nexus</artifactId>
<version>2.2-SNAPSHOT</version>
</parent>

<artifactId>nexus-logging-extras-appender</artifactId>
<name>Nexus : Logging Extras - Appender</name>

<dependencies>
<!-- We have components in here -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>

<!-- Logging -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>compile</scope>
</dependency>

<!-- Testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit-dep</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2007-2012 Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.sonatype.nexus.logback;

import ch.qos.logback.classic.spi.ILoggingEvent;

/**
* An target that receives logging events from {@link ForwardingAppender}.
*
* @author cstamas
* @since 2.2
*/
public interface EventTarget
{
void onEvent( ILoggingEvent event );
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2007-2012 Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.sonatype.nexus.logback;

import javax.inject.Inject;

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.UnsynchronizedAppenderBase;

/**
* A forwarding appender for Logback, that forwards {@link ILoggingEvent} events it gets as Appender, to it's target.
*
* @author cstamas
* @since 2.2
*/
public class ForwardingAppender
extends UnsynchronizedAppenderBase<ILoggingEvent>
{
@Inject
private EventTarget target;

@Override
protected void append( final ILoggingEvent event )
{
if ( target != null )
{
target.onEvent( event );
}
}
}
6 changes: 6 additions & 0 deletions nexus/nexus-logging-extras/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
<name>Nexus : Logging Extras</name>

<dependencies>
<!-- The appender -->
<dependency>
<groupId>org.sonatype.nexus</groupId>
<artifactId>nexus-logging-extras-appender</artifactId>
</dependency>

<!-- We have components in here -->
<dependency>
<groupId>org.sonatype.sisu</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2007-2012 Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.sonatype.nexus.log.internal;

import javax.enterprise.inject.Typed;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import org.sonatype.nexus.logback.EventTarget;
import org.sonatype.plexus.appevents.ApplicationEventMulticaster;

import ch.qos.logback.classic.spi.ILoggingEvent;

/**
* {@link EventTarget} that will multicast the incoming logging event to {@link ApplicationEventMulticaster}.
*
* @author cstamas
* @since 2.2
*/
@Named
@Singleton
@Typed( EventTarget.class )
public class NexusEventSystemEventTarget
implements EventTarget
{
@Inject
private ApplicationEventMulticaster eventMulticaster;

@Override
public void onEvent( final ILoggingEvent eventObject )
{
if ( eventMulticaster != null )
{
final LogbackLoggingEvent logEvent = new LogbackLoggingEvent( eventObject );
eventMulticaster.notifyEventListeners( logEvent );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<included>

<appender name="events" class="org.sonatype.nexus.log.internal.NexusEventSystemAppender">
<appender name="events" class="org.sonatype.nexus.logback.ForwardingAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>WARN</level>
</filter>
Expand Down
4 changes: 4 additions & 0 deletions nexus/nexus-oss-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>org.sonatype.nexus</groupId>
<artifactId>nexus-logging-extras-appender</artifactId>
</dependency>

<!-- The Jetty itself -->
<dependency>
Expand Down
4 changes: 4 additions & 0 deletions nexus/nexus-oss-webapp/src/main/assembly/bundle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
<excludes>
<exclude>META-INF/**</exclude>
<exclude>WEB-INF/lib/appcontext*.jar</exclude>
<exclude>WEB-INF/lib/slf4j-api*.jar</exclude>
<exclude>WEB-INF/lib/logback-core*.jar</exclude>
<exclude>WEB-INF/lib/logback-classic*.jar</exclude>
<exclude>WEB-INF/classes/logback.xml</exclude>
</excludes>
</unpackOptions>
Expand All @@ -101,6 +104,7 @@
<dependencySet>
<includes>
<include>org.sonatype.nexus:nexus-bootstrap</include>
<include>org.sonatype.nexus:nexus-logging-extras-appender</include>
<include>javax.servlet:*</include>
<include>org.eclipse.jetty:*</include>
<include>org.codehaus.plexus:*</include>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@
<Arg><Ref id="Contexts"/></Arg>
<Arg>${nexus-webapp}</Arg>
<Arg>${nexus-webapp-context-path}</Arg>
<Set name="serverClasses">
<Array type="java.lang.String">
<Item>org.slf4j.</Item>
<Item>ch.qos.logback.</Item>
</Array>
</Set>
<Set name="extractWAR">false</Set>
<Set name="throwUnavailableOnStartupException">true</Set>
</New>
Expand Down
6 changes: 6 additions & 0 deletions nexus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,11 @@
<artifactId>nexus-logging-extras</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.sonatype.nexus</groupId>
<artifactId>nexus-logging-extras-appender</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.sonatype.nexus</groupId>
<artifactId>nexus-api</artifactId>
Expand Down Expand Up @@ -1803,6 +1808,7 @@
<module>nexus-utils</module>
<module>nexus-web-utils</module>
<module>nexus-logging-extras</module>
<module>nexus-logging-extras-appender</module>
<module>nexus-api</module>
<module>nexus-oss-edition</module>
<module>nexus-configuration-model</module>
Expand Down

0 comments on commit 349670d

Please sign in to comment.