Skip to content

Commit

Permalink
ongoing work on jigsaw modularization
Browse files Browse the repository at this point in the history
  • Loading branch information
ceki committed Dec 2, 2017
1 parent 0e25744 commit e59b6d6
Show file tree
Hide file tree
Showing 21 changed files with 69 additions and 303 deletions.
13 changes: 10 additions & 3 deletions logback-classic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,16 @@
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<artifactId>groovy-all</artifactId>
<scope>compile</scope>
<!--<optional>true</optional>-->
<optional>true</optional>
</dependency>
<!-- <dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-test</artifactId>
<scope>test</scope>
</dependency>
-->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
Expand Down Expand Up @@ -235,6 +241,7 @@
</dependencies>

<executions>
<!--
<execution>
<id>ant-osgi-test</id>
<phase>package</phase>
Expand All @@ -250,7 +257,7 @@
<goal>run</goal>
</goals>
</execution>

-->
<execution>
<id>ant-integration-test</id>
<phase>package</phase>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ch.qos.logback.classic.provider;
package ch.qos.logback.classic.spi;

import org.slf4j.ILoggerFactory;
import org.slf4j.IMarkerFactory;
Expand Down Expand Up @@ -27,29 +27,35 @@ public class LogbackServiceProvider implements SLF4JServiceProvider {
// to avoid constant folding by the compiler, this field must *not* be final
public static String REQUESTED_API_VERSION = "1.8.99"; // !final

private LoggerContext loggerFactory;
private LoggerContext defaultLoggerContext;
private IMarkerFactory markerFactory;
private MDCAdapter mdcAdapter;

private final ContextSelectorStaticBinder contextSelectorBinder = ContextSelectorStaticBinder.getSingleton();
private static Object KEY = new Object();
private boolean initialized = false;

@Override
public void initialize() {
loggerFactory = new LoggerContext();
initializeLoggerContext(loggerFactory);
defaultLoggerContext = new LoggerContext();
defaultLoggerContext.setName(CoreConstants.DEFAULT_CONTEXT_NAME);
initializeLoggerContext();
markerFactory = new BasicMarkerFactory();
mdcAdapter = new LogbackMDCAdapter();
}

private void initializeLoggerContext(LoggerContext loggerFactory) {
private void initializeLoggerContext() {
try {
try {
new ContextInitializer(loggerFactory).autoConfig();
new ContextInitializer(defaultLoggerContext).autoConfig();
} catch (JoranException je) {
Util.report("Failed to auto configure default logger context", je);
}
// logback-292
if (!StatusUtil.contextHasStatusListener(loggerFactory)) {
StatusPrinter.printInCaseOfErrorsOrWarnings(loggerFactory);
if (!StatusUtil.contextHasStatusListener(defaultLoggerContext)) {
StatusPrinter.printInCaseOfErrorsOrWarnings(defaultLoggerContext);
}
contextSelectorBinder.init(defaultLoggerContext, KEY);
initialized = true;
} catch (Exception t) { // see LOGBACK-1159
Util.report("Failed to instantiate [" + LoggerContext.class.getName() + "]", t);
}
Expand All @@ -58,7 +64,14 @@ private void initializeLoggerContext(LoggerContext loggerFactory) {
@Override

public ILoggerFactory getLoggerFactory() {
return loggerFactory;
if (!initialized) {
return defaultLoggerContext;
}

if (contextSelectorBinder.getContextSelector() == null) {
throw new IllegalStateException("contextSelector cannot be null. See also " + NULL_CS_URL);
}
return contextSelectorBinder.getContextSelector().getLoggerContext();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.security.CodeSource;
import java.util.HashMap;

import sun.reflect.Reflection;
//import sun.reflect.Reflection;

// import java.security.AccessControlException; import java.security.AccessController;import java.security.PrivilegedAction;
/**
Expand All @@ -42,8 +42,8 @@ public class PackagingDataCalculator {
// sun.reflect.Reflection class. However, this class will *not compile*
// on JDKs lacking sun.reflect.Reflection.
try {
Reflection.getCallerClass(2);
GET_CALLER_CLASS_METHOD_AVAILABLE = true;
//Reflection.getCallerClass(2);
//GET_CALLER_CLASS_METHOD_AVAILABLE = true;
} catch (NoClassDefFoundError e) {
} catch (NoSuchMethodError e) {
} catch (UnsupportedOperationException e) {
Expand All @@ -70,9 +70,9 @@ void populateFrames(StackTraceElementProxy[] stepArray) {
// in the initial part of this method we populate package information for
// common stack frames
final Throwable t = new Throwable("local stack reference");
final StackTraceElement[] localteSTEArray = t.getStackTrace();
final int commonFrames = STEUtil.findNumberOfCommonFrames(localteSTEArray, stepArray);
final int localFirstCommon = localteSTEArray.length - commonFrames;
final StackTraceElement[] localSTEArray = t.getStackTrace();
final int commonFrames = STEUtil.findNumberOfCommonFrames(localSTEArray, stepArray);
final int localFirstCommon = localSTEArray.length - commonFrames;
final int stepFirstCommon = stepArray.length - commonFrames;

ClassLoader lastExactClassLoader = null;
Expand All @@ -82,7 +82,7 @@ void populateFrames(StackTraceElementProxy[] stepArray) {
for (int i = 0; i < commonFrames; i++) {
Class callerClass = null;
if (GET_CALLER_CLASS_METHOD_AVAILABLE) {
callerClass = Reflection.getCallerClass(localFirstCommon + i - missfireCount + 1);
//callerClass = Reflection.getCallerClass(localFirstCommon + i - missfireCount + 1);
}
StackTraceElementProxy step = stepArray[stepFirstCommon + i];
String stepClassname = step.ste.getClassName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
requires static java.management;



requires ch.qos.logback.core;
requires static groovy;

provides org.slf4j.spi.SLF4JServiceProvider with ch.qos.logback.classic.provider.LogbackServiceProvider;
provides org.slf4j.spi.SLF4JServiceProvider with ch.qos.logback.classic.spi.LogbackServiceProvider;

}
114 changes: 0 additions & 114 deletions logback-classic/src/main/java/org/slf4j/impl/StaticLoggerBinder.java

This file was deleted.

46 changes: 0 additions & 46 deletions logback-classic/src/main/java/org/slf4j/impl/StaticMDCBinder.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ch.qos.logback.classic.spi.LogbackServiceProvider
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class GafferConfiguratorTest {

@Test
void appenderRefShouldWork() {
context.putProperty("p", "HELLO");
File file = new File(ClassicTestConstants.GAFFER_INPUT_PREFIX + "asyncAppender.groovy")
configurator.run file.text

Expand All @@ -183,6 +184,7 @@ class GafferConfiguratorTest {

@Test
void appenderRefWithNonAppenderAttachable() {
context.putProperty("p", "HELLO");
String message = shouldFail(IllegalArgumentException) {
File file = new File(ClassicTestConstants.GAFFER_INPUT_PREFIX + "appenderRefWithNonAppenderAttachable.groovy")
configurator.run file.text
Expand Down
Loading

0 comments on commit e59b6d6

Please sign in to comment.