Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

NEXUS-5118: Rationalizing logging in bundle #530

Merged
merged 7 commits into from

4 participants

@cstamas
Owner

Logging between Nexus 1.9, 2.0, 2.1 changed a lot, and 2.2 should sort all the user reported problems, like:

  • Jetty and Nexus uses different logging frameworks (Jetty uses ConsoleLogger while Nexus logback in 2.0 for example)
  • duplications of logback libraries in 2.1 etc

CI:
https://builds.sonatype.org/view/nexus-features/job/nexus-oss-its-feature/407/

cstamas added some commits
@cstamas cstamas NEXUS-5118: Initial imple
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.
349670d
@cstamas cstamas NEXUS-5118: Adding exclusion for top level invluded JAR
Did not stir much water, but Tattletale chokes on this.
18270f5
@cstamas cstamas NEXUS-5118: Made a plexus component for EventTarget 4f87c61
@cstamas cstamas NEXUS-5118: Making the Event Target a SISU component 6d10eba
@cstamas cstamas NEXUS-5118: Fixing the initial imple
The initial implementation was conceived okay, but
there was a problem with Injection happening as the class
loaded up had annotations thrown away by classloader.

Reason for that is that in bundle layout the appender
is on Jetty classloader level (parent of Nexus webapp)
and that CL does not have @Inject. Hence, the fix was to
introduce "special" case for injection when ForwaringAppender
was met, simply doing manual injection on it.
9b6bffb
@cstamas cstamas NEXUS-5118: Unrelated file on my local FS got into the commit by mist…
…ake.
1b90ad3
@peterlynch peterlynch commented on the diff
...main/java/org/sonatype/nexus/logback/EventTarget.java
((8 lines not shown))
+ *
+ * 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
@peterlynch Owner

If this is all about logging, is there a reason you did not call this LoggingEventTarget?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@peterlynch
Owner

checked out the branch and tried this out a bit - seems to log things correctly - and nexus war is not affected ( still contain logback impl ), so appears all fine.

If there are problems this is solving, are there tests we can write to demonstrate the problems and prove this changes fixes it?

@cstamas
Owner

CI passed on both slaves, but new file missed a license header (fixed in c0ee3dd)

@adreghiciu
Owner

+1

@nabcos

+1

@cstamas cstamas merged commit bd8d01f into master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 4, 2012
  1. @cstamas

    NEXUS-5118: Initial imple

    cstamas authored
    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.
  2. @cstamas

    NEXUS-5118: Adding exclusion for top level invluded JAR

    cstamas authored
    Did not stir much water, but Tattletale chokes on this.
  3. @cstamas
  4. @cstamas
  5. @cstamas

    NEXUS-5118: Fixing the initial imple

    cstamas authored
    The initial implementation was conceived okay, but
    there was a problem with Injection happening as the class
    loaded up had annotations thrown away by classloader.
    
    Reason for that is that in bundle layout the appender
    is on Jetty classloader level (parent of Nexus webapp)
    and that CL does not have @Inject. Hence, the fix was to
    introduce "special" case for injection when ForwaringAppender
    was met, simply doing manual injection on it.
  6. @cstamas
  7. @cstamas
This page is out of date. Refresh to see the latest.
View
42 nexus/nexus-logging-extras-appender/pom.xml
@@ -0,0 +1,42 @@
+<!--
+
+ 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>
+ <!-- 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>
+ </dependencies>
+
+</project>
View
26 ...s/nexus-logging-extras-appender/src/main/java/org/sonatype/nexus/logback/EventTarget.java
@@ -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
@peterlynch Owner

If this is all about logging, is there a reason you did not call this LoggingEventTarget?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+{
+ void onEvent( ILoggingEvent event );
+}
View
70 ...-logging-extras-appender/src/main/java/org/sonatype/nexus/logback/ForwardingAppender.java
@@ -0,0 +1,70 @@
+/**
+ * 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;
+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>
+{
+ private EventTarget target;
+
+ /**
+ * Default constructor that creates and resets this instance.
+ */
+ public ForwardingAppender()
+ {
+ reset();
+ }
+
+ @Override
+ protected void append( final ILoggingEvent event )
+ {
+ target.onEvent( event );
+ }
+
+ // ==
+
+ /**
+ * Installs or replaces an {@link EventTarget} to have events forwarded to it.
+ *
+ * @param target
+ */
+ public void installEventTarget( final EventTarget target )
+ {
+ if ( target != null )
+ {
+ this.target = target;
+ }
+ else
+ {
+ reset();
+ }
+ }
+
+ /**
+ * Performs a "reset" of this forwarding appender, and previously installed {@link EventTarget} (if any) will stop
+ * receiving events.
+ */
+ public void reset()
+ {
+ this.target = NoopEventTarget.INSTANCE;
+ }
+}
View
27 ...xus-logging-extras-appender/src/main/java/org/sonatype/nexus/logback/NoopEventTarget.java
@@ -0,0 +1,27 @@
+/**
+ * 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;
+
+public final class NoopEventTarget
+ implements EventTarget
+{
+ final static NoopEventTarget INSTANCE = new NoopEventTarget();
+
+ @Override
+ public void onEvent( final ILoggingEvent event )
+ {
+ // noop
+ }
+}
View
6 nexus/nexus-logging-extras/pom.xml
@@ -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>
View
14 ...nexus-logging-extras/src/main/java/org/sonatype/nexus/log/internal/LogbackLogManager.java
@@ -50,6 +50,8 @@
import org.sonatype.nexus.log.LogConfiguration;
import org.sonatype.nexus.log.LogConfigurationParticipant;
import org.sonatype.nexus.log.LogManager;
+import org.sonatype.nexus.logback.EventTarget;
+import org.sonatype.nexus.logback.ForwardingAppender;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
@@ -101,6 +103,9 @@
@Requirement
private ApplicationConfiguration applicationConfiguration;
+ @Requirement
+ private EventTarget eventTarget;
+
private ObjectName jmxName;
public LogbackLogManager()
@@ -482,6 +487,15 @@ private void injectAppenders()
{
Appender<ILoggingEvent> ap = it.next();
injector.injectMembers( ap );
+
+ // ForwardingAppender needs some special care: manual injection
+ // since @Inject is not on Jetty classpath (parent of this classpath) and Injector will not do anything
+ // with it since classloader will not pick up annotations on class while loading up the class itself
+ if ( ap instanceof ForwardingAppender )
+ {
+ final ForwardingAppender fap = (ForwardingAppender) ap;
+ fap.installEventTarget( eventTarget );
+ }
}
}
}
View
44 ...ing-extras/src/main/java/org/sonatype/nexus/log/internal/NexusEventSystemEventTarget.java
@@ -0,0 +1,44 @@
+/**
+ * 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 org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+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
+ */
+@Component( role = EventTarget.class )
+public class NexusEventSystemEventTarget
+ implements EventTarget
+{
+ @Requirement
+ private ApplicationEventMulticaster eventMulticaster;
+
+ @Override
+ public void onEvent( final ILoggingEvent eventObject )
+ {
+ if ( eventMulticaster != null )
+ {
+ final LogbackLoggingEvent logEvent = new LogbackLoggingEvent( eventObject );
+ eventMulticaster.notifyEventListeners( logEvent );
+ }
+ }
+}
View
2  nexus/nexus-logging-extras/src/main/resources/META-INF/log/logback-events.xml
@@ -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>
View
4 nexus/nexus-oss-webapp/pom.xml
@@ -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>
View
5 nexus/nexus-oss-webapp/src/main/assembly/bundle.xml
@@ -91,6 +91,10 @@
<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/lib/nexus-logging-extras-appender*.jar</exclude>
<exclude>WEB-INF/classes/logback.xml</exclude>
</excludes>
</unpackOptions>
@@ -101,6 +105,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>
View
6 nexus/nexus-oss-webapp/src/main/resources/content/conf/jetty.xml
@@ -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>
View
6 nexus/pom.xml
@@ -1113,6 +1113,11 @@
</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>
<version>${project.version}</version>
</dependency>
@@ -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>
Something went wrong with that request. Please try again.