Skip to content

Commit 684a072

Browse files
committed
Fix initialization for Android 8.0
1 parent 8d912b3 commit 684a072

File tree

3 files changed

+13
-20
lines changed

3 files changed

+13
-20
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.idea
2+
android-log4j2-support.iml
3+
settings.xml
4+
target

pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.atteq</groupId>
66
<artifactId>android-log4j2-support</artifactId>
7-
<version>2.3</version>
7+
<version>2.3-f1</version>
88
<packaging>jar</packaging>
99

1010
<name>android-log4j2-support</name>
@@ -67,8 +67,8 @@
6767
<artifactId>maven-compiler-plugin</artifactId>
6868
<version>3.5.1</version>
6969
<configuration>
70-
<source>1.6</source>
71-
<target>1.6</target>
70+
<source>1.7</source>
71+
<target>1.7</target>
7272
</configuration>
7373
</plugin>
7474
<plugin>

src/main/java/com/atteq/log4j/initialization/android/AndroidContextSelector.java

+6-17
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import org.apache.logging.log4j.core.impl.ContextAnchor;
77
import org.apache.logging.log4j.core.selector.ContextSelector;
88

9-
import java.io.IOException;
109
import java.io.InputStream;
1110
import java.net.URI;
1211
import java.util.ArrayList;
@@ -20,20 +19,17 @@ public class AndroidContextSelector implements ContextSelector {
2019

2120
private static final LoggerContext CONTEXT = new LoggerContext("Default");
2221

23-
// private static boolean isStarted = false;
24-
2522
private void start(LoggerContext context) {
2623
InputStream stream = AndroidLog4jHelper.getConfig();
2724

28-
ConfigurationSource source = null;
2925
try {
30-
source = new ConfigurationSource(stream);
31-
} catch (IOException e) {
26+
ConfigurationSource source = new ConfigurationSource(stream);
27+
Configuration config = org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory.getInstance()
28+
.getConfiguration(source);
29+
context.start(config);
30+
} catch (Exception e) {
3231
e.printStackTrace();
3332
}
34-
Configuration config = org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory.getInstance()
35-
.getConfiguration(source);
36-
context.start(config);
3733
}
3834

3935
public LoggerContext getContext(String fqcn, ClassLoader loader, boolean currentContext) {
@@ -53,21 +49,14 @@ public LoggerContext getContext(final String fqcn, final ClassLoader loader, fin
5349
return ctx != null ? ctx : CONTEXT;
5450
}
5551

56-
public LoggerContext locateContext(final String name, final String configLocation) {
57-
if (!CONTEXT.isStarted()) {
58-
start(CONTEXT);
59-
}
60-
return CONTEXT;
61-
}
62-
6352
public void removeContext(final LoggerContext context) {
6453
}
6554

6655
public List<LoggerContext> getLoggerContexts() {
6756
if (!CONTEXT.isStarted()) {
6857
start(CONTEXT);
6958
}
70-
final List<LoggerContext> list = new ArrayList<LoggerContext>();
59+
final List<LoggerContext> list = new ArrayList<>();
7160
list.add(CONTEXT);
7261
return Collections.unmodifiableList(list);
7362
}

0 commit comments

Comments
 (0)