Skip to content

Commit

Permalink
Improve custom logger
Browse files Browse the repository at this point in the history
  • Loading branch information
fr1kin committed Dec 22, 2020
1 parent d5e1597 commit b520b1d
Show file tree
Hide file tree
Showing 35 changed files with 280 additions and 1,088 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ minecraft {
client {
workingDirectory project.file('run')

// property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
property 'forge.logging.console.level', 'info'
property 'forgehax.logging.level', 'debug'

Expand Down
14 changes: 8 additions & 6 deletions src/main/java/dev/fiki/forgehax/api/ImageUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.fiki.forgehax.api;

import dev.fiki.forgehax.main.Common;
import lombok.extern.log4j.Log4j2;

import javax.imageio.ImageIO;
import java.awt.*;
Expand All @@ -10,8 +11,9 @@
/**
* Created by Babbaj on 11/7/2017.
*/
@Log4j2
public class ImageUtils implements Common {

public static BufferedImage createResizedCopy(
Image originalImage, int scaledWidth, int scaledHeight, boolean preserveAlpha) {
int imageType = preserveAlpha ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
Expand All @@ -24,24 +26,24 @@ public static BufferedImage createResizedCopy(
g.dispose();
return scaledBI;
}

public static BufferedImage getImageFromUrl(String link) {
BufferedImage image = null;
try {
URL url = new URL(link);
image = ImageIO.read(url);
} catch (Exception e) {
Common.getLogger().error("Failed to download Image");
log.error("Failed to download Image");
}
return image;
}

public static int[][] imageToArray(BufferedImage imageIn) {
int width = imageIn.getWidth();
int height = imageIn.getHeight();

int[][] data = new int[height][width]; // array of rows

for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
data[i][j] = imageIn.getRGB(i, j);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.fiki.forgehax.api.classloader;

import lombok.extern.log4j.Log4j2;

import javax.annotation.Nullable;
import java.io.IOException;
import java.lang.annotation.Annotation;
Expand All @@ -11,11 +13,11 @@
import java.util.stream.Collectors;

import static dev.fiki.forgehax.main.Common.getLauncherClassLoader;
import static dev.fiki.forgehax.main.Common.getLogger;

/**
* Created on 2/13/2018 by fr1kin
*/
@Log4j2
public abstract class AbstractClassLoader<E> {

protected AbstractClassLoader() {
Expand Down Expand Up @@ -76,8 +78,8 @@ protected E create(Class<? extends E> clazz) {
| IllegalAccessException
| InvocationTargetException
| NoSuchMethodException e) {
getLogger().error("Failed to create new instance of {}", clazz.getSimpleName());
getLogger().error(e, e);
log.error("Failed to create new instance of {}", clazz.getSimpleName());
log.error(e, e);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.fiki.forgehax.api.Streamables;
import dev.fiki.forgehax.main.ForgeHax;
import lombok.SneakyThrows;
import lombok.extern.log4j.Log4j2;
import net.minecraftforge.fml.loading.FMLLoader;
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
import org.objectweb.asm.Type;
Expand All @@ -27,8 +28,8 @@
import java.util.stream.Collectors;

import static dev.fiki.forgehax.api.FileHelper.*;
import static dev.fiki.forgehax.main.Common.getLogger;

@Log4j2
public class ClassLoaderHelper {
private static Class<?> MODJAR_URLCONNECTION_CLASS;

Expand Down Expand Up @@ -199,7 +200,7 @@ public static List<Path> getClassesInPackage(final ClassLoader classLoader,

final URLConnection connection = url.openConnection();

getLogger().debug("Connecting to jar using {}", connection.getClass());
log.debug("Connecting to jar using {}", connection.getClass());

if (isFMLConnection(connection)) {
final ModFile modFile = getModFileInModJar(connection);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/fiki/forgehax/api/cmd/ICommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import dev.fiki.forgehax.api.cmd.listener.ICommandListener;
import dev.fiki.forgehax.api.cmd.listener.IListenable;
import dev.fiki.forgehax.api.serialization.IJsonSerializable;
import dev.fiki.forgehax.main.Common;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.annotation.Nullable;
Expand Down Expand Up @@ -146,7 +146,7 @@ default Path getConfigDirectory() {
}

default Logger getLog() {
return Common.getLogger();
return LogManager.getLogger(getClass());
}

class MissingConfigurationDirectoryException extends RuntimeException {
Expand Down

This file was deleted.

Loading

0 comments on commit b520b1d

Please sign in to comment.