mirror of https://github.com/qos-ch/slf4j
Compare commits
20 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
0b97c416e4 | |
|
|
c6c7a98a7e | |
|
|
ca93154c79 | |
|
|
d061e25477 | |
|
|
e8ce694e2e | |
|
|
125e7cca19 | |
|
|
a7562cb4b9 | |
|
|
9752c892fd | |
|
|
b44fbd53cc | |
|
|
2a1374691f | |
|
|
4c6c574a7a | |
|
|
71291d97ba | |
|
|
bf50c49d10 | |
|
|
4e5ddca4ea | |
|
|
e69d4a9c73 | |
|
|
acb850d669 | |
|
|
179350d855 | |
|
|
7a35058597 | |
|
|
3cd3f3e5cc | |
|
|
918a055bdf |
|
|
@ -1,4 +1,9 @@
|
|||
language: java
|
||||
|
||||
jdk:
|
||||
- openjdk8
|
||||
|
||||
notifications:
|
||||
email:
|
||||
- notification@qos.ch
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,12 @@
|
|||
<pathelement location="../slf4j-simple/target/slf4j-simple-${currentVersion}.jar" />
|
||||
</path >
|
||||
|
||||
<path id="pathNoBinding">
|
||||
<pathelement location="target/test-classes/" />
|
||||
<pathelement location="../slf4j-api/target/slf4j-api-${currentVersion}.jar" />
|
||||
</path >
|
||||
|
||||
|
||||
<path id="incompatibleMultiBinding">
|
||||
<pathelement location="target/test-classes/" />
|
||||
<pathelement location="../slf4j-api/target/slf4j-api-${currentVersion}.jar" />
|
||||
|
|
@ -102,11 +107,12 @@
|
|||
</target>
|
||||
|
||||
<target name="testAll" depends="init,
|
||||
testMissingSingletonMethod,
|
||||
testMissingSingletonMethod,
|
||||
testMismatch,
|
||||
testMatch,
|
||||
testMultiBinding,
|
||||
testIncompatibleMultiBinding,
|
||||
testNoBinding,
|
||||
testMatch,
|
||||
testMultiBinding,
|
||||
testIncompatibleMultiBinding,
|
||||
testFuture_16Series,
|
||||
testActiveSecurityManager">
|
||||
</target>
|
||||
|
|
@ -215,7 +221,17 @@
|
|||
</junit>
|
||||
|
||||
</target>
|
||||
|
||||
|
||||
<target name="testNoBinding">
|
||||
<junit printsummary="yes" fork="no" haltonfailure="yes">
|
||||
<classpath refid="pathNoBinding" />
|
||||
<formatter type="plain" />
|
||||
<test fork="yes" todir="target/unit-reports"
|
||||
outfile="TEST-NOBINDING"
|
||||
name="org.slf4j.helpers.NoBindingMultithreadedInitializationTest2" />
|
||||
</junit>
|
||||
</target>
|
||||
|
||||
|
||||
<condition property="runFromWithinIntegrationModule">
|
||||
<contains string="${user.dir}" substring="integration" />
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>1.7.25</version>
|
||||
<version>1.7.30</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>integration</artifactId>
|
||||
|
|
|
|||
67
slf4j-ext/src/main/java/org/slf4j/ext/EventLogger.java → integration/src/test/java/org/slf4j/helpers/LoggerAccessingThread2.java
Executable file → Normal file
67
slf4j-ext/src/main/java/org/slf4j/ext/EventLogger.java → integration/src/test/java/org/slf4j/helpers/LoggerAccessingThread2.java
Executable file → Normal file
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (c) 2004-2011 QOS.ch
|
||||
* Copyright (c) 2004-2016 QOS.ch
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
|
|
@ -22,43 +22,44 @@
|
|||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
package org.slf4j.ext;
|
||||
package org.slf4j.helpers;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CyclicBarrier;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.slf4j.Marker;
|
||||
import org.slf4j.MarkerFactory;
|
||||
import org.slf4j.spi.LocationAwareLogger;
|
||||
|
||||
/**
|
||||
* Simple Logger used to log events. All events are directed to a logger named "EventLogger"
|
||||
* with a level of INFO and with an Event marker.
|
||||
*
|
||||
* @author Ralph Goers
|
||||
*/
|
||||
public class EventLogger {
|
||||
|
||||
private static final String FQCN = EventLogger.class.getName();
|
||||
|
||||
static Marker EVENT_MARKER = MarkerFactory.getMarker("EVENT");
|
||||
|
||||
private static LoggerWrapper eventLogger = new LoggerWrapper(LoggerFactory.getLogger("EventLogger"), FQCN);
|
||||
|
||||
/**
|
||||
* There can only be a single EventLogger.
|
||||
*/
|
||||
private EventLogger() {
|
||||
public class LoggerAccessingThread2 extends Thread {
|
||||
private static int LOOP_LEN = 64;
|
||||
|
||||
final CyclicBarrier barrier;
|
||||
final int count;
|
||||
final AtomicLong eventCount;
|
||||
List<Logger> loggerList;
|
||||
|
||||
public LoggerAccessingThread2(final CyclicBarrier barrier, List<Logger> loggerList, final int count, final AtomicLong eventCount) {
|
||||
this.barrier = barrier;
|
||||
this.loggerList = loggerList;
|
||||
this.count = count;
|
||||
this.eventCount = eventCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the event.
|
||||
*
|
||||
* @param data The EventData.
|
||||
*/
|
||||
public static void logEvent(EventData data) {
|
||||
if (eventLogger.instanceofLAL) {
|
||||
((LocationAwareLogger) eventLogger.logger).log(EVENT_MARKER, FQCN, LocationAwareLogger.INFO_INT, data.toXML(), new Object[] { data }, null);
|
||||
} else {
|
||||
eventLogger.logger.info(EVENT_MARKER, data.toXML(), data);
|
||||
public void run() {
|
||||
try {
|
||||
barrier.await();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String loggerNamePrefix = this.getClass().getName();
|
||||
for (int i = 0; i < LOOP_LEN; i++) {
|
||||
Logger logger = LoggerFactory.getLogger(loggerNamePrefix + "-" + count + "-" + i);
|
||||
loggerList.add(logger);
|
||||
Thread.yield();
|
||||
logger.info("in run method");
|
||||
eventCount.getAndIncrement();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
/**
|
||||
* Copyright (c) 2004-2016 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.
|
||||
*
|
||||
*/
|
||||
package org.slf4j.helpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.BrokenBarrierException;
|
||||
import java.util.concurrent.CyclicBarrier;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.slf4j.event.EventRecodingLogger;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class NoBindingMultithreadedInitializationTest2 extends TestCase {
|
||||
final protected static int THREAD_COUNT = 4 + Runtime.getRuntime().availableProcessors() * 2;
|
||||
|
||||
private final List<Logger> createdLoggers = Collections.synchronizedList(new ArrayList<Logger>());
|
||||
|
||||
protected final AtomicLong eventCount = new AtomicLong(0);
|
||||
final private CyclicBarrier barrier = new CyclicBarrier(THREAD_COUNT + 1);
|
||||
|
||||
int diff = new Random().nextInt(10000);
|
||||
|
||||
|
||||
public NoBindingMultithreadedInitializationTest2(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void testNoBindingMultiThreadedInitialization() throws InterruptedException, BrokenBarrierException {
|
||||
@SuppressWarnings("unused")
|
||||
LoggerAccessingThread2[] accessors = harness();
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(getClass().getName());
|
||||
logger.info("hello");
|
||||
eventCount.getAndIncrement();
|
||||
|
||||
assertAllSubstLoggersAreFixed();
|
||||
long recordedEventCount = getRecordedEventCount();
|
||||
int LENIENCY_COUNT = 16;
|
||||
|
||||
long expectedEventCount = eventCount.get() + extraLogEvents();
|
||||
|
||||
assertTrue(expectedEventCount + " >= " + recordedEventCount, expectedEventCount >= recordedEventCount);
|
||||
assertTrue(expectedEventCount + " < " + recordedEventCount + "+" + LENIENCY_COUNT,
|
||||
expectedEventCount < recordedEventCount + LENIENCY_COUNT);
|
||||
}
|
||||
|
||||
protected int extraLogEvents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void assertAllSubstLoggersAreFixed() {
|
||||
for (Logger logger : createdLoggers) {
|
||||
if (logger instanceof SubstituteLogger) {
|
||||
SubstituteLogger substLogger = (SubstituteLogger) logger;
|
||||
if (substLogger.delegate() instanceof EventRecodingLogger)
|
||||
fail("substLogger " + substLogger.getName() + " has a delegate of type EventRecodingLogger");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private LoggerAccessingThread2[] harness() throws InterruptedException, BrokenBarrierException {
|
||||
LoggerAccessingThread2[] threads = new LoggerAccessingThread2[THREAD_COUNT];
|
||||
for (int i = 0; i < THREAD_COUNT; i++) {
|
||||
threads[i] = new LoggerAccessingThread2(barrier, createdLoggers, i, eventCount);
|
||||
threads[i].start();
|
||||
}
|
||||
|
||||
// trigger barrier
|
||||
barrier.await();
|
||||
|
||||
for (int i = 0; i < THREAD_COUNT; i++) {
|
||||
threads[i].join();
|
||||
}
|
||||
|
||||
return threads;
|
||||
}
|
||||
|
||||
final String loggerName = this.getClass().getName();
|
||||
|
||||
protected long getRecordedEventCount() {
|
||||
return eventCount.get();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>1.7.25</version>
|
||||
<version>1.7.30</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
|
@ -16,6 +16,14 @@
|
|||
<description>JCL 1.2 implemented over SLF4J</description>
|
||||
<url>http://www.slf4j.org</url>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Apache License, Version 2.0</name>
|
||||
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
|
|
@ -28,4 +36,5 @@
|
|||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ Bundle-SymbolicName: jcl.over.slf4j
|
|||
Bundle-Name: jcl-over-slf4j
|
||||
Bundle-Vendor: SLF4J.ORG
|
||||
Bundle-RequiredExecutionEnvironment: J2SE-1.5
|
||||
Automatic-Module-Name: org.apache.commons.logging
|
||||
Export-Package: org.apache.commons.logging;version=1.2,
|
||||
org.apache.commons.logging.impl;version=1.2
|
||||
Import-Package: org.slf4j;version=${parsedVersion.osgiVersion}, org.slf4j.spi;version=${parsedVersion.osgiVersion}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>1.7.25</version>
|
||||
<version>1.7.30</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>jul-to-slf4j</artifactId>
|
||||
|
|
@ -30,5 +30,5 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>1.7.25</version>
|
||||
<version>1.7.30</version>
|
||||
</parent>
|
||||
|
||||
|
||||
|
|
@ -36,5 +36,5 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ Bundle-SymbolicName: log4j.over.slf4j
|
|||
Bundle-Name: log4j-over-slf4j
|
||||
Bundle-Vendor: SLF4J.ORG
|
||||
Bundle-RequiredExecutionEnvironment: J2SE-1.5
|
||||
Automatic-Module-Name: org.apache.log4j
|
||||
Export-Package: org.apache.log4j;version=${log4j.version},
|
||||
org.apache.log4j.helpers;version=${log4j.version},
|
||||
org.apache.log4j.spi;version=${log4j.version},
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>1.7.25</version>
|
||||
<version>1.7.30</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>osgi-over-slf4j</artifactId>
|
||||
|
|
@ -41,4 +41,6 @@
|
|||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
|
|
|
|||
43
pom.xml
43
pom.xml
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>1.7.25</version>
|
||||
<version>1.7.30</version>
|
||||
|
||||
<packaging>pom</packaging>
|
||||
<name>SLF4J</name>
|
||||
|
|
@ -46,7 +46,9 @@
|
|||
<logback.version>1.0.13</logback.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
<maven-site-plugin.version>3.3</maven-site-plugin.version>
|
||||
<javadoc.plugin.version>2.10.4</javadoc.plugin.version>
|
||||
<maven-source-plugin.version>3.0.1</maven-source-plugin.version>
|
||||
<javadoc.plugin.version>3.1.0</javadoc.plugin.version>
|
||||
<doclint>none</doclint>
|
||||
</properties>
|
||||
|
||||
<developers>
|
||||
|
|
@ -145,7 +147,7 @@
|
|||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</pluginManagement>
|
||||
|
||||
<plugins>
|
||||
|
||||
|
|
@ -177,7 +179,21 @@
|
|||
<skipIfEmpty>true</skipIfEmpty>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>${maven-source-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
|
|
@ -194,20 +210,6 @@
|
|||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.1.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
|
|
@ -262,6 +264,8 @@
|
|||
<version>${javadoc.plugin.version}</version>
|
||||
<configuration>
|
||||
<linksource>true</linksource>
|
||||
<doclint>none</doclint>
|
||||
|
||||
<!--<aggregate>true</aggregate>-->
|
||||
<excludePackageNames>org.slf4j.migrator:org.slf4j.migrator.*</excludePackageNames>
|
||||
<links>
|
||||
|
|
@ -323,6 +327,9 @@
|
|||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>${javadoc.plugin.version}</version>
|
||||
<configuration>
|
||||
<doclint>none</doclint>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
#mvn versions:set -DgenerateBackupPoms=false -DnewVersion=${VERSION_NUMBER}
|
||||
|
||||
MVN='/java/maven-3.5.2//bin/mvn'
|
||||
|
||||
PASS=$1
|
||||
echo $PASS
|
||||
|
||||
function checkExit(){
|
||||
if test "$?" != "0"; then
|
||||
echo Command $1 exited with abnormal status
|
||||
exit 1;
|
||||
else echo $?
|
||||
fi
|
||||
}
|
||||
|
||||
function echoThenRun () { # echo and then run the command
|
||||
echo $1
|
||||
$1
|
||||
ret=$?
|
||||
echo $ret
|
||||
return $ret
|
||||
}
|
||||
|
||||
$MVN clean
|
||||
checkExit "mvn clean"
|
||||
|
||||
|
||||
$MVN install
|
||||
checkExit "mvn install"
|
||||
|
||||
|
||||
$MVN site:site
|
||||
checkExit "mvn site:ste"
|
||||
|
||||
|
||||
$MVN assembly:single
|
||||
checkExit "mvn assembly:single"
|
||||
|
||||
|
||||
$MVN deploy -P javadocjar,sign-artifacts -Dgpg.passphrase=$PASS
|
||||
checkExit "mvn deploy -P javadocjar,sign-artifacts -Dgpg.passphrase=xxx"
|
||||
|
||||
#$MVN site:deploy -N # with Java 8!!!
|
||||
#checkExit "mvn site:deploy -N"
|
||||
|
||||
#git tag -m "tagging" -a v_${VERSION_NUMBER}
|
||||
#git push --tags
|
||||
|
||||
#release version and add next version on jira
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>1.7.25</version>
|
||||
<version>1.7.30</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>slf4j-android</artifactId>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>1.7.25</version>
|
||||
<version>1.7.30</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
|
|
@ -117,4 +117,4 @@
|
|||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -150,10 +150,6 @@ public final class LoggerFactory {
|
|||
StaticLoggerBinder.getSingleton();
|
||||
INITIALIZATION_STATE = SUCCESSFUL_INITIALIZATION;
|
||||
reportActualBinding(staticLoggerBinderPathSet);
|
||||
fixSubstituteLoggers();
|
||||
replayEvents();
|
||||
// release all resources in SUBST_FACTORY
|
||||
SUBST_FACTORY.clear();
|
||||
} catch (NoClassDefFoundError ncde) {
|
||||
String msg = ncde.getMessage();
|
||||
if (messageContainsOrgSlf4jImplStaticLoggerBinder(msg)) {
|
||||
|
|
@ -177,9 +173,18 @@ public final class LoggerFactory {
|
|||
} catch (Exception e) {
|
||||
failedBinding(e);
|
||||
throw new IllegalStateException("Unexpected initialization failure", e);
|
||||
} finally {
|
||||
postBindCleanUp();
|
||||
}
|
||||
}
|
||||
|
||||
private static void postBindCleanUp() {
|
||||
fixSubstituteLoggers();
|
||||
replayEvents();
|
||||
// release all resources in SUBST_FACTORY
|
||||
SUBST_FACTORY.clear();
|
||||
}
|
||||
|
||||
private static void fixSubstituteLoggers() {
|
||||
synchronized (SUBST_FACTORY) {
|
||||
SUBST_FACTORY.postInitialization();
|
||||
|
|
|
|||
|
|
@ -4,14 +4,28 @@ import java.util.Queue;
|
|||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.Marker;
|
||||
import org.slf4j.helpers.MessageFormatter;
|
||||
import org.slf4j.helpers.SubstituteLogger;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class is used to record events during the initialization phase of the
|
||||
* underlying logging framework. It is called by {@link SubstituteLogger}.
|
||||
*
|
||||
*
|
||||
* @author Ceki Gülcü
|
||||
* @author Wessel van Norel
|
||||
*
|
||||
*/
|
||||
public class EventRecodingLogger implements Logger {
|
||||
|
||||
String name;
|
||||
SubstituteLogger logger;
|
||||
Queue<SubstituteLoggingEvent> eventQueue;
|
||||
|
||||
// as an event recording logger we have no choice but to record all events
|
||||
final static boolean RECORD_ALL_EVENTS = true;
|
||||
|
||||
public EventRecodingLogger(SubstituteLogger logger, Queue<SubstituteLoggingEvent> eventQueue) {
|
||||
this.logger = logger;
|
||||
this.name = logger.getName();
|
||||
|
|
@ -22,12 +36,276 @@ public class EventRecodingLogger implements Logger {
|
|||
return name;
|
||||
}
|
||||
|
||||
private void recordEvent(Level level, String msg, Object[] args, Throwable throwable) {
|
||||
recordEvent(level, null, msg, args, throwable);
|
||||
public boolean isTraceEnabled() {
|
||||
return RECORD_ALL_EVENTS;
|
||||
}
|
||||
|
||||
public void trace(String msg) {
|
||||
recordEvent_0Args(Level.TRACE, null, msg, null);
|
||||
}
|
||||
|
||||
public void trace(String format, Object arg) {
|
||||
recordEvent_1Args(Level.TRACE, null, format, arg);
|
||||
}
|
||||
|
||||
public void trace(String format, Object arg1, Object arg2) {
|
||||
recordEvent2Args(Level.TRACE, null, format, arg1, arg2);
|
||||
}
|
||||
|
||||
public void trace(String format, Object... arguments) {
|
||||
recordEventArgArray(Level.TRACE, null, format, arguments);
|
||||
}
|
||||
|
||||
public void trace(String msg, Throwable t) {
|
||||
recordEvent_0Args(Level.TRACE, null, msg, t);
|
||||
}
|
||||
|
||||
public boolean isTraceEnabled(Marker marker) {
|
||||
return RECORD_ALL_EVENTS;
|
||||
}
|
||||
|
||||
public void trace(Marker marker, String msg) {
|
||||
recordEvent_0Args(Level.TRACE, marker, msg, null);
|
||||
}
|
||||
|
||||
public void trace(Marker marker, String format, Object arg) {
|
||||
recordEvent_1Args(Level.TRACE, marker, format, arg);
|
||||
}
|
||||
|
||||
public void trace(Marker marker, String format, Object arg1, Object arg2) {
|
||||
recordEvent2Args(Level.TRACE, marker, format, arg1, arg2);
|
||||
}
|
||||
|
||||
public void trace(Marker marker, String format, Object... argArray) {
|
||||
recordEventArgArray(Level.TRACE, marker, format, argArray);
|
||||
}
|
||||
|
||||
public void trace(Marker marker, String msg, Throwable t) {
|
||||
recordEvent_0Args(Level.TRACE, marker, msg, t);
|
||||
}
|
||||
|
||||
public boolean isDebugEnabled() {
|
||||
return RECORD_ALL_EVENTS;
|
||||
}
|
||||
|
||||
public void debug(String msg) {
|
||||
recordEvent_0Args(Level.DEBUG, null, msg, null);
|
||||
}
|
||||
|
||||
public void debug(String format, Object arg) {
|
||||
recordEvent_1Args(Level.DEBUG, null, format, arg);
|
||||
}
|
||||
|
||||
public void debug(String format, Object arg1, Object arg2) {
|
||||
recordEvent2Args(Level.DEBUG, null, format, arg1, arg2);
|
||||
}
|
||||
|
||||
public void debug(String format, Object... arguments) {
|
||||
recordEventArgArray(Level.DEBUG, null, format, arguments);
|
||||
}
|
||||
|
||||
public void debug(String msg, Throwable t) {
|
||||
recordEvent_0Args(Level.DEBUG, null, msg, t);
|
||||
}
|
||||
|
||||
public boolean isDebugEnabled(Marker marker) {
|
||||
return RECORD_ALL_EVENTS;
|
||||
}
|
||||
|
||||
public void debug(Marker marker, String msg) {
|
||||
recordEvent_0Args(Level.DEBUG, marker, msg, null);
|
||||
}
|
||||
|
||||
public void debug(Marker marker, String format, Object arg) {
|
||||
recordEvent_1Args(Level.DEBUG, marker, format, arg);
|
||||
}
|
||||
|
||||
public void debug(Marker marker, String format, Object arg1, Object arg2) {
|
||||
recordEvent2Args(Level.DEBUG, marker, format, arg1, arg2);
|
||||
}
|
||||
|
||||
public void debug(Marker marker, String format, Object... arguments) {
|
||||
recordEventArgArray(Level.DEBUG, marker, format, arguments);
|
||||
}
|
||||
|
||||
public void debug(Marker marker, String msg, Throwable t) {
|
||||
recordEvent_0Args(Level.DEBUG, marker, msg, t);
|
||||
}
|
||||
|
||||
public boolean isInfoEnabled() {
|
||||
return RECORD_ALL_EVENTS;
|
||||
}
|
||||
|
||||
public void info(String msg) {
|
||||
recordEvent_0Args(Level.INFO, null, msg, null);
|
||||
}
|
||||
|
||||
public void info(String format, Object arg) {
|
||||
recordEvent_1Args(Level.INFO, null, format, arg);
|
||||
}
|
||||
|
||||
public void info(String format, Object arg1, Object arg2) {
|
||||
recordEvent2Args(Level.INFO, null, format, arg1, arg2);
|
||||
}
|
||||
|
||||
public void info(String format, Object... arguments) {
|
||||
recordEventArgArray(Level.INFO, null, format, arguments);
|
||||
}
|
||||
|
||||
public void info(String msg, Throwable t) {
|
||||
recordEvent_0Args(Level.INFO, null, msg, t);
|
||||
}
|
||||
|
||||
public boolean isInfoEnabled(Marker marker) {
|
||||
return RECORD_ALL_EVENTS;
|
||||
}
|
||||
|
||||
public void info(Marker marker, String msg) {
|
||||
recordEvent_0Args(Level.INFO, marker, msg, null);
|
||||
}
|
||||
|
||||
public void info(Marker marker, String format, Object arg) {
|
||||
recordEvent_1Args(Level.INFO, marker, format, arg);
|
||||
}
|
||||
|
||||
public void info(Marker marker, String format, Object arg1, Object arg2) {
|
||||
recordEvent2Args(Level.INFO, marker, format, arg1, arg2);
|
||||
}
|
||||
|
||||
public void info(Marker marker, String format, Object... arguments) {
|
||||
recordEventArgArray(Level.INFO, marker, format, arguments);
|
||||
}
|
||||
|
||||
public void info(Marker marker, String msg, Throwable t) {
|
||||
recordEvent_0Args(Level.INFO, marker, msg, t);
|
||||
|
||||
}
|
||||
|
||||
public boolean isWarnEnabled() {
|
||||
return RECORD_ALL_EVENTS;
|
||||
}
|
||||
|
||||
public void warn(String msg) {
|
||||
recordEvent_0Args(Level.WARN, null, msg, null);
|
||||
}
|
||||
|
||||
public void warn(String format, Object arg) {
|
||||
recordEvent_1Args(Level.WARN, null, format, arg);
|
||||
}
|
||||
|
||||
public void warn(String format, Object arg1, Object arg2) {
|
||||
recordEvent2Args(Level.WARN, null, format, arg1, arg2);
|
||||
}
|
||||
|
||||
public void warn(String format, Object... arguments) {
|
||||
recordEventArgArray(Level.WARN, null, format, arguments);
|
||||
}
|
||||
|
||||
public void warn(String msg, Throwable t) {
|
||||
recordEvent_0Args(Level.WARN, null, msg, t);
|
||||
}
|
||||
|
||||
public boolean isWarnEnabled(Marker marker) {
|
||||
return RECORD_ALL_EVENTS;
|
||||
}
|
||||
|
||||
public void warn(Marker marker, String msg) {
|
||||
recordEvent_0Args(Level.WARN, marker, msg, null);
|
||||
}
|
||||
|
||||
public void warn(Marker marker, String format, Object arg) {
|
||||
recordEvent_1Args(Level.WARN, marker, format, arg);
|
||||
}
|
||||
|
||||
public void warn(Marker marker, String format, Object arg1, Object arg2) {
|
||||
recordEvent2Args(Level.WARN, marker, format, arg1, arg2);
|
||||
}
|
||||
|
||||
public void warn(Marker marker, String format, Object... arguments) {
|
||||
recordEventArgArray(Level.WARN, marker, format, arguments);
|
||||
}
|
||||
|
||||
public void warn(Marker marker, String msg, Throwable t) {
|
||||
recordEvent_0Args(Level.WARN, marker, msg, t);
|
||||
}
|
||||
|
||||
public boolean isErrorEnabled() {
|
||||
return RECORD_ALL_EVENTS;
|
||||
}
|
||||
|
||||
public void error(String msg) {
|
||||
recordEvent_0Args(Level.ERROR, null, msg, null);
|
||||
}
|
||||
|
||||
public void error(String format, Object arg) {
|
||||
recordEvent_1Args(Level.ERROR, null, format, arg);
|
||||
}
|
||||
|
||||
public void error(String format, Object arg1, Object arg2) {
|
||||
recordEvent2Args(Level.ERROR, null, format, arg1, arg2);
|
||||
}
|
||||
|
||||
public void error(String format, Object... arguments) {
|
||||
recordEventArgArray(Level.ERROR, null, format, arguments);
|
||||
}
|
||||
|
||||
public void error(String msg, Throwable t) {
|
||||
recordEvent_0Args(Level.ERROR, null, msg, t);
|
||||
}
|
||||
|
||||
public boolean isErrorEnabled(Marker marker) {
|
||||
return RECORD_ALL_EVENTS;
|
||||
}
|
||||
|
||||
public void error(Marker marker, String msg) {
|
||||
recordEvent_0Args(Level.ERROR, marker, msg, null);
|
||||
}
|
||||
|
||||
public void error(Marker marker, String format, Object arg) {
|
||||
recordEvent_1Args(Level.ERROR, marker, format, arg);
|
||||
}
|
||||
|
||||
public void error(Marker marker, String format, Object arg1, Object arg2) {
|
||||
recordEvent2Args(Level.ERROR, marker, format, arg1, arg2);
|
||||
}
|
||||
|
||||
public void error(Marker marker, String format, Object... arguments) {
|
||||
recordEventArgArray(Level.ERROR, marker, format, arguments);
|
||||
}
|
||||
|
||||
public void error(Marker marker, String msg, Throwable t) {
|
||||
recordEvent_0Args(Level.ERROR, marker, msg, t);
|
||||
}
|
||||
|
||||
private void recordEvent_0Args(Level level, Marker marker, String msg, Throwable t) {
|
||||
recordEvent(level, marker, msg, null, t);
|
||||
}
|
||||
|
||||
private void recordEvent_1Args(Level level, Marker marker, String msg, Object arg1) {
|
||||
recordEvent(level, marker, msg, new Object[] { arg1 }, null);
|
||||
}
|
||||
|
||||
private void recordEvent2Args(Level level, Marker marker, String msg, Object arg1, Object arg2) {
|
||||
if (arg2 instanceof Throwable) {
|
||||
recordEvent(level, marker, msg, new Object[] { arg1 }, (Throwable) arg2);
|
||||
} else {
|
||||
recordEvent(level, marker, msg, new Object[] { arg1, arg2 }, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void recordEventArgArray(Level level, Marker marker, String msg, Object[] args) {
|
||||
Throwable throwableCandidate = MessageFormatter.getThrowableCandidate(args);
|
||||
if (throwableCandidate != null) {
|
||||
Object[] trimmedCopy = MessageFormatter.trimmedCopy(args);
|
||||
recordEvent(level, marker, msg, trimmedCopy, throwableCandidate);
|
||||
} else {
|
||||
recordEvent(level, marker, msg, args, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// WARNING: this method assumes that any throwable is properly extracted
|
||||
private void recordEvent(Level level, Marker marker, String msg, Object[] args, Throwable throwable) {
|
||||
// System.out.println("recording logger:"+name+", msg:"+msg);
|
||||
SubstituteLoggingEvent loggingEvent = new SubstituteLoggingEvent();
|
||||
loggingEvent.setTimeStamp(System.currentTimeMillis());
|
||||
loggingEvent.setLevel(level);
|
||||
|
|
@ -35,262 +313,11 @@ public class EventRecodingLogger implements Logger {
|
|||
loggingEvent.setLoggerName(name);
|
||||
loggingEvent.setMarker(marker);
|
||||
loggingEvent.setMessage(msg);
|
||||
loggingEvent.setThreadName(Thread.currentThread().getName());
|
||||
|
||||
loggingEvent.setArgumentArray(args);
|
||||
loggingEvent.setThrowable(throwable);
|
||||
loggingEvent.setThreadName(Thread.currentThread().getName());
|
||||
|
||||
eventQueue.add(loggingEvent);
|
||||
}
|
||||
|
||||
public boolean isTraceEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void trace(String msg) {
|
||||
recordEvent(Level.TRACE, msg, null, null);
|
||||
}
|
||||
|
||||
public void trace(String format, Object arg) {
|
||||
recordEvent(Level.TRACE, format, new Object[] { arg }, null);
|
||||
}
|
||||
|
||||
public void trace(String format, Object arg1, Object arg2) {
|
||||
recordEvent(Level.TRACE, format, new Object[] { arg1, arg2 }, null);
|
||||
}
|
||||
|
||||
public void trace(String format, Object... arguments) {
|
||||
recordEvent(Level.TRACE, format, arguments, null);
|
||||
}
|
||||
|
||||
public void trace(String msg, Throwable t) {
|
||||
recordEvent(Level.TRACE, msg, null, t);
|
||||
}
|
||||
|
||||
public boolean isTraceEnabled(Marker marker) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void trace(Marker marker, String msg) {
|
||||
recordEvent(Level.TRACE, marker, msg, null, null);
|
||||
|
||||
}
|
||||
|
||||
public void trace(Marker marker, String format, Object arg) {
|
||||
recordEvent(Level.TRACE, marker, format, new Object[] { arg }, null);
|
||||
}
|
||||
|
||||
public void trace(Marker marker, String format, Object arg1, Object arg2) {
|
||||
recordEvent(Level.TRACE, marker, format, new Object[] { arg1, arg2 }, null);
|
||||
}
|
||||
|
||||
public void trace(Marker marker, String format, Object... argArray) {
|
||||
recordEvent(Level.TRACE, marker, format, argArray, null);
|
||||
|
||||
}
|
||||
|
||||
public void trace(Marker marker, String msg, Throwable t) {
|
||||
recordEvent(Level.TRACE, marker, msg, null, t);
|
||||
}
|
||||
|
||||
public boolean isDebugEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void debug(String msg) {
|
||||
recordEvent(Level.TRACE, msg, null, null);
|
||||
}
|
||||
|
||||
public void debug(String format, Object arg) {
|
||||
recordEvent(Level.DEBUG, format, new Object[] { arg }, null);
|
||||
|
||||
}
|
||||
|
||||
public void debug(String format, Object arg1, Object arg2) {
|
||||
recordEvent(Level.DEBUG, format, new Object[] { arg1, arg2 }, null);
|
||||
|
||||
}
|
||||
|
||||
public void debug(String format, Object... arguments) {
|
||||
recordEvent(Level.DEBUG, format, arguments, null);
|
||||
}
|
||||
|
||||
public void debug(String msg, Throwable t) {
|
||||
recordEvent(Level.DEBUG, msg, null, t);
|
||||
}
|
||||
|
||||
public boolean isDebugEnabled(Marker marker) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void debug(Marker marker, String msg) {
|
||||
recordEvent(Level.DEBUG, marker, msg, null, null);
|
||||
}
|
||||
|
||||
public void debug(Marker marker, String format, Object arg) {
|
||||
recordEvent(Level.DEBUG, marker, format, new Object[] { arg }, null);
|
||||
}
|
||||
|
||||
public void debug(Marker marker, String format, Object arg1, Object arg2) {
|
||||
recordEvent(Level.DEBUG, marker, format, new Object[] { arg1, arg2 }, null);
|
||||
}
|
||||
|
||||
public void debug(Marker marker, String format, Object... arguments) {
|
||||
recordEvent(Level.DEBUG, marker, format, arguments, null);
|
||||
}
|
||||
|
||||
public void debug(Marker marker, String msg, Throwable t) {
|
||||
recordEvent(Level.DEBUG, marker, msg, null, t);
|
||||
}
|
||||
|
||||
public boolean isInfoEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void info(String msg) {
|
||||
recordEvent(Level.INFO, msg, null, null);
|
||||
}
|
||||
|
||||
public void info(String format, Object arg) {
|
||||
recordEvent(Level.INFO, format, new Object[] { arg }, null);
|
||||
}
|
||||
|
||||
public void info(String format, Object arg1, Object arg2) {
|
||||
recordEvent(Level.INFO, format, new Object[] { arg1, arg2 }, null);
|
||||
}
|
||||
|
||||
public void info(String format, Object... arguments) {
|
||||
recordEvent(Level.INFO, format, arguments, null);
|
||||
}
|
||||
|
||||
public void info(String msg, Throwable t) {
|
||||
recordEvent(Level.INFO, msg, null, t);
|
||||
}
|
||||
|
||||
public boolean isInfoEnabled(Marker marker) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void info(Marker marker, String msg) {
|
||||
recordEvent(Level.INFO, marker, msg, null, null);
|
||||
}
|
||||
|
||||
public void info(Marker marker, String format, Object arg) {
|
||||
recordEvent(Level.INFO, marker, format, new Object[] { arg }, null);
|
||||
}
|
||||
|
||||
public void info(Marker marker, String format, Object arg1, Object arg2) {
|
||||
recordEvent(Level.INFO, marker, format, new Object[] { arg1, arg2 }, null);
|
||||
}
|
||||
|
||||
public void info(Marker marker, String format, Object... arguments) {
|
||||
recordEvent(Level.INFO, marker, format, arguments, null);
|
||||
}
|
||||
|
||||
public void info(Marker marker, String msg, Throwable t) {
|
||||
recordEvent(Level.INFO, marker, msg, null, t);
|
||||
|
||||
}
|
||||
|
||||
public boolean isWarnEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void warn(String msg) {
|
||||
recordEvent(Level.WARN, msg, null, null);
|
||||
}
|
||||
|
||||
public void warn(String format, Object arg) {
|
||||
recordEvent(Level.WARN, format, new Object[] { arg }, null);
|
||||
|
||||
}
|
||||
|
||||
public void warn(String format, Object arg1, Object arg2) {
|
||||
recordEvent(Level.WARN, format, new Object[] { arg1, arg2 }, null);
|
||||
}
|
||||
|
||||
public void warn(String format, Object... arguments) {
|
||||
recordEvent(Level.WARN, format, arguments, null);
|
||||
}
|
||||
|
||||
public void warn(String msg, Throwable t) {
|
||||
recordEvent(Level.WARN, msg, null, t);
|
||||
}
|
||||
|
||||
public boolean isWarnEnabled(Marker marker) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void warn(Marker marker, String msg) {
|
||||
recordEvent(Level.WARN, msg, null, null);
|
||||
}
|
||||
|
||||
public void warn(Marker marker, String format, Object arg) {
|
||||
recordEvent(Level.WARN, format, new Object[] { arg }, null);
|
||||
}
|
||||
|
||||
public void warn(Marker marker, String format, Object arg1, Object arg2) {
|
||||
recordEvent(Level.WARN, marker, format, new Object[] { arg1, arg2 }, null);
|
||||
|
||||
}
|
||||
|
||||
public void warn(Marker marker, String format, Object... arguments) {
|
||||
recordEvent(Level.WARN, marker, format, arguments, null);
|
||||
}
|
||||
|
||||
public void warn(Marker marker, String msg, Throwable t) {
|
||||
recordEvent(Level.WARN, marker, msg, null, t);
|
||||
}
|
||||
|
||||
public boolean isErrorEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void error(String msg) {
|
||||
recordEvent(Level.ERROR, msg, null, null);
|
||||
}
|
||||
|
||||
public void error(String format, Object arg) {
|
||||
recordEvent(Level.ERROR, format, new Object[] { arg }, null);
|
||||
|
||||
}
|
||||
|
||||
public void error(String format, Object arg1, Object arg2) {
|
||||
recordEvent(Level.ERROR, format, new Object[] { arg1, arg2 }, null);
|
||||
|
||||
}
|
||||
|
||||
public void error(String format, Object... arguments) {
|
||||
recordEvent(Level.ERROR, format, arguments, null);
|
||||
|
||||
}
|
||||
|
||||
public void error(String msg, Throwable t) {
|
||||
recordEvent(Level.ERROR, msg, null, t);
|
||||
}
|
||||
|
||||
public boolean isErrorEnabled(Marker marker) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void error(Marker marker, String msg) {
|
||||
recordEvent(Level.ERROR, marker, msg, null, null);
|
||||
|
||||
}
|
||||
|
||||
public void error(Marker marker, String format, Object arg) {
|
||||
recordEvent(Level.ERROR, marker, format, new Object[] { arg }, null);
|
||||
|
||||
}
|
||||
|
||||
public void error(Marker marker, String format, Object arg1, Object arg2) {
|
||||
recordEvent(Level.ERROR, marker, format, new Object[] { arg1, arg2 }, null);
|
||||
}
|
||||
|
||||
public void error(Marker marker, String format, Object... arguments) {
|
||||
recordEvent(Level.ERROR, marker, format, arguments, null);
|
||||
}
|
||||
|
||||
public void error(Marker marker, String msg, Throwable t) {
|
||||
recordEvent(Level.ERROR, marker, msg, null, t);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -152,37 +152,15 @@ final public class MessageFormatter {
|
|||
}
|
||||
|
||||
|
||||
static final Throwable getThrowableCandidate(Object[] argArray) {
|
||||
if (argArray == null || argArray.length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Object lastEntry = argArray[argArray.length - 1];
|
||||
if (lastEntry instanceof Throwable) {
|
||||
return (Throwable) lastEntry;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
final public static FormattingTuple arrayFormat(final String messagePattern, final Object[] argArray) {
|
||||
Throwable throwableCandidate = getThrowableCandidate(argArray);
|
||||
Throwable throwableCandidate = MessageFormatter.getThrowableCandidate(argArray);
|
||||
Object[] args = argArray;
|
||||
if (throwableCandidate != null) {
|
||||
args = trimmedCopy(argArray);
|
||||
args = MessageFormatter.trimmedCopy(argArray);
|
||||
}
|
||||
return arrayFormat(messagePattern, args, throwableCandidate);
|
||||
}
|
||||
|
||||
private static Object[] trimmedCopy(Object[] argArray) {
|
||||
if (argArray == null || argArray.length == 0) {
|
||||
throw new IllegalStateException("non-sensical empty or null argument array");
|
||||
}
|
||||
final int trimemdLen = argArray.length - 1;
|
||||
Object[] trimmed = new Object[trimemdLen];
|
||||
System.arraycopy(argArray, 0, trimmed, 0, trimemdLen);
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
final public static FormattingTuple arrayFormat(final String messagePattern, final Object[] argArray, Throwable throwable) {
|
||||
|
||||
if (messagePattern == null) {
|
||||
|
|
@ -411,4 +389,49 @@ final public class MessageFormatter {
|
|||
sbuf.append(']');
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to determine if an {@link Object} array contains a {@link Throwable} as last element
|
||||
*
|
||||
* @param argArray
|
||||
* The arguments off which we want to know if it contains a {@link Throwable} as last element
|
||||
* @return if the last {@link Object} in argArray is a {@link Throwable} this method will return it,
|
||||
* otherwise it returns null
|
||||
*/
|
||||
public static Throwable getThrowableCandidate(final Object[] argArray) {
|
||||
if (argArray == null || argArray.length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Object lastEntry = argArray[argArray.length - 1];
|
||||
if (lastEntry instanceof Throwable) {
|
||||
return (Throwable) lastEntry;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to get all but the last element of an array
|
||||
*
|
||||
* @param argArray
|
||||
* The arguments from which we want to remove the last element
|
||||
*
|
||||
* @return a copy of the array without the last element
|
||||
*/
|
||||
public static Object[] trimmedCopy(final Object[] argArray) {
|
||||
if (argArray == null || argArray.length == 0) {
|
||||
throw new IllegalStateException("non-sensical empty or null argument array");
|
||||
}
|
||||
|
||||
final int trimmedLen = argArray.length - 1;
|
||||
|
||||
Object[] trimmed = new Object[trimmedLen];
|
||||
|
||||
if (trimmedLen > 0) {
|
||||
System.arraycopy(argArray, 0, trimmed, 0, trimmedLen);
|
||||
}
|
||||
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ Bundle-SymbolicName: slf4j.api
|
|||
Bundle-Name: slf4j-api
|
||||
Bundle-Vendor: SLF4J.ORG
|
||||
Bundle-RequiredExecutionEnvironment: J2SE-1.5
|
||||
Automatic-Module-Name: org.slf4j
|
||||
Export-Package: org.slf4j;version=${parsedVersion.osgiVersion},
|
||||
org.slf4j.spi;version=${parsedVersion.osgiVersion},
|
||||
org.slf4j.helpers;version=${parsedVersion.osgiVersion},
|
||||
|
|
|
|||
|
|
@ -0,0 +1,525 @@
|
|||
package org.slf4j.event;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Marker;
|
||||
import org.slf4j.helpers.BasicMarkerFactory;
|
||||
import org.slf4j.helpers.SubstituteLogger;
|
||||
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class EventRecodingLoggerTest {
|
||||
private Queue<SubstituteLoggingEvent> queue;
|
||||
private EventRecodingLogger logger;
|
||||
private String message;
|
||||
private Object param1;
|
||||
private Object param2;
|
||||
private Object param3;
|
||||
private Object[] oneParam;
|
||||
private Object[] twoParams;
|
||||
private Object[] threeParams;
|
||||
private Throwable exception;
|
||||
private Marker marker;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
queue = new LinkedBlockingQueue<SubstituteLoggingEvent>();
|
||||
logger = new EventRecodingLogger(new SubstituteLogger("testLogger", queue, true), queue);
|
||||
message = "Test message with 3 parameters {} {} {} {}";
|
||||
param1 = 1;
|
||||
param2 = 2;
|
||||
param3 = 3;
|
||||
oneParam = new Object[] { param1 };
|
||||
twoParams = new Object[] { param1, param2 };
|
||||
threeParams = new Object[] { param1, param2, param3 };
|
||||
exception = new IllegalStateException("We just need an exception");
|
||||
marker = new BasicMarkerFactory().getMarker("testMarker");
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
assertTrue(queue.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleMessage() {
|
||||
for (Level level : Level.values()) {
|
||||
singleMessageCheck(level);
|
||||
}
|
||||
}
|
||||
|
||||
private void singleMessageCheck(Level level) {
|
||||
switch (level) {
|
||||
case TRACE:
|
||||
logger.trace(message);
|
||||
break;
|
||||
case DEBUG:
|
||||
logger.debug(message);
|
||||
break;
|
||||
case INFO:
|
||||
logger.info(message);
|
||||
break;
|
||||
case WARN:
|
||||
logger.warn(message);
|
||||
break;
|
||||
case ERROR:
|
||||
logger.error(message);
|
||||
break;
|
||||
}
|
||||
verifyMessageWithoutMarker(level, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneParameter() {
|
||||
for (Level level : Level.values()) {
|
||||
oneParameterCheck(level);
|
||||
}
|
||||
}
|
||||
private void oneParameterCheck(Level level) {
|
||||
switch (level) {
|
||||
case TRACE:
|
||||
logger.trace(message, param1);
|
||||
break;
|
||||
case DEBUG:
|
||||
logger.debug(message, param1);
|
||||
break;
|
||||
case INFO:
|
||||
logger.info(message, param1);
|
||||
break;
|
||||
case WARN:
|
||||
logger.warn(message, param1);
|
||||
break;
|
||||
case ERROR:
|
||||
logger.error(message, param1);
|
||||
break;
|
||||
}
|
||||
verifyMessageWithoutMarker(level, oneParam, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void messageTwoParameters() {
|
||||
for (Level level : Level.values()) {
|
||||
messageTwoParametersCheck(level);
|
||||
}
|
||||
}
|
||||
|
||||
private void messageTwoParametersCheck(Level level) {
|
||||
switch (level) {
|
||||
case TRACE:
|
||||
logger.trace(message, param1, param2);
|
||||
break;
|
||||
case DEBUG:
|
||||
logger.debug(message, param1, param2);
|
||||
break;
|
||||
case INFO:
|
||||
logger.info(message, param1, param2);
|
||||
break;
|
||||
case WARN:
|
||||
logger.warn(message, param1, param2);
|
||||
break;
|
||||
case ERROR:
|
||||
logger.error(message, param1, param2);
|
||||
break;
|
||||
}
|
||||
verifyMessageWithoutMarker(level, twoParams, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void traceMessageThreeParameters() {
|
||||
for (Level level : Level.values()) {
|
||||
threeParameterCheck(level);
|
||||
}
|
||||
}
|
||||
|
||||
private void threeParameterCheck(Level level) {
|
||||
switch (level) {
|
||||
case TRACE:
|
||||
logger.trace(message, param1, param2, param3);
|
||||
break;
|
||||
case DEBUG:
|
||||
logger.debug(message, param1, param2, param3);
|
||||
break;
|
||||
case INFO:
|
||||
logger.info(message, param1, param2, param3);
|
||||
break;
|
||||
case WARN:
|
||||
logger.warn(message, param1, param2, param3);
|
||||
break;
|
||||
case ERROR:
|
||||
logger.error(message, param1, param2, param3);
|
||||
break;
|
||||
}
|
||||
verifyMessageWithoutMarker(level, threeParams, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageThrowable() {
|
||||
for (Level level : Level.values()) {
|
||||
throwableCheck(level);
|
||||
}
|
||||
}
|
||||
|
||||
private void throwableCheck(Level level) {
|
||||
switch (level) {
|
||||
case TRACE:
|
||||
logger.trace(message, exception);
|
||||
break;
|
||||
case DEBUG:
|
||||
logger.debug(message, exception);
|
||||
break;
|
||||
case INFO:
|
||||
logger.info(message, exception);
|
||||
break;
|
||||
case WARN:
|
||||
logger.warn(message, exception);
|
||||
break;
|
||||
case ERROR:
|
||||
logger.error(message, exception);
|
||||
break;
|
||||
}
|
||||
verifyMessageWithoutMarker(level, null, exception);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void traceMessageOneParameterThrowable() {
|
||||
for (Level level : Level.values()) {
|
||||
oneParamThrowableCheck(level);
|
||||
}
|
||||
}
|
||||
|
||||
private void oneParamThrowableCheck(Level level) {
|
||||
switch (level) {
|
||||
case TRACE:
|
||||
logger.trace(message, param1, exception);
|
||||
break;
|
||||
case DEBUG:
|
||||
logger.debug(message, param1, exception);
|
||||
break;
|
||||
case INFO:
|
||||
logger.info(message, param1, exception);
|
||||
break;
|
||||
case WARN:
|
||||
logger.warn(message, param1, exception);
|
||||
break;
|
||||
case ERROR:
|
||||
logger.error(message, param1, exception);
|
||||
break;
|
||||
}
|
||||
verifyMessageWithoutMarker(level, oneParam, exception);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void traceMessageTwoParametersThrowable() {
|
||||
for (Level level : Level.values()) {
|
||||
twoParamThrowableCheck(level);
|
||||
}
|
||||
}
|
||||
|
||||
private void twoParamThrowableCheck(Level level) {
|
||||
switch (level) {
|
||||
case TRACE:
|
||||
logger.trace(message, param1, param2, exception);
|
||||
break;
|
||||
case DEBUG:
|
||||
logger.debug(message, param1, param2, exception);
|
||||
break;
|
||||
case INFO:
|
||||
logger.info(message, param1, param2, exception);
|
||||
break;
|
||||
case WARN:
|
||||
logger.warn(message, param1, param2, exception);
|
||||
break;
|
||||
case ERROR:
|
||||
logger.error(message, param1, param2, exception);
|
||||
break;
|
||||
}
|
||||
verifyMessageWithoutMarker(level, twoParams, exception);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageThreeParametersThrowable() {
|
||||
for (Level level : Level.values()) {
|
||||
messageWith3ArgsPlusException(level);
|
||||
}
|
||||
}
|
||||
|
||||
private void messageWith3ArgsPlusException(Level level) {
|
||||
switch (level) {
|
||||
case TRACE:
|
||||
logger.trace(message, param1, param2, param3, exception);
|
||||
break;
|
||||
case DEBUG:
|
||||
logger.debug(message, param1, param2, param3, exception);
|
||||
break;
|
||||
case INFO:
|
||||
logger.info(message, param1, param2, param3, exception);
|
||||
break;
|
||||
case WARN:
|
||||
logger.warn(message, param1, param2, param3, exception);
|
||||
break;
|
||||
case ERROR:
|
||||
logger.error(message, param1, param2, param3, exception);
|
||||
break;
|
||||
}
|
||||
verifyMessageWithoutMarker(level, threeParams, exception);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void markerMessage() {
|
||||
for (Level level : Level.values()) {
|
||||
markerMessageCheck(level);
|
||||
}
|
||||
}
|
||||
private void markerMessageCheck(Level level) {
|
||||
switch (level) {
|
||||
case TRACE:
|
||||
logger.trace(marker, message);
|
||||
break;
|
||||
case DEBUG:
|
||||
logger.debug(marker, message);
|
||||
break;
|
||||
case INFO:
|
||||
logger.info(marker, message);
|
||||
break;
|
||||
case WARN:
|
||||
logger.warn(marker, message);
|
||||
break;
|
||||
case ERROR:
|
||||
logger.error(marker, message);
|
||||
break;
|
||||
}
|
||||
verifyMessage(level, marker, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void markerMessageOneParameter() {
|
||||
for (Level level : Level.values()) {
|
||||
markerMessageOneParameter(level);
|
||||
}
|
||||
}
|
||||
private void markerMessageOneParameter(Level level) {
|
||||
switch (level) {
|
||||
case TRACE:
|
||||
logger.trace(marker, message, param1);
|
||||
break;
|
||||
case DEBUG:
|
||||
logger.debug(marker, message, param1);
|
||||
break;
|
||||
case INFO:
|
||||
logger.info(marker, message, param1);
|
||||
break;
|
||||
case WARN:
|
||||
logger.warn(marker, message, param1);
|
||||
break;
|
||||
case ERROR:
|
||||
logger.error(marker, message, param1);
|
||||
break;
|
||||
}
|
||||
verifyMessage(level, marker, oneParam, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void traceMarkerMessageTwoParameters() {
|
||||
for (Level level : Level.values()) {
|
||||
markerMessageTwoParameters(level);
|
||||
}
|
||||
}
|
||||
|
||||
private void markerMessageTwoParameters(Level level) {
|
||||
switch (level) {
|
||||
case TRACE:
|
||||
logger.trace(marker, message, param1, param2);
|
||||
break;
|
||||
case DEBUG:
|
||||
logger.debug(marker, message, param1, param2);
|
||||
break;
|
||||
case INFO:
|
||||
logger.info(marker, message, param1, param2);
|
||||
break;
|
||||
case WARN:
|
||||
logger.warn(marker, message, param1, param2);
|
||||
break;
|
||||
case ERROR:
|
||||
logger.error(marker, message, param1, param2);
|
||||
break;
|
||||
}
|
||||
verifyMessage(level, marker, twoParams, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void traceMarkerMessageThreeParameters() {
|
||||
for (Level level : Level.values()) {
|
||||
markerMessageThreeParameters(level);
|
||||
}
|
||||
}
|
||||
|
||||
private void markerMessageThreeParameters(Level level) {
|
||||
switch (level) {
|
||||
case TRACE:
|
||||
logger.trace(marker, message, param1, param2, param3);
|
||||
break;
|
||||
case DEBUG:
|
||||
logger.debug(marker, message, param1, param2, param3);
|
||||
break;
|
||||
case INFO:
|
||||
logger.info(marker, message, param1, param2, param3);
|
||||
break;
|
||||
case WARN:
|
||||
logger.warn(marker, message, param1, param2, param3);
|
||||
break;
|
||||
case ERROR:
|
||||
logger.error(marker, message, param1, param2, param3);
|
||||
break;
|
||||
}
|
||||
verifyMessage(level, marker, threeParams, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void markerMessageThrowable() {
|
||||
for (Level level : Level.values()) {
|
||||
markerMessageThrowable(level);
|
||||
}
|
||||
}
|
||||
|
||||
private void markerMessageThrowable(Level level) {
|
||||
switch (level) {
|
||||
case TRACE:
|
||||
logger.trace(marker, message, exception);
|
||||
break;
|
||||
case DEBUG:
|
||||
logger.debug(marker, message, exception);
|
||||
break;
|
||||
case INFO:
|
||||
logger.info(marker, message, exception);
|
||||
break;
|
||||
case WARN:
|
||||
logger.warn(marker, message, exception);
|
||||
break;
|
||||
case ERROR:
|
||||
logger.error(marker, message, exception);
|
||||
break;
|
||||
}
|
||||
verifyMessage(level, marker, null, exception);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void markerMessageOneParameterThrowable() {
|
||||
for (Level level : Level.values()) {
|
||||
markerMessageOneParameterThrowableCheck(level);
|
||||
}
|
||||
}
|
||||
|
||||
private void markerMessageOneParameterThrowableCheck(Level level) {
|
||||
switch (level) {
|
||||
case TRACE:
|
||||
logger.trace(marker, message, param1, exception);
|
||||
break;
|
||||
case DEBUG:
|
||||
logger.debug(marker, message, param1, exception);
|
||||
break;
|
||||
case INFO:
|
||||
logger.info(marker, message, param1, exception);
|
||||
break;
|
||||
case WARN:
|
||||
logger.warn(marker, message, param1, exception);
|
||||
break;
|
||||
case ERROR:
|
||||
logger.error(marker, message, param1, exception);
|
||||
break;
|
||||
}
|
||||
verifyMessage(level, marker, oneParam, exception);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void traceMarkerMessageTwoParametersThrowable() {
|
||||
for (Level level : Level.values()) {
|
||||
markerMessageTwoParametersThrowableCheck(level);
|
||||
}
|
||||
}
|
||||
|
||||
private void markerMessageTwoParametersThrowableCheck(Level level) {
|
||||
switch (level) {
|
||||
case TRACE:
|
||||
logger.trace(marker, message, param1, param2, exception);
|
||||
break;
|
||||
case DEBUG:
|
||||
logger.debug(marker, message, param1, param2, exception);
|
||||
break;
|
||||
case INFO:
|
||||
logger.info(marker, message, param1, param2, exception);
|
||||
break;
|
||||
case WARN:
|
||||
logger.warn(marker, message, param1, param2, exception);
|
||||
break;
|
||||
case ERROR:
|
||||
logger.error(marker, message, param1, param2, exception);
|
||||
break;
|
||||
}
|
||||
verifyMessage(level, marker, twoParams, exception);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void traceMarkerMessageThreeParametersThrowable() {
|
||||
for (Level level : Level.values()) {
|
||||
markerMessageThreeParametersThrowableCheck(level);
|
||||
}
|
||||
}
|
||||
|
||||
private void markerMessageThreeParametersThrowableCheck(Level level) {
|
||||
switch (level) {
|
||||
case TRACE:
|
||||
logger.trace(marker, message, param1, param2, param3, exception);
|
||||
break;
|
||||
case DEBUG:
|
||||
logger.debug(marker, message, param1, param2, param3, exception);
|
||||
break;
|
||||
case INFO:
|
||||
logger.info(marker, message, param1, param2, param3, exception);
|
||||
break;
|
||||
case WARN:
|
||||
logger.warn(marker, message, param1, param2, param3, exception);
|
||||
break;
|
||||
case ERROR:
|
||||
logger.error(marker, message, param1, param2, param3, exception);
|
||||
break;
|
||||
}
|
||||
verifyMessage(level, marker, threeParams, exception);
|
||||
}
|
||||
|
||||
private void verifyMessageWithoutMarker(Level level, Object[] arguments, Throwable exception) {
|
||||
verifyMessage(level, null, arguments, exception);
|
||||
}
|
||||
|
||||
private void verifyMessage(Level level, Marker marker, Object[] arguments, Throwable exception) {
|
||||
|
||||
assertEquals("missing event: ", 1, queue.size());
|
||||
SubstituteLoggingEvent event = queue.poll();
|
||||
assertNotNull(event);
|
||||
|
||||
if (marker == null) {
|
||||
assertNull(event.getMarker());
|
||||
} else {
|
||||
assertEquals(marker, event.getMarker());
|
||||
}
|
||||
|
||||
assertEquals(message, event.getMessage());
|
||||
|
||||
if (arguments == null) {
|
||||
assertNull(event.getArgumentArray());
|
||||
} else {
|
||||
assertArrayEquals(arguments, event.getArgumentArray());
|
||||
}
|
||||
|
||||
assertEquals("wrong level: ", level, event.getLevel());
|
||||
|
||||
if (exception == null) {
|
||||
assertNull(event.getThrowable());
|
||||
} else {
|
||||
assertEquals(exception, event.getThrowable());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -22,7 +22,7 @@ abstract public class MultithreadedInitializationTest {
|
|||
|
||||
private final List<Logger> createdLoggers = Collections.synchronizedList(new ArrayList<Logger>());
|
||||
|
||||
final private AtomicLong eventCount = new AtomicLong(0);
|
||||
protected final AtomicLong eventCount = new AtomicLong(0);
|
||||
final private CyclicBarrier barrier = new CyclicBarrier(THREAD_COUNT + 1);
|
||||
|
||||
int diff = new Random().nextInt(10000);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>1.7.25</version>
|
||||
<version>1.7.30</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>slf4j-ext</artifactId>
|
||||
|
|
|
|||
|
|
@ -1,305 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2004-2011 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.
|
||||
*
|
||||
*/
|
||||
package org.slf4j.ext;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.beans.XMLDecoder;
|
||||
import java.beans.XMLEncoder;
|
||||
import java.beans.ExceptionListener;
|
||||
|
||||
/**
|
||||
* Base class for Event Data. Event Data contains data to be logged about an
|
||||
* event. Users may extend this class for each EventType they want to log.
|
||||
*
|
||||
* @author Ralph Goers
|
||||
*/
|
||||
public class EventData implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 153270778642103985L;
|
||||
|
||||
private Map<String, Object> eventData = new HashMap<String, Object>();
|
||||
public static final String EVENT_MESSAGE = "EventMessage";
|
||||
public static final String EVENT_TYPE = "EventType";
|
||||
public static final String EVENT_DATETIME = "EventDateTime";
|
||||
public static final String EVENT_ID = "EventId";
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
public EventData() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor to create event data from a Map.
|
||||
*
|
||||
* @param map
|
||||
* The event data.
|
||||
*/
|
||||
public EventData(Map<String, Object> map) {
|
||||
eventData.putAll(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct from a serialized form of the Map containing the RequestInfo
|
||||
* elements
|
||||
*
|
||||
* @param xml
|
||||
* The serialized form of the RequestInfo Map.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public EventData(String xml) {
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
|
||||
try {
|
||||
XMLDecoder decoder = new XMLDecoder(bais);
|
||||
this.eventData = (Map<String, Object>) decoder.readObject();
|
||||
} catch (Exception e) {
|
||||
throw new EventException("Error decoding " + xml, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize all the EventData items into an XML representation.
|
||||
*
|
||||
* @return an XML String containing all the EventData items.
|
||||
*/
|
||||
public String toXML() {
|
||||
return toXML(eventData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize all the EventData items into an XML representation.
|
||||
*
|
||||
* @param map the Map to transform
|
||||
* @return an XML String containing all the EventData items.
|
||||
*/
|
||||
public static String toXML(Map<String, Object> map) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try {
|
||||
XMLEncoder encoder = new XMLEncoder(baos);
|
||||
encoder.setExceptionListener(new ExceptionListener() {
|
||||
public void exceptionThrown(Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
});
|
||||
encoder.writeObject(map);
|
||||
encoder.close();
|
||||
return baos.toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the event identifier.
|
||||
*
|
||||
* @return The event identifier
|
||||
*/
|
||||
public String getEventId() {
|
||||
return (String) this.eventData.get(EVENT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the event identifier.
|
||||
*
|
||||
* @param eventId
|
||||
* The event identifier.
|
||||
*/
|
||||
public void setEventId(String eventId) {
|
||||
if (eventId == null) {
|
||||
throw new IllegalArgumentException("eventId cannot be null");
|
||||
}
|
||||
this.eventData.put(EVENT_ID, eventId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the message text associated with this event, if any.
|
||||
*
|
||||
* @return The message text associated with this event or null if there is
|
||||
* none.
|
||||
*/
|
||||
public String getMessage() {
|
||||
return (String) this.eventData.get(EVENT_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the message text associated with this event.
|
||||
*
|
||||
* @param message
|
||||
* The message text.
|
||||
*/
|
||||
public void setMessage(String message) {
|
||||
this.eventData.put(EVENT_MESSAGE, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the date and time the event occurred.
|
||||
*
|
||||
* @return The Date associated with the event.
|
||||
*/
|
||||
public Date getEventDateTime() {
|
||||
return (Date) this.eventData.get(EVENT_DATETIME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the date and time the event occurred in case it is not the same as when
|
||||
* the event was logged.
|
||||
*
|
||||
* @param eventDateTime
|
||||
* The event Date.
|
||||
*/
|
||||
public void setEventDateTime(Date eventDateTime) {
|
||||
this.eventData.put(EVENT_DATETIME, eventDateTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the type of event that occurred.
|
||||
*
|
||||
* @param eventType
|
||||
* The type of the event.
|
||||
*/
|
||||
public void setEventType(String eventType) {
|
||||
this.eventData.put(EVENT_TYPE, eventType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the type of the event.
|
||||
*
|
||||
* @return The event type.
|
||||
*/
|
||||
public String getEventType() {
|
||||
return (String) this.eventData.get(EVENT_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add arbitrary attributes about the event.
|
||||
*
|
||||
* @param name
|
||||
* The attribute's key.
|
||||
* @param obj
|
||||
* The data associated with the key.
|
||||
*/
|
||||
public void put(String name, Serializable obj) {
|
||||
this.eventData.put(name, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an event attribute.
|
||||
*
|
||||
* @param name
|
||||
* The attribute's key.
|
||||
* @return The value associated with the key or null if the key is not
|
||||
* present.
|
||||
*/
|
||||
public Serializable get(String name) {
|
||||
return (Serializable) this.eventData.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate the event data from a Map.
|
||||
*
|
||||
* @param data
|
||||
* The Map to copy.
|
||||
*/
|
||||
public void putAll(Map<String, Object> data) {
|
||||
this.eventData.putAll(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of attributes in the EventData.
|
||||
*
|
||||
* @return the number of attributes in the EventData.
|
||||
*/
|
||||
public int getSize() {
|
||||
return this.eventData.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Iterator over all the entries in the EventData.
|
||||
*
|
||||
* @return an Iterator that can be used to access all the event attributes.
|
||||
*/
|
||||
public Iterator<Map.Entry<String, Object>> getEntrySetIterator() {
|
||||
return this.eventData.entrySet().iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all the attributes in the EventData as a Map. Changes to this map
|
||||
* will be reflected in the EventData.
|
||||
*
|
||||
* @return The Map of attributes in this EventData instance.
|
||||
*/
|
||||
public Map<String, Object> getEventMap() {
|
||||
return this.eventData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the EventData to a String.
|
||||
*
|
||||
* @return The EventData as a String.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return toXML();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two EventData objects for equality.
|
||||
*
|
||||
* @param o
|
||||
* The Object to compare.
|
||||
* @return true if the objects are the same instance or contain all the same
|
||||
* keys and their values.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof EventData || o instanceof Map)) {
|
||||
return false;
|
||||
}
|
||||
Map<String, Object> map = (o instanceof EventData) ? ((EventData) o).getEventMap() : (Map<String, Object>) o;
|
||||
|
||||
return this.eventData.equals(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the hashCode for this EventData instance.
|
||||
*
|
||||
* @return The hashcode for this EventData instance.
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.eventData.hashCode();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2004-2011 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.
|
||||
*
|
||||
*/
|
||||
package org.slf4j.ext;
|
||||
|
||||
/**
|
||||
* Exception used to identify issues related to an event that is being logged.
|
||||
*/
|
||||
public class EventException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = -22873966112391992L;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public EventException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that allows an exception message.
|
||||
* @param exceptionMessage The exception message.
|
||||
*/
|
||||
public EventException(String exceptionMessage) {
|
||||
super(exceptionMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that chains another Exception or Error.
|
||||
* @param originalException The original exception.
|
||||
*/
|
||||
public EventException(Throwable originalException) {
|
||||
super(originalException);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that chains another Exception or Error and also allows a message
|
||||
* to be specified.
|
||||
* @param exceptionMessage The exception message.
|
||||
* @param originalException The original exception.
|
||||
*/
|
||||
public EventException(String exceptionMessage, Throwable originalException) {
|
||||
super(exceptionMessage, originalException);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,106 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2004-2011 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.
|
||||
*
|
||||
*/
|
||||
package org.slf4j.dummyExt;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.apache.log4j.spi.LocationInfo;
|
||||
import org.apache.log4j.spi.LoggingEvent;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.MDC;
|
||||
import org.slf4j.ext.EventData;
|
||||
import org.slf4j.ext.EventLogger;
|
||||
|
||||
public class EventLoggerTest {
|
||||
|
||||
ListAppender listAppender;
|
||||
org.apache.log4j.Logger log4;
|
||||
|
||||
final static String EXPECTED_FILE_NAME = "EventLoggerTest.java";
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
// start from a clean slate for each test
|
||||
|
||||
listAppender = new ListAppender();
|
||||
listAppender.extractLocationInfo = true;
|
||||
org.apache.log4j.Logger eventLogger = org.apache.log4j.Logger.getLogger("EventLogger");
|
||||
eventLogger.addAppender(listAppender);
|
||||
eventLogger.setLevel(org.apache.log4j.Level.TRACE);
|
||||
eventLogger.setAdditivity(false);
|
||||
// Items that apply to any activity
|
||||
MDC.put("ipAddress", "192.168.1.110");
|
||||
MDC.put("login", "TestUSer");
|
||||
MDC.put("hostname", "localhost");
|
||||
MDC.put("productName", "SLF4J");
|
||||
MDC.put("locale", Locale.getDefault().getDisplayName());
|
||||
MDC.put("timezone", TimeZone.getDefault().getDisplayName());
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
MDC.clear();
|
||||
}
|
||||
|
||||
void verify(LoggingEvent le, String expectedMsg) {
|
||||
assertEquals(expectedMsg, le.getMessage());
|
||||
assertEquals(EXPECTED_FILE_NAME, le.getLocationInformation().getFileName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEventLogger() {
|
||||
EventData data[] = new EventData[2];
|
||||
data[0] = new EventData();
|
||||
data[0].setEventType("Login");
|
||||
data[0].setEventId("1");
|
||||
data[0].setEventDateTime(new Date());
|
||||
data[0].put("Userid", "TestUser");
|
||||
EventLogger.logEvent(data[0]);
|
||||
|
||||
data[1] = new EventData();
|
||||
data[1].setEventType("Update");
|
||||
data[1].setEventId("2");
|
||||
data[1].setEventDateTime(new Date());
|
||||
data[1].put("FileName", "/etc/hosts");
|
||||
EventLogger.logEvent(data[1]);
|
||||
|
||||
assertEquals(2, listAppender.list.size());
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
LoggingEvent event = listAppender.list.get(i);
|
||||
verify(event, data[i].toXML());
|
||||
LocationInfo li = event.getLocationInformation();
|
||||
assertEquals(this.getClass().getName(), li.getClassName());
|
||||
assertEquals(event.getMDC("hostname"), "localhost");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -29,6 +29,6 @@ import org.junit.runners.Suite;
|
|||
import org.junit.runners.Suite.SuiteClasses;
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({ MDCStrLookupTest.class, XLoggerTest.class, EventLoggerTest.class })
|
||||
@SuiteClasses({ MDCStrLookupTest.class, XLoggerTest.class })
|
||||
public class PackageTest {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>1.7.25</version>
|
||||
<version>1.7.30</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>slf4j-jcl</artifactId>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>1.7.25</version>
|
||||
<version>1.7.30</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>slf4j-jdk14</artifactId>
|
||||
|
|
@ -31,4 +31,5 @@
|
|||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ Bundle-SymbolicName: slf4j.jdk14
|
|||
Bundle-Name: slf4j-jdk14
|
||||
Bundle-Vendor: SLF4J.ORG
|
||||
Bundle-RequiredExecutionEnvironment: J2SE-1.5
|
||||
Automatic-Module-Name: org.slf4j.jul
|
||||
Export-Package: org.slf4j.impl;version=${parsedVersion.osgiVersion}
|
||||
Import-Package: org.slf4j;version=${parsedVersion.osgiVersion},
|
||||
org.slf4j.spi;version=${parsedVersion.osgiVersion},
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>1.7.25</version>
|
||||
<version>1.7.30</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
|
|
@ -37,4 +37,5 @@
|
|||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>1.7.25</version>
|
||||
<version>1.7.30</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>slf4j-migrator</artifactId>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>1.7.25</version>
|
||||
<version>1.7.30</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>slf4j-nop</artifactId>
|
||||
|
|
@ -24,4 +24,5 @@
|
|||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ Bundle-SymbolicName: slf4j.nop
|
|||
Bundle-Name: slf4j-nop
|
||||
Bundle-Vendor: SLF4J.ORG
|
||||
Bundle-RequiredExecutionEnvironment: J2SE-1.5
|
||||
Automatic-Module-Name: org.slf4j.nop
|
||||
Export-Package: org.slf4j.impl;version=${parsedVersion.osgiVersion}
|
||||
Import-Package: org.slf4j;version=${parsedVersion.osgiVersion},
|
||||
org.slf4j.spi;version=${parsedVersion.osgiVersion},
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>1.7.25</version>
|
||||
<version>1.7.30</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
|
|
@ -31,4 +31,5 @@
|
|||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ Bundle-Name: slf4j-simple
|
|||
Bundle-Vendor: SLF4J.ORG
|
||||
Require-Bundle: slf4j.api
|
||||
Bundle-RequiredExecutionEnvironment: J2SE-1.5
|
||||
Automatic-Module-Name: org.slf4j.simple
|
||||
Export-Package: org.slf4j.impl;version=${parsedVersion.osgiVersion}
|
||||
Import-Package: org.slf4j;version=${parsedVersion.osgiVersion},
|
||||
org.slf4j.spi;version=${parsedVersion.osgiVersion},
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>1.7.25</version>
|
||||
<version>1.7.30</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>slf4j-site</artifactId>
|
||||
|
|
@ -30,6 +30,37 @@
|
|||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>${maven-source-plugin.version}</version>
|
||||
<configuration>
|
||||
<includes>
|
||||
<include>**/META-INF/*</include>
|
||||
</includes>
|
||||
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
|
|
@ -41,4 +72,4 @@
|
|||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@
|
|||
|
||||
<ul>
|
||||
<li><a
|
||||
href="http://jira.qos.ch/issues/?jql=project%20%3D%20SLF4J">Search for
|
||||
href="https://jira.qos.ch/issues/?jql=project%3DSLF4J">Search for
|
||||
SLF4J bugs</a></li>
|
||||
</ul>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue