mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-07-04 15:27:30 +07:00
Replaced Log4j2 with com.riiablo.logger (see #105)
Log4j2 removed as a dependency
This commit is contained in:
43
android/assets/log4j2.xml
vendored
43
android/assets/log4j2.xml
vendored
@ -1,43 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="warn" strict="true" name="RiiabloConfig"
|
||||
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="io.netty" level="warn" additivity="false">
|
||||
<AppenderRef ref="STDOUT"/>
|
||||
</Logger>
|
||||
|
||||
<Logger name="com.riiablo.save" level="trace" additivity="false">
|
||||
<AppenderRef ref="STDOUT"/>
|
||||
</Logger>
|
||||
|
||||
<Logger name="com.riiablo.item" level="trace" additivity="false">
|
||||
<AppenderRef ref="STDOUT"/>
|
||||
</Logger>
|
||||
|
||||
<Root level="debug">
|
||||
<AppenderRef ref="STDOUT"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
|
||||
</Configuration>
|
@ -243,11 +243,6 @@ project(":core") {
|
||||
compile group: 'io.netty', name: 'netty-all', version: nettyVersion
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.13.3'
|
||||
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.13.3'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testCompile 'junit:junit:4.12'
|
||||
testCompile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
|
||||
|
@ -59,7 +59,10 @@ import com.riiablo.loader.DC6Loader;
|
||||
import com.riiablo.loader.DCCLoader;
|
||||
import com.riiablo.loader.IndexLoader;
|
||||
import com.riiablo.loader.PaletteLoader;
|
||||
import com.riiablo.log.LogManager;
|
||||
import com.riiablo.logger.Level;
|
||||
import com.riiablo.logger.LogManager;
|
||||
import com.riiablo.logger.LoggerRegistry;
|
||||
import com.riiablo.logger.OutputStreamAppender;
|
||||
import com.riiablo.map.DS1;
|
||||
import com.riiablo.map.DS1Loader;
|
||||
import com.riiablo.map.DT1;
|
||||
@ -113,7 +116,7 @@ public class Client extends Game {
|
||||
private CharData charData;
|
||||
private D2 anim;
|
||||
private Metrics metrics;
|
||||
private LogManager logs;
|
||||
private LoggerRegistry logs;
|
||||
|
||||
private boolean forceWindowed;
|
||||
private boolean forceDrawFps;
|
||||
@ -216,9 +219,14 @@ public class Client extends Game {
|
||||
@Override
|
||||
public void create() {
|
||||
Riiablo.client = this;
|
||||
Riiablo.logs = logs = LogManager.INSTANCE;
|
||||
Gdx.app.setLogLevel(Application.LOG_DEBUG);
|
||||
|
||||
Riiablo.logs = logs = LogManager.getRegistry();
|
||||
logs.getRoot().level(Level.DEBUG);
|
||||
logs.setLevel("com.riiablo.save", Level.DEBUG);
|
||||
logs.setLevel("com.riiablo.item", Level.DEBUG);
|
||||
logs.setLevel("com.riiablo.engine", Level.TRACE);
|
||||
|
||||
// This is needed so that home is in a platform-dependent handle
|
||||
Riiablo.home = home = Gdx.files.absolute(home.path());
|
||||
|
||||
@ -231,6 +239,7 @@ public class Client extends Game {
|
||||
try {
|
||||
System.setOut(console.out);
|
||||
System.setErr(console.out);
|
||||
logs.getRoot().addAppender(new OutputStreamAppender(System.out));
|
||||
} catch (SecurityException e) {
|
||||
console.out.println("stdout could not be redirected to console: " + e.getMessage());
|
||||
throw new GdxRuntimeException("Unable to bind console out.", e);
|
||||
|
@ -5,10 +5,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.core.config.Configurator;
|
||||
import org.apache.logging.log4j.spi.LoggerContext;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input;
|
||||
@ -28,6 +24,8 @@ import com.riiablo.command.ParameterException;
|
||||
import com.riiablo.console.Console;
|
||||
import com.riiablo.cvar.Cvar;
|
||||
import com.riiablo.key.MappedKey;
|
||||
import com.riiablo.logger.Level;
|
||||
import com.riiablo.logger.LogManager;
|
||||
import com.riiablo.screen.SelectCharacterScreen3;
|
||||
import com.riiablo.serializer.SerializeException;
|
||||
import com.riiablo.serializer.StringSerializer;
|
||||
@ -292,12 +290,11 @@ public class Commands {
|
||||
@Override
|
||||
public void onExecuted(Command.Instance instance) {
|
||||
String name = instance.getArg(0);
|
||||
LoggerContext context = LogManager.getContext(false);
|
||||
Level level;
|
||||
if (name.equalsIgnoreCase("root")) {
|
||||
level = context.getLogger(LogManager.ROOT_LOGGER_NAME).getLevel();
|
||||
level = Riiablo.logs.getLevel(LogManager.ROOT);
|
||||
} else {
|
||||
level = context.getLogger(name).getLevel();
|
||||
level = Riiablo.logs.getLevel(name);
|
||||
}
|
||||
Riiablo.console.out.println(level);
|
||||
}
|
||||
@ -314,12 +311,12 @@ public class Commands {
|
||||
@Override
|
||||
public void onExecuted(Command.Instance instance) {
|
||||
String name = instance.getArg(0);
|
||||
Level level = Level.toLevel(instance.getArg(1), null);
|
||||
Level level = Level.valueOf(instance.getArg(1), null);
|
||||
if (level == null) {
|
||||
Riiablo.console.out.println("Unknown log level: " + instance.getArg(1));
|
||||
return;
|
||||
}
|
||||
Configurator.setLevel(name, level);
|
||||
Riiablo.logs.setLevel(name, level);
|
||||
}
|
||||
})
|
||||
.build();
|
||||
|
@ -17,7 +17,7 @@ import com.riiablo.codec.D2;
|
||||
import com.riiablo.codec.StringTBLs;
|
||||
import com.riiablo.console.RenderedConsole;
|
||||
import com.riiablo.graphics.PaletteIndexedBatch;
|
||||
import com.riiablo.log.LogManager;
|
||||
import com.riiablo.logger.LoggerRegistry;
|
||||
import com.riiablo.mpq.MPQFileHandleResolver;
|
||||
import com.riiablo.save.CharData;
|
||||
import com.riiablo.screen.GameScreen;
|
||||
@ -86,5 +86,5 @@ public class Riiablo {
|
||||
public static GameScreen game;
|
||||
public static D2 anim;
|
||||
public static Metrics metrics;
|
||||
public static LogManager logs;
|
||||
public static LoggerRegistry logs;
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.riiablo.engine.client;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.artemis.Aspect;
|
||||
import com.artemis.BaseSystem;
|
||||
import com.artemis.ComponentMapper;
|
||||
@ -26,7 +24,8 @@ import com.riiablo.engine.server.component.Interactable;
|
||||
import com.riiablo.engine.server.component.Position;
|
||||
import com.riiablo.engine.server.component.Target;
|
||||
import com.riiablo.item.Item;
|
||||
import com.riiablo.log.LogManager;
|
||||
import com.riiablo.logger.LogManager;
|
||||
import com.riiablo.logger.Logger;
|
||||
import com.riiablo.map.Map;
|
||||
import com.riiablo.map.RenderSystem;
|
||||
import com.riiablo.profiler.ProfilerSystem;
|
||||
|
@ -1,8 +1,5 @@
|
||||
package com.riiablo.engine.client;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.artemis.ComponentMapper;
|
||||
import com.artemis.annotations.All;
|
||||
import com.artemis.systems.IteratingSystem;
|
||||
@ -14,6 +11,8 @@ import com.riiablo.codec.Animation;
|
||||
import com.riiablo.codec.DC;
|
||||
import com.riiablo.codec.excel.Overlay;
|
||||
import com.riiablo.graphics.BlendMode;
|
||||
import com.riiablo.logger.LogManager;
|
||||
import com.riiablo.logger.Logger;
|
||||
|
||||
@All(com.riiablo.engine.client.component.Overlay.class)
|
||||
public class OverlayManager extends IteratingSystem {
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.riiablo.engine.client;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import net.mostlyoriginal.api.event.common.Subscribe;
|
||||
import net.mostlyoriginal.api.system.core.PassiveSystem;
|
||||
|
||||
@ -10,7 +8,8 @@ import com.riiablo.codec.excel.Skills;
|
||||
import com.riiablo.engine.server.event.SkillCastEvent;
|
||||
import com.riiablo.engine.server.event.SkillDoEvent;
|
||||
import com.riiablo.engine.server.event.SkillStartEvent;
|
||||
import com.riiablo.log.LogManager;
|
||||
import com.riiablo.logger.LogManager;
|
||||
import com.riiablo.logger.Logger;
|
||||
|
||||
public class SkillCastHandler extends PassiveSystem {
|
||||
private static final Logger log = LogManager.getLogger(SkillCastHandler.class);
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.riiablo.engine.server;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.artemis.ComponentMapper;
|
||||
import net.mostlyoriginal.api.event.common.EventSystem;
|
||||
import net.mostlyoriginal.api.event.common.Subscribe;
|
||||
@ -24,7 +22,8 @@ import com.riiablo.engine.server.event.AnimDataKeyframeEvent;
|
||||
import com.riiablo.engine.server.event.SkillCastEvent;
|
||||
import com.riiablo.engine.server.event.SkillDoEvent;
|
||||
import com.riiablo.engine.server.event.SkillStartEvent;
|
||||
import com.riiablo.log.LogManager;
|
||||
import com.riiablo.logger.LogManager;
|
||||
import com.riiablo.logger.Logger;
|
||||
|
||||
public class Actioneer extends PassiveSystem {
|
||||
private static final Logger log = LogManager.getLogger(Actioneer.class);
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.riiablo.engine.server;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.artemis.ComponentMapper;
|
||||
import com.artemis.annotations.All;
|
||||
import com.artemis.systems.IntervalIteratingSystem;
|
||||
@ -12,7 +10,8 @@ import com.riiablo.engine.Engine;
|
||||
import com.riiablo.engine.server.component.AnimData;
|
||||
import com.riiablo.engine.server.event.AnimDataFinishedEvent;
|
||||
import com.riiablo.engine.server.event.AnimDataKeyframeEvent;
|
||||
import com.riiablo.log.LogManager;
|
||||
import com.riiablo.logger.LogManager;
|
||||
import com.riiablo.logger.Logger;
|
||||
|
||||
@All(AnimData.class)
|
||||
public class AnimStepper extends IntervalIteratingSystem {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.riiablo.item;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
@ -9,8 +8,9 @@ import com.riiablo.codec.excel.Gems;
|
||||
import com.riiablo.codec.util.BitStream;
|
||||
import com.riiablo.io.BitInput;
|
||||
import com.riiablo.io.ByteInput;
|
||||
import com.riiablo.log.Log;
|
||||
import com.riiablo.log.LogManager;
|
||||
import com.riiablo.logger.LogManager;
|
||||
import com.riiablo.logger.Logger;
|
||||
import com.riiablo.logger.MDC;
|
||||
|
||||
public class ItemReader {
|
||||
private static final Logger log = LogManager.getLogger(ItemReader.class);
|
||||
@ -27,17 +27,17 @@ public class ItemReader {
|
||||
if (item.socketsFilled > 0) log.trace("Reading {} sockets...", item.socketsFilled);
|
||||
for (int i = 0; i < item.socketsFilled; i++) {
|
||||
try {
|
||||
Log.put("socket", i);
|
||||
MDC.put("socket", i);
|
||||
in.skipUntil(SIGNATURE);
|
||||
item.sockets.add(readSingleItem(in));
|
||||
} finally {
|
||||
Log.remove("socket");
|
||||
MDC.remove("socket");
|
||||
}
|
||||
}
|
||||
final int endOffset = in.bytesRead();
|
||||
final int itemSize = endOffset - startOffset; // TODO: remove when serialization implemented
|
||||
item.data = in.duplicate(startOffset, itemSize); // TODO: remove when serialization implemented
|
||||
if (log.isTraceEnabled()) {
|
||||
if (log.traceEnabled()) {
|
||||
log.trace("size: {} (0x{}) (+{} .. +{})",
|
||||
itemSize,
|
||||
Integer.toHexString(itemSize),
|
||||
@ -56,7 +56,7 @@ public class ItemReader {
|
||||
Item item = new Item();
|
||||
item.reset();
|
||||
item.flags = in.read32();
|
||||
Log.tracef(log, "flags: 0x%08X [%s]", item.flags, item.getFlagsString());
|
||||
log.tracef("flags: 0x%08X [%s]", item.flags, item.getFlagsString());
|
||||
item.version = in.readSafe8u();
|
||||
log.trace("version: {}", item.version);
|
||||
final BitInput bits = in.unalign();
|
||||
@ -101,7 +101,7 @@ public class ItemReader {
|
||||
|
||||
private static void readStandard(BitInput bits, Item item) {
|
||||
item.id = (int) bits.readRaw(32);
|
||||
Log.tracef(log, "id: 0x%08X", item.id);
|
||||
log.tracef("id: 0x%08X", item.id);
|
||||
item.ilvl = bits.read7u(7);
|
||||
item.quality = Quality.valueOf(bits.read7u(4));
|
||||
item.pictureId = bits.readBoolean() ? bits.read7u(3) : Item.NO_PICTURE_ID;
|
||||
@ -128,10 +128,10 @@ public class ItemReader {
|
||||
for (int i = 0; i < Item.NUM_PROPS; i++) {
|
||||
if (((listFlags >> i) & 1) == 1) {
|
||||
try {
|
||||
Log.put("propList", Item.getPropListString(i));
|
||||
MDC.put("propList", Item.getPropListString(i));
|
||||
props[i] = PropertyList.obtain().read(bits);
|
||||
} finally {
|
||||
Log.remove("propList");
|
||||
MDC.remove("propList");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import com.badlogic.gdx.utils.GdxRuntimeException;
|
||||
import com.riiablo.Riiablo;
|
||||
import com.riiablo.codec.excel.Gems;
|
||||
import com.riiablo.codec.excel.ItemEntry;
|
||||
import com.riiablo.log.Log;
|
||||
import com.riiablo.logger.MDC;
|
||||
|
||||
public class ItemUtils {
|
||||
private ItemUtils() {}
|
||||
@ -31,14 +31,14 @@ public class ItemUtils {
|
||||
static PropertyList[] getGemProps(Gems.Entry gem) {
|
||||
PropertyList[] props = new PropertyList[Item.NUM_GEMPROPS];
|
||||
try {
|
||||
Log.put("propList", "GEMPROPS_WEAPON");
|
||||
MDC.put("propList", "GEMPROPS_WEAPON");
|
||||
props[Item.GEMPROPS_WEAPON] = PropertyList.obtain().add(gem.weaponModCode, gem.weaponModParam, gem.weaponModMin, gem.weaponModMax);
|
||||
Log.put("propList", "GEMPROPS_ARMOR");
|
||||
MDC.put("propList", "GEMPROPS_ARMOR");
|
||||
props[Item.GEMPROPS_ARMOR] = PropertyList.obtain().add(gem.helmModCode, gem.helmModParam, gem.helmModMin, gem.helmModMax);
|
||||
Log.put("propList", "GEMPROPS_SHIELD");
|
||||
MDC.put("propList", "GEMPROPS_SHIELD");
|
||||
props[Item.GEMPROPS_SHIELD] = PropertyList.obtain().add(gem.shieldModCode, gem.shieldModParam, gem.shieldModMin, gem.shieldModMax);
|
||||
} finally {
|
||||
Log.remove("propList");
|
||||
MDC.remove("propList");
|
||||
}
|
||||
return props;
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package com.riiablo.item;
|
||||
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.riiablo.Riiablo;
|
||||
import com.riiablo.codec.excel.SetItems;
|
||||
@ -10,8 +9,9 @@ import com.riiablo.codec.excel.Sets;
|
||||
import com.riiablo.io.BitInput;
|
||||
import com.riiablo.io.BitOutput;
|
||||
import com.riiablo.io.ByteOutput;
|
||||
import com.riiablo.log.Log;
|
||||
import com.riiablo.log.LogManager;
|
||||
import com.riiablo.logger.LogManager;
|
||||
import com.riiablo.logger.Logger;
|
||||
import com.riiablo.logger.MDC;
|
||||
|
||||
public class ItemWriter {
|
||||
private static final Logger log = LogManager.getLogger(ItemWriter.class);
|
||||
@ -24,14 +24,14 @@ public class ItemWriter {
|
||||
if (item.socketsFilled > 0) log.trace("Writing {} sockets...", item.socketsFilled);
|
||||
for (int i = 0; i < item.socketsFilled; i++) {
|
||||
try {
|
||||
Log.put("socket", i);
|
||||
MDC.put("socket", i);
|
||||
Item socket = item.sockets.get(i);
|
||||
writeSingleItem(socket, out);
|
||||
} finally {
|
||||
Log.remove("socket");
|
||||
MDC.remove("socket");
|
||||
}
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
if (log.debugEnabled()) {
|
||||
final int endOffset = out.bytesWritten();
|
||||
final int itemSize = endOffset - startOffset;
|
||||
log.debug("size: {} (0x{}) (+{} .. +{})",
|
||||
@ -39,8 +39,8 @@ public class ItemWriter {
|
||||
Integer.toHexString(itemSize),
|
||||
Integer.toHexString(startOffset),
|
||||
Integer.toHexString(endOffset));
|
||||
if (log.isTraceEnabled()) {
|
||||
Log.tracef(log, "bytes: %n%s", ByteBufUtil.prettyHexDump(out.buffer()));
|
||||
if (log.traceEnabled()) {
|
||||
log.tracef("bytes: %n%s", ByteBufUtil.prettyHexDump(out.buffer()));
|
||||
} else {
|
||||
log.debug("bytes: {}", ByteBufUtil.hexDump(out.buffer()));
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package com.riiablo.item;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
@ -13,8 +12,9 @@ import com.riiablo.codec.excel.ItemStatCost;
|
||||
import com.riiablo.codec.excel.Properties;
|
||||
import com.riiablo.io.BitInput;
|
||||
import com.riiablo.io.BitOutput;
|
||||
import com.riiablo.log.Log;
|
||||
import com.riiablo.log.LogManager;
|
||||
import com.riiablo.logger.LogManager;
|
||||
import com.riiablo.logger.Logger;
|
||||
import com.riiablo.logger.MDC;
|
||||
|
||||
public class PropertyList implements Iterable<Stat> {
|
||||
private static final Logger log = LogManager.getLogger(PropertyList.class);
|
||||
@ -85,12 +85,12 @@ public class PropertyList implements Iterable<Stat> {
|
||||
for (int prop; (prop = bitStream.read15u(Stat.BITS)) != Stat.NONE; ) {
|
||||
final int numEncoded = Stat.getNumEncoded(prop);
|
||||
try {
|
||||
if (numEncoded > 1) Log.put("numEncoded", numEncoded);
|
||||
if (numEncoded > 1) MDC.put("numEncoded", numEncoded);
|
||||
for (int j = prop, size = j + numEncoded; j < size; j++) {
|
||||
read(j, bitStream);
|
||||
}
|
||||
} finally {
|
||||
Log.remove("numEncoded");
|
||||
MDC.remove("numEncoded");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package com.riiablo.item;
|
||||
|
||||
import com.google.common.primitives.UnsignedInts;
|
||||
import java.util.Arrays;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.riiablo.CharacterClass;
|
||||
import com.riiablo.Riiablo;
|
||||
@ -12,7 +11,8 @@ import com.riiablo.codec.excel.SkillDesc;
|
||||
import com.riiablo.codec.excel.Skills;
|
||||
import com.riiablo.io.BitInput;
|
||||
import com.riiablo.io.BitOutput;
|
||||
import com.riiablo.log.LogManager;
|
||||
import com.riiablo.logger.LogManager;
|
||||
import com.riiablo.logger.Logger;
|
||||
import com.riiablo.save.CharData;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
@ -1,55 +0,0 @@
|
||||
package com.riiablo.log;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.ThreadContext;
|
||||
import org.apache.logging.log4j.message.Message;
|
||||
import org.apache.logging.log4j.message.MessageFactory;
|
||||
import org.apache.logging.log4j.message.StringFormatterMessageFactory;
|
||||
|
||||
public class Log {
|
||||
private static final MessageFactory FORMAT_MESSAGE_FACTORY = StringFormatterMessageFactory.INSTANCE;
|
||||
|
||||
private static Message createMessage(String format, Object... args) {
|
||||
return FORMAT_MESSAGE_FACTORY.newMessage(format, args);
|
||||
}
|
||||
|
||||
public static void tracef(Logger logger, String format, Object... args) {
|
||||
logger.trace(createMessage(format, args));
|
||||
}
|
||||
|
||||
public static void debugf(Logger logger, String format, Object... args) {
|
||||
logger.debug(createMessage(format, args));
|
||||
}
|
||||
|
||||
public static void infof(Logger logger, String format, Object... args) {
|
||||
logger.info(createMessage(format, args));
|
||||
}
|
||||
|
||||
public static void warnf(Logger logger, String format, Object... args) {
|
||||
logger.warn(createMessage(format, args));
|
||||
}
|
||||
|
||||
public static void warnf(Logger logger, Throwable t, String format, Object... args) {
|
||||
logger.warn(createMessage(format, args), t);
|
||||
}
|
||||
|
||||
public static void errorf(Logger logger, Throwable t, String format, Object... args) {
|
||||
logger.error(createMessage(format, args), t);
|
||||
}
|
||||
|
||||
public static void put(String key, String value) {
|
||||
ThreadContext.put(key, value);
|
||||
}
|
||||
|
||||
public static void put(String key, int value) {
|
||||
put(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
public static void remove(String key) {
|
||||
ThreadContext.remove(key);
|
||||
}
|
||||
|
||||
public static void clearMap() {
|
||||
ThreadContext.clearMap();
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
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);
|
||||
}
|
||||
|
||||
public static Logger getLogger(String name) {
|
||||
return INSTANCE.get(name);
|
||||
}
|
||||
|
||||
private final Trie<String, Logger> loggers = new PatriciaTrie<>();
|
||||
|
||||
public Logger get(Class<?> clazz) {
|
||||
Logger logger = org.apache.logging.log4j.LogManager.getLogger(clazz);
|
||||
loggers.put(logger.getName().toLowerCase(), logger);
|
||||
return logger;
|
||||
}
|
||||
|
||||
public Logger get(String name) {
|
||||
Logger logger = org.apache.logging.log4j.LogManager.getLogger(name);
|
||||
loggers.put(logger.getName().toLowerCase(), logger);
|
||||
return logger;
|
||||
}
|
||||
|
||||
public SortedMap<String, Logger> prefixMap(String key) {
|
||||
return loggers.prefixMap(key);
|
||||
}
|
||||
}
|
@ -1,195 +0,0 @@
|
||||
package com.riiablo.log;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.core.Layout;
|
||||
import org.apache.logging.log4j.core.LogEvent;
|
||||
import org.apache.logging.log4j.core.config.Configuration;
|
||||
import org.apache.logging.log4j.core.config.DefaultConfiguration;
|
||||
import org.apache.logging.log4j.core.config.Node;
|
||||
import org.apache.logging.log4j.core.config.plugins.Plugin;
|
||||
import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute;
|
||||
import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
|
||||
import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
|
||||
import org.apache.logging.log4j.core.config.plugins.PluginElement;
|
||||
import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
|
||||
import org.apache.logging.log4j.core.layout.AbstractStringLayout;
|
||||
import org.apache.logging.log4j.core.layout.ByteBufferDestination;
|
||||
import org.apache.logging.log4j.core.layout.PatternLayout;
|
||||
import org.apache.logging.log4j.util.BiConsumer;
|
||||
import org.apache.logging.log4j.util.ReadOnlyStringMap;
|
||||
|
||||
import com.badlogic.gdx.utils.OrderedMap;
|
||||
|
||||
@Plugin(
|
||||
name = "MDCLayout",
|
||||
category = Node.CATEGORY,
|
||||
elementType = Layout.ELEMENT_TYPE,
|
||||
printObject = true
|
||||
)
|
||||
public class MDCLayout extends AbstractStringLayout {
|
||||
private final PatternLayout parent;
|
||||
private final boolean fullMode;
|
||||
|
||||
private static final int MAX_DEPTH = 256;
|
||||
private static final int DEPTH_STEP = 2;
|
||||
|
||||
private int depth = 0;
|
||||
private ReadOnlyStringMap ctx;
|
||||
private final byte[] spaces = StringUtils.repeat(' ', MAX_DEPTH * DEPTH_STEP).getBytes(super.getCharset());
|
||||
private final byte[] endl = System.getProperty("line.separator").getBytes(super.getCharset());
|
||||
|
||||
public MDCLayout(Configuration config, Charset charset, PatternLayout parent, boolean fullMode) {
|
||||
super(config, charset, null, null);
|
||||
this.parent = parent;
|
||||
this.fullMode = fullMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSerializable(LogEvent event) {
|
||||
return parent.toSerializable(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresLocation() {
|
||||
return parent.requiresLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getContentFormat() {
|
||||
return parent.getContentFormat();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private void writeEntry(
|
||||
ByteBufferDestination destination,
|
||||
int depth,
|
||||
OrderedMap.Entry<String, String> entry
|
||||
) {
|
||||
byte[] b = entry.toString().getBytes(getCharset());
|
||||
destination.writeBytes(spaces, 0, (depth - 1) * DEPTH_STEP + 1);
|
||||
destination.writeBytes(b, 0, b.length);
|
||||
destination.writeBytes(endl, 0, endl.length);
|
||||
}
|
||||
|
||||
private void writeEntry(
|
||||
ByteBufferDestination destination,
|
||||
int depth,
|
||||
Object obj
|
||||
) {
|
||||
byte[] b = String.valueOf(obj).getBytes(getCharset());
|
||||
if (depth > 0) destination.writeBytes(spaces, 0, (depth - 1) * DEPTH_STEP + 1);
|
||||
destination.writeBytes(b, 0, b.length);
|
||||
destination.writeBytes(endl, 0, endl.length);
|
||||
}
|
||||
|
||||
// Deprecated. May be needed when implementing different output
|
||||
@Deprecated
|
||||
private void writeMapDifference(
|
||||
ByteBufferDestination destination,
|
||||
int depth,
|
||||
final ReadOnlyStringMap parent,
|
||||
final ReadOnlyStringMap child
|
||||
) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append('{');
|
||||
child.forEach(new BiConsumer<String, Object>() {
|
||||
@Override
|
||||
public void accept(String s, Object o) {
|
||||
if (parent != null && Objects.equals(parent.getValue(s), o)) return;
|
||||
sb.append(s);
|
||||
sb.append(':');
|
||||
sb.append(o);
|
||||
sb.append(',');
|
||||
}
|
||||
});
|
||||
if (sb.length() > 1) sb.setLength(sb.length() - 1);
|
||||
sb.append('}');
|
||||
writeEntry(destination, depth, sb);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(LogEvent event, ByteBufferDestination destination) {
|
||||
if (fullMode) {
|
||||
parent.encode(event, destination);
|
||||
destination.writeBytes(spaces, 0, 1);
|
||||
writeEntry(destination, 0, event.getContextData());
|
||||
} else {
|
||||
ReadOnlyStringMap ctx = event.getContextData();
|
||||
depth = ctx.size();
|
||||
if (depth > 0) {
|
||||
if (!ctx.equals(this.ctx)) {
|
||||
writeEntry(destination, depth, ctx);
|
||||
this.ctx = ctx;
|
||||
}
|
||||
|
||||
destination.writeBytes(spaces, 0, depth * DEPTH_STEP);
|
||||
}
|
||||
|
||||
parent.encode(event, destination);
|
||||
destination.writeBytes(endl, 0, endl.length);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return parent.toString();
|
||||
}
|
||||
|
||||
@PluginBuilderFactory
|
||||
public static Builder newBuilder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder implements org.apache.logging.log4j.core.util.Builder<MDCLayout> {
|
||||
@PluginElement("PatternLayout")
|
||||
@Required
|
||||
private PatternLayout patternLayout;
|
||||
|
||||
// LOG4J2-783 use platform default by default
|
||||
@PluginBuilderAttribute
|
||||
private Charset charset = Charset.defaultCharset();
|
||||
|
||||
@PluginConfiguration
|
||||
private Configuration configuration;
|
||||
|
||||
@PluginBuilderAttribute
|
||||
private boolean fullMode = false;
|
||||
|
||||
private Builder() {}
|
||||
|
||||
public Builder withPatternLayout(final PatternLayout patternLayout) {
|
||||
this.patternLayout = patternLayout;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withConfiguration(final Configuration configuration) {
|
||||
this.configuration = configuration;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withCharset(final Charset charset) {
|
||||
// LOG4J2-783 if null, use platform default by default
|
||||
if (charset != null) {
|
||||
this.charset = charset;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withFullMode(final boolean fullMode) {
|
||||
this.fullMode = fullMode;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MDCLayout build() {
|
||||
// fall back to DefaultConfiguration
|
||||
if (configuration == null) {
|
||||
configuration = new DefaultConfiguration();
|
||||
}
|
||||
return new MDCLayout(configuration, charset, patternLayout, fullMode);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,235 +0,0 @@
|
||||
package com.riiablo.log;
|
||||
|
||||
import java.util.Map;
|
||||
import org.apache.commons.collections4.OrderedMap;
|
||||
import org.apache.commons.collections4.map.LinkedMap;
|
||||
import org.apache.commons.collections4.map.UnmodifiableOrderedMap;
|
||||
import org.apache.logging.log4j.spi.ThreadContextMap;
|
||||
import org.apache.logging.log4j.util.BiConsumer;
|
||||
import org.apache.logging.log4j.util.PropertiesUtil;
|
||||
import org.apache.logging.log4j.util.ReadOnlyStringMap;
|
||||
import org.apache.logging.log4j.util.TriConsumer;
|
||||
|
||||
@Deprecated
|
||||
public class OrderedThreadContextMap implements ThreadContextMap, ReadOnlyStringMap {
|
||||
/**
|
||||
* Property name ({@value} ) for selecting {@code InheritableThreadLocal} (value "true") or plain
|
||||
* {@code ThreadLocal} (value is not "true") in the implementation.
|
||||
*/
|
||||
public static final String INHERITABLE_MAP = "isThreadContextMapInheritable";
|
||||
|
||||
private final boolean useMap;
|
||||
private final ThreadLocal<OrderedMap<String, String>> localMap;
|
||||
|
||||
private static boolean inheritableMap;
|
||||
|
||||
static {
|
||||
init();
|
||||
}
|
||||
|
||||
static <K, V> OrderedMap<K, V> unmodifiableOrderedMap(OrderedMap<K, V> map) {
|
||||
return UnmodifiableOrderedMap.unmodifiableOrderedMap(map);
|
||||
}
|
||||
|
||||
// LOG4J2-479: by default, use a plain ThreadLocal, only use InheritableThreadLocal if configured.
|
||||
// (This method is package protected for JUnit tests.)
|
||||
static ThreadLocal<OrderedMap<String, String>> createThreadLocalMap(final boolean isMapEnabled) {
|
||||
if (inheritableMap) {
|
||||
return new InheritableThreadLocal<OrderedMap<String, String>>() {
|
||||
@Override
|
||||
protected OrderedMap<String, String> childValue(final OrderedMap<String, String> parentValue) {
|
||||
return parentValue != null && isMapEnabled
|
||||
? unmodifiableOrderedMap(new LinkedMap<>(parentValue))
|
||||
: null;
|
||||
}
|
||||
};
|
||||
}
|
||||
// if not inheritable, return plain ThreadLocal with null as initial value
|
||||
return new ThreadLocal<>();
|
||||
}
|
||||
|
||||
static void init() {
|
||||
inheritableMap = PropertiesUtil.getProperties().getBooleanProperty(INHERITABLE_MAP);
|
||||
}
|
||||
|
||||
public OrderedThreadContextMap() {
|
||||
this(true);
|
||||
}
|
||||
|
||||
public OrderedThreadContextMap(final boolean useMap) {
|
||||
this.useMap = useMap;
|
||||
this.localMap = createThreadLocalMap(useMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(final String key, final String value) {
|
||||
if (!useMap) {
|
||||
return;
|
||||
}
|
||||
OrderedMap<String, String> map = localMap.get();
|
||||
map = map == null ? new LinkedMap<String, String>(1) : new LinkedMap<>(map);
|
||||
map.put(key, value);
|
||||
localMap.set(unmodifiableOrderedMap(map));
|
||||
}
|
||||
|
||||
public void putAll(final Map<String, String> m) {
|
||||
if (!useMap) {
|
||||
return;
|
||||
}
|
||||
OrderedMap<String, String> map = localMap.get();
|
||||
map = map == null ? new LinkedMap<String, String>(m.size()) : new LinkedMap<>(map);
|
||||
for (final Map.Entry<String, String> e : m.entrySet()) {
|
||||
map.put(e.getKey(), e.getValue());
|
||||
}
|
||||
localMap.set(unmodifiableOrderedMap(map));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(final String key) {
|
||||
final Map<String, String> map = localMap.get();
|
||||
return map == null ? null : map.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(final String key) {
|
||||
final Map<String, String> map = localMap.get();
|
||||
if (map != null) {
|
||||
final OrderedMap<String, String> copy = new LinkedMap<>(map);
|
||||
copy.remove(key);
|
||||
localMap.set(unmodifiableOrderedMap(copy));
|
||||
}
|
||||
}
|
||||
|
||||
public void removeAll(final Iterable<String> keys) {
|
||||
final Map<String, String> map = localMap.get();
|
||||
if (map != null) {
|
||||
final OrderedMap<String, String> copy = new LinkedMap<>(map);
|
||||
for (final String key : keys) {
|
||||
copy.remove(key);
|
||||
}
|
||||
localMap.set(unmodifiableOrderedMap(copy));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
localMap.remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> toMap() {
|
||||
return getCopy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(final String key) {
|
||||
final Map<String, String> map = localMap.get();
|
||||
return map != null && map.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V> void forEach(final BiConsumer<String, ? super V> action) {
|
||||
final Map<String, String> map = localMap.get();
|
||||
if (map == null) {
|
||||
return;
|
||||
}
|
||||
for (final Map.Entry<String, String> entry : map.entrySet()) {
|
||||
//BiConsumer should be able to handle values of any type V. In our case the values are of type String.
|
||||
@SuppressWarnings("unchecked")
|
||||
final
|
||||
V value = (V) entry.getValue();
|
||||
action.accept(entry.getKey(), value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V, S> void forEach(final TriConsumer<String, ? super V, S> action, final S state) {
|
||||
final Map<String, String> map = localMap.get();
|
||||
if (map == null) {
|
||||
return;
|
||||
}
|
||||
for (final Map.Entry<String, String> entry : map.entrySet()) {
|
||||
//TriConsumer should be able to handle values of any type V. In our case the values are of type String.
|
||||
@SuppressWarnings("unchecked")
|
||||
final
|
||||
V value = (V) entry.getValue();
|
||||
action.accept(entry.getKey(), value, state);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <V> V getValue(final String key) {
|
||||
final Map<String, String> map = localMap.get();
|
||||
return (V) (map == null ? null : map.get(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getCopy() {
|
||||
final Map<String, String> map = localMap.get();
|
||||
return map == null ? new LinkedMap<String, String>() : new LinkedMap<>(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getImmutableMapOrNull() {
|
||||
return localMap.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
final Map<String, String> map = localMap.get();
|
||||
return map == null || map.size() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
final Map<String, String> map = localMap.get();
|
||||
return map == null ? 0 : map.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final Map<String, String> map = localMap.get();
|
||||
return map == null ? "{}" : map.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
final Map<String, String> map = this.localMap.get();
|
||||
result = prime * result + ((map == null) ? 0 : map.hashCode());
|
||||
result = prime * result + Boolean.valueOf(this.useMap).hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (obj instanceof OrderedThreadContextMap) {
|
||||
final OrderedThreadContextMap other = (OrderedThreadContextMap) obj;
|
||||
if (this.useMap != other.useMap) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!(obj instanceof ThreadContextMap)) {
|
||||
return false;
|
||||
}
|
||||
final ThreadContextMap other = (ThreadContextMap) obj;
|
||||
final Map<String, String> map = this.localMap.get();
|
||||
final Map<String, String> otherMap = other.getImmutableMapOrNull();
|
||||
if (map == null) {
|
||||
if (otherMap != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!map.equals(otherMap)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package com.riiablo.save;
|
||||
|
||||
import io.netty.util.ByteProcessor;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
|
||||
@ -9,8 +8,9 @@ import com.riiablo.io.ByteInput;
|
||||
import com.riiablo.io.InvalidFormat;
|
||||
import com.riiablo.io.UnsafeNarrowing;
|
||||
import com.riiablo.item.ItemReader;
|
||||
import com.riiablo.log.Log;
|
||||
import com.riiablo.log.LogManager;
|
||||
import com.riiablo.logger.LogManager;
|
||||
import com.riiablo.logger.Logger;
|
||||
import com.riiablo.logger.MDC;
|
||||
|
||||
public enum D2SReader {
|
||||
INSTANCE;
|
||||
@ -58,7 +58,7 @@ public enum D2SReader {
|
||||
d2s.version = in.readSafe32u();
|
||||
log.debug("version: {} ({})", d2s.version, D2S.getVersionString(d2s.version));
|
||||
try {
|
||||
Log.put("d2s.version", d2s.version);
|
||||
MDC.put("d2s.version", d2s.version);
|
||||
switch (d2s.version) {
|
||||
case D2S.VERSION_110:
|
||||
return D2SReader96.readHeader(in, d2s);
|
||||
@ -71,13 +71,13 @@ public enum D2SReader {
|
||||
return d2s;
|
||||
}
|
||||
} finally {
|
||||
Log.remove("d2s.version");
|
||||
MDC.remove("d2s.version");
|
||||
}
|
||||
}
|
||||
|
||||
public D2S readRemaining(D2S d2s, ByteInput in, ItemReader itemReader) {
|
||||
try {
|
||||
Log.put("d2s.version", d2s.version);
|
||||
MDC.put("d2s.version", d2s.version);
|
||||
switch (d2s.version) {
|
||||
case D2S.VERSION_110:
|
||||
return D2SReader96.readRemaining(d2s, in, itemReader);
|
||||
@ -90,13 +90,13 @@ public enum D2SReader {
|
||||
return d2s;
|
||||
}
|
||||
} finally {
|
||||
Log.remove("d2s.version");
|
||||
MDC.remove("d2s.version");
|
||||
}
|
||||
}
|
||||
|
||||
CharData copyTo(D2S d2s, CharData data) {
|
||||
try {
|
||||
Log.put("d2s.version", d2s.version);
|
||||
MDC.put("d2s.version", d2s.version);
|
||||
switch (d2s.version) {
|
||||
case D2S.VERSION_110:
|
||||
return D2SReader96.copyTo(d2s, data);
|
||||
@ -109,7 +109,7 @@ public enum D2SReader {
|
||||
return data;
|
||||
}
|
||||
} finally {
|
||||
Log.remove("d2s.version");
|
||||
MDC.remove("d2s.version");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package com.riiablo.save;
|
||||
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import java.util.Arrays;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
@ -19,8 +18,9 @@ import com.riiablo.item.Item;
|
||||
import com.riiablo.item.ItemReader;
|
||||
import com.riiablo.item.PropertyList;
|
||||
import com.riiablo.item.Stat;
|
||||
import com.riiablo.log.Log;
|
||||
import com.riiablo.log.LogManager;
|
||||
import com.riiablo.logger.LogManager;
|
||||
import com.riiablo.logger.Logger;
|
||||
import com.riiablo.logger.MDC;
|
||||
import com.riiablo.util.DebugUtils;
|
||||
|
||||
public class D2SReader96 {
|
||||
@ -82,11 +82,11 @@ public class D2SReader96 {
|
||||
d2s.alternate = in.readSafe32u();
|
||||
d2s.name = in.readString(Riiablo.MAX_NAME_LENGTH + 1);
|
||||
try {
|
||||
Log.put("d2s.name", d2s.name);
|
||||
MDC.put("d2s.name", d2s.name);
|
||||
log.debug("name: \"{}\"", d2s.name);
|
||||
Log.tracef(log, "checksum: 0x%08X", d2s.checksum);
|
||||
log.tracef("checksum: 0x%08X", d2s.checksum);
|
||||
d2s.flags = in.read32();
|
||||
Log.debugf(log, "flags: 0x%08X [%s]", d2s.flags, d2s.getFlagsString());
|
||||
log.debugf("flags: 0x%08X [%s]", d2s.flags, d2s.getFlagsString());
|
||||
d2s.charClass = in.readSafe8u();
|
||||
log.debug("charClass: {} ({})", d2s.charClass, DebugUtils.getClassString(d2s.charClass));
|
||||
in.skipBytes(2); // unknown
|
||||
@ -95,30 +95,30 @@ public class D2SReader96 {
|
||||
d2s.timestamp = in.read32();
|
||||
in.skipBytes(4); // unknown
|
||||
d2s.hotkeys = readInts(in, D2S.NUM_HOTKEYS);
|
||||
if (log.isDebugEnabled()) log.debug("hotkeys: {}", Arrays.toString(d2s.hotkeys));
|
||||
if (log.debugEnabled()) log.debug("hotkeys: {}", Arrays.toString(d2s.hotkeys));
|
||||
d2s.actions = new int[D2S.NUM_ACTIONS][D2S.NUM_BUTTONS];
|
||||
for (int i = 0; i < D2S.NUM_ACTIONS; i++) {
|
||||
final int[] actions = d2s.actions[i] = readInts(in, D2S.NUM_BUTTONS);
|
||||
if (log.isDebugEnabled()) log.debug("actions[{}]: {}", i, Arrays.toString(actions));
|
||||
if (log.debugEnabled()) log.debug("actions[{}]: {}", i, Arrays.toString(actions));
|
||||
}
|
||||
d2s.composites = in.readBytes(COF.Component.NUM_COMPONENTS);
|
||||
if (log.isDebugEnabled()) log.debug("composites: {}", ByteBufUtil.hexDump(d2s.composites));
|
||||
if (log.debugEnabled()) log.debug("composites: {}", ByteBufUtil.hexDump(d2s.composites));
|
||||
d2s.colors = in.readBytes(COF.Component.NUM_COMPONENTS);
|
||||
if (log.isDebugEnabled()) log.debug("colors: {}", ByteBufUtil.hexDump(d2s.colors));
|
||||
if (log.debugEnabled()) log.debug("colors: {}", ByteBufUtil.hexDump(d2s.colors));
|
||||
d2s.towns = in.readBytes(Riiablo.NUM_DIFFS);
|
||||
if (log.isDebugEnabled()) log.debug("towns: {} ({})", ByteBufUtil.hexDump(d2s.towns), d2s.getTownsString());
|
||||
if (log.debugEnabled()) log.debug("towns: {} ({})", ByteBufUtil.hexDump(d2s.towns), d2s.getTownsString());
|
||||
d2s.mapSeed = in.read32();
|
||||
Log.debugf(log, "mapSeed: 0x%08X", d2s.mapSeed);
|
||||
log.debugf("mapSeed: 0x%08X", d2s.mapSeed);
|
||||
try {
|
||||
Log.put("d2s.section", "merc");
|
||||
MDC.put("d2s.section", "merc");
|
||||
d2s.merc = readMercData(in);
|
||||
} finally {
|
||||
Log.remove("d2s.section");
|
||||
MDC.remove("d2s.section");
|
||||
}
|
||||
in.skipBytes(144); // realm data (unused)
|
||||
assert in.bytesRemaining() == 0 : "in.bytesRemaining(" + in.bytesRemaining() + ") > " + 0;
|
||||
} finally {
|
||||
Log.remove("d2s.name");
|
||||
MDC.remove("d2s.name");
|
||||
}
|
||||
return d2s;
|
||||
}
|
||||
@ -127,9 +127,9 @@ public class D2SReader96 {
|
||||
in = in.readSlice(MERC_SIZE);
|
||||
D2S.MercData merc = new D2S.MercData();
|
||||
merc.flags = in.read32();
|
||||
Log.debugf(log, "merc.flags: 0x%08X", merc.flags);
|
||||
log.debugf("merc.flags: 0x%08X", merc.flags);
|
||||
merc.seed = in.read32();
|
||||
Log.debugf(log, "merc.seed: 0x%08X", merc.seed);
|
||||
log.debugf("merc.seed: 0x%08X", merc.seed);
|
||||
merc.name = in.readSafe16u();
|
||||
log.debug("merc.name: {}", merc.name);
|
||||
merc.type = in.readSafe16u();
|
||||
@ -153,44 +153,44 @@ public class D2SReader96 {
|
||||
|
||||
static D2S readRemaining(D2S d2s, ByteInput in, ItemReader itemReader) {
|
||||
try {
|
||||
Log.put("d2s.name", d2s.name);
|
||||
MDC.put("d2s.name", d2s.name);
|
||||
|
||||
Log.put("d2s.section", "quests");
|
||||
MDC.put("d2s.section", "quests");
|
||||
d2s.quests = readQuestData(in);
|
||||
|
||||
Log.put("d2s.section", "waypoints");
|
||||
MDC.put("d2s.section", "waypoints");
|
||||
d2s.waypoints = readWaypointData(in);
|
||||
|
||||
Log.put("d2s.section", "npcs");
|
||||
MDC.put("d2s.section", "npcs");
|
||||
d2s.npcs = readNPCData(in);
|
||||
|
||||
Log.put("d2s.section", "stats");
|
||||
MDC.put("d2s.section", "stats");
|
||||
d2s.stats = readStatData(in);
|
||||
|
||||
recover(in, SKILLS_SIGNATURE, "skills");
|
||||
Log.put("d2s.section", "skills");
|
||||
MDC.put("d2s.section", "skills");
|
||||
d2s.skills = readSkillData(in);
|
||||
|
||||
recover(in, ITEMS_SIGNATURE, "items");
|
||||
Log.put("d2s.section", "items");
|
||||
MDC.put("d2s.section", "items");
|
||||
d2s.items = readItemData(in, itemReader);
|
||||
|
||||
recover(in, ITEMS_SIGNATURE, "corpse");
|
||||
Log.put("d2s.section", "corpse");
|
||||
MDC.put("d2s.section", "corpse");
|
||||
d2s.corpse = readItemData(in, itemReader);
|
||||
|
||||
recover(in, MERC_SIGNATURE, "merc");
|
||||
Log.put("d2s.section", "merc");
|
||||
MDC.put("d2s.section", "merc");
|
||||
d2s.merc = readMercData(d2s.merc, in, itemReader);
|
||||
|
||||
recover(in, GOLEM_SIGNATURE, "golem");
|
||||
Log.put("d2s.section", "golem");
|
||||
MDC.put("d2s.section", "golem");
|
||||
d2s.golem = readGolemData(in, itemReader);
|
||||
|
||||
d2s.bodyRead = true;
|
||||
} finally {
|
||||
Log.remove("d2s.section");
|
||||
Log.remove("d2s.name");
|
||||
MDC.remove("d2s.section");
|
||||
MDC.remove("d2s.name");
|
||||
}
|
||||
return d2s;
|
||||
}
|
||||
@ -208,8 +208,8 @@ public class D2SReader96 {
|
||||
final byte[][] flags = quests.flags = new byte[D2S.NUM_DIFFS][];
|
||||
for (int i = 0; i < D2S.NUM_DIFFS; i++) {
|
||||
flags[i] = in.readBytes(D2S.QuestData.NUM_QUESTFLAGS);
|
||||
if (log.isDebugEnabled()) {
|
||||
Log.debugf(log, "quests.flags[%.4s]: %s",
|
||||
if (log.debugEnabled()) {
|
||||
log.debugf("quests.flags[%.4s]: %s",
|
||||
DebugUtils.getDifficultyString(i),
|
||||
ByteBufUtil.hexDump(flags[i]));
|
||||
}
|
||||
@ -231,8 +231,8 @@ public class D2SReader96 {
|
||||
final byte[][] flags = waypoints.flags = new byte[D2S.NUM_DIFFS][];
|
||||
for (int i = 0; i < D2S.NUM_DIFFS; i++) {
|
||||
flags[i] = readWaypointFlags(in);
|
||||
if (log.isDebugEnabled()) {
|
||||
Log.debugf(log, "waypoints.flags[%.4s]: %s",
|
||||
if (log.debugEnabled()) {
|
||||
log.debugf("waypoints.flags[%.4s]: %s",
|
||||
DebugUtils.getDifficultyString(i),
|
||||
ByteBufUtil.hexDump(flags[i]));
|
||||
}
|
||||
@ -261,8 +261,8 @@ public class D2SReader96 {
|
||||
for (int i = 0; i < D2S.NPCData.NUM_GREETINGS; i++) {
|
||||
for (int j = 0; j < D2S.NUM_DIFFS; j++) {
|
||||
flags[i][j] = in.readBytes(D2S.NPCData.NUM_INTROS);
|
||||
if (log.isDebugEnabled()) {
|
||||
Log.debugf(log, "npcs.flags[%s][%.4s]: %s",
|
||||
if (log.debugEnabled()) {
|
||||
log.debugf("npcs.flags[%s][%.4s]: %s",
|
||||
D2S.NPCData.getGreetingString(i),
|
||||
DebugUtils.getDifficultyString(j),
|
||||
ByteBufUtil.hexDump(flags[i][j]));
|
||||
@ -383,9 +383,11 @@ public class D2SReader96 {
|
||||
in = in.readSlice(SKILLS_SIZE - SKILLS_SIGNATURE.length);
|
||||
D2S.SkillData skills = new D2S.SkillData();
|
||||
skills.skills = in.readBytes(D2S.SkillData.NUM_TREES * D2S.SkillData.NUM_SKILLS);
|
||||
if (log.isDebugEnabled()) {
|
||||
if (log.debugEnabled()) {
|
||||
for (int i = 0, j = 0; i < D2S.SkillData.NUM_TREES; i++, j += D2S.SkillData.NUM_SKILLS) {
|
||||
Log.debugf(log, "skills.skills[%d] = %s", i, ByteBufUtil.hexDump(skills.skills, j, D2S.SkillData.NUM_SKILLS));
|
||||
log.debugf("skills.skills[%d] = %s",
|
||||
i,
|
||||
ByteBufUtil.hexDump(skills.skills, j, D2S.SkillData.NUM_SKILLS));
|
||||
}
|
||||
}
|
||||
assert in.bytesRemaining() == 0 : "in.bytesRemaining(" + in.bytesRemaining() + ") > " + 0;
|
||||
@ -402,20 +404,20 @@ public class D2SReader96 {
|
||||
int errors = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
try {
|
||||
Log.put("item", i);
|
||||
MDC.put("item", i);
|
||||
final Item item = itemReader.readItem(in);
|
||||
log.debug("item: {}", item);
|
||||
itemList.add(item);
|
||||
} catch (SignatureMismatch t) {
|
||||
log.warn(t);
|
||||
log.warn(t.getMessage(), t);
|
||||
i--;
|
||||
itemReader.skipUntil(in.realign());
|
||||
} catch (InvalidFormat t) {
|
||||
log.warn(t);
|
||||
log.warn(t.getMessage(), t);
|
||||
errors++;
|
||||
itemReader.skipUntil(in.realign());
|
||||
} finally {
|
||||
Log.remove("item");
|
||||
MDC.remove("item");
|
||||
}
|
||||
}
|
||||
assert itemList.size == size : "itemList.size(" + itemList.size + ") != size(" + size + ")";
|
||||
|
@ -1,10 +1,9 @@
|
||||
package com.riiablo.save;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.riiablo.io.ByteOutput;
|
||||
import com.riiablo.log.Log;
|
||||
import com.riiablo.log.LogManager;
|
||||
import com.riiablo.logger.LogManager;
|
||||
import com.riiablo.logger.Logger;
|
||||
import com.riiablo.logger.MDC;
|
||||
|
||||
public enum D2SWriter {
|
||||
INSTANCE;
|
||||
@ -24,7 +23,7 @@ public enum D2SWriter {
|
||||
out.writeBytes(SIGNATURE);
|
||||
out.write32(d2s.version);
|
||||
try {
|
||||
Log.put("d2s.version", d2s.version);
|
||||
MDC.put("d2s.version", d2s.version);
|
||||
switch (d2s.version) {
|
||||
case D2S.VERSION_110:
|
||||
D2SWriter96.writeHeader(d2s, out);
|
||||
@ -38,7 +37,7 @@ public enum D2SWriter {
|
||||
return;
|
||||
}
|
||||
} finally {
|
||||
Log.remove("d2s.version");
|
||||
MDC.remove("d2s.version");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
package com.riiablo.save;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.riiablo.Riiablo;
|
||||
import com.riiablo.io.ByteOutput;
|
||||
import com.riiablo.log.LogManager;
|
||||
import com.riiablo.logger.LogManager;
|
||||
import com.riiablo.logger.Logger;
|
||||
|
||||
public class D2SWriter96 {
|
||||
private static final Logger log = LogManager.getLogger(D2SWriter96.class);
|
||||
|
@ -1,12 +1,12 @@
|
||||
package com.riiablo.save;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
|
||||
import com.riiablo.io.ByteOutput;
|
||||
import com.riiablo.log.LogManager;
|
||||
import com.riiablo.logger.LogManager;
|
||||
import com.riiablo.logger.Logger;
|
||||
|
||||
public class D2SWriterStub {
|
||||
private static final Logger log = LogManager.getLogger(D2SWriterStub.class);
|
||||
|
@ -4,10 +4,10 @@ import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import org.apache.commons.collections4.Trie;
|
||||
import org.apache.commons.collections4.trie.PatriciaTrie;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import com.riiablo.console.Console;
|
||||
import com.riiablo.console.ConsoleUtils;
|
||||
import com.riiablo.logger.Level;
|
||||
import com.riiablo.util.StringUtils;
|
||||
|
||||
public enum LoggerLevelSuggester implements Console.SuggestionProvider {
|
||||
|
@ -3,7 +3,6 @@ package com.riiablo.suggester;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
|
||||
import com.riiablo.Riiablo;
|
||||
import com.riiablo.console.Console;
|
||||
import com.riiablo.console.ConsoleUtils;
|
||||
import com.riiablo.util.StringUtils;
|
||||
@ -13,8 +12,9 @@ public enum LoggerSuggester implements Console.SuggestionProvider {
|
||||
|
||||
@Override
|
||||
public int suggest(Console console, CharSequence buffer, String[] args, int targetArg) {
|
||||
if (true) return 0;
|
||||
String arg = targetArg == args.length ? "" : args[targetArg];
|
||||
SortedMap<String, ?> keys = Riiablo.logs.prefixMap(arg);
|
||||
SortedMap<String, ?> keys = null;//Riiablo.logs.prefixMap(arg);
|
||||
switch (keys.size()) {
|
||||
case 0:
|
||||
return 0;
|
||||
|
@ -15,6 +15,8 @@ import com.riiablo.Riiablo;
|
||||
import com.riiablo.codec.StringTBLs;
|
||||
import com.riiablo.io.ByteInput;
|
||||
import com.riiablo.item.ItemReader;
|
||||
import com.riiablo.logger.Level;
|
||||
import com.riiablo.logger.LogManager;
|
||||
import com.riiablo.mpq.MPQFileHandleResolver;
|
||||
|
||||
public class D2SReaderTool extends ApplicationAdapter {
|
||||
@ -42,6 +44,9 @@ public class D2SReaderTool extends ApplicationAdapter {
|
||||
Riiablo.files = new Files(Riiablo.assets);
|
||||
Riiablo.string = new StringTBLs(Riiablo.mpqs);
|
||||
|
||||
LogManager.setLevel("com.riiablo.save", Level.ALL);
|
||||
LogManager.setLevel("com.riiablo.item", Level.ALL);
|
||||
|
||||
ItemReader itemReader = new ItemReader();
|
||||
D2SReader serializer = D2SReader.INSTANCE;
|
||||
for (String d2ss0 : d2ss) {
|
||||
|
Reference in New Issue
Block a user