Added programmic loading of log4j2 configuration file

Committing log4j2.xml with default settings (to be ammended)
This commit is contained in:
Collin Smith 2020-08-15 13:34:11 -07:00
parent 39227995a2
commit b573bd4fa7
2 changed files with 53 additions and 0 deletions

35
android/assets/log4j2.xml vendored Normal file
View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" strict="true" name="XMLConfigTest"
packages="com.riiablo">
<!--<Filter type="ThresholdFilter" level="trace"/>-->
<Appenders>
<!--<Appender type="Console" name="STDOUT" follow="true">-->
<!--<PatternLayout>-->
<!--<MarkerPatternSelector defaultPattern="%-5level [%logger{1}] %message%n">-->
<!--<PatternMatch key="FLOW" pattern="%-5level [%logger{1}] %method %message%n"/>-->
<!--</MarkerPatternSelector>-->
<!--</PatternLayout>-->
<!--</Appender>-->
<Appender type="Console" name="STDOUT" follow="true">
<MDCLayout fullMode="false">
<PatternLayout alwaysWriteExceptions="true">
<MarkerPatternSelector defaultPattern="%-5level [%logger{1}] %message">
<PatternMatch key="FLOW" pattern="%-5level [%logger{1}] %method %message"/>
</MarkerPatternSelector>
</PatternLayout>
</MDCLayout>
</Appender>
</Appenders>
<Loggers>
<Logger name="com.riiablo.item" level="trace" additivity="false">
<AppenderRef ref="STDOUT"/>
</Logger>
<Root level="trace">
<AppenderRef ref="STDOUT"/>
</Root>
</Loggers>
</Configuration>

View File

@ -1,13 +1,31 @@
package com.riiablo.log;
import java.io.File;
import java.io.FileInputStream;
import java.util.SortedMap;
import org.apache.commons.collections4.Trie;
import org.apache.commons.collections4.trie.PatriciaTrie;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.config.Configurator;
public enum LogManager {
INSTANCE;
// DO NOT USE GDX METHODS HERE
// THIS BLOCK SHOULD BE GDX AGNOSTIC
static {
// -Dlog4j.configurationFile=log4j2.xml
System.out.println("Initializing log4j2 configuration file...");
try {
String log4jConfigFile = System.getProperty("user.dir") + File.separator + "log4j2.xml";
ConfigurationSource source = new ConfigurationSource(new FileInputStream(log4jConfigFile));
Configurator.initialize(null, source);
} catch (Throwable t) {
t.printStackTrace();
}
}
public static Logger getLogger(Class<?> clazz) {
return INSTANCE.get(clazz);
}