Skip to content

Commit

Permalink
Logging
Browse files Browse the repository at this point in the history
  • Loading branch information
xdnw committed Aug 22, 2024
1 parent 376a1f2 commit adb4d7f
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 82 deletions.
40 changes: 20 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ plugins {
id "nu.studer.jooq" version "8.0"
id 'maven-publish'
id "gg.jte.gradle" version "3.1.6"
// id "nebula.lint" version "19.0.3"
}

apply plugin: "kotlin"
apply plugin: 'java'
//apply plugin: "nebula.lint"

//gradleLint {
// rules=['unused-dependency']
//}

group 'link.locutus'
version '1.0-SNAPSHOT'
Expand Down Expand Up @@ -96,19 +102,17 @@ dependencies {
implementation 'com.amazonaws:aws-java-sdk-bom:1.12.649'
implementation 'com.amazonaws:aws-java-sdk-s3:1.12.649'

implementation 'org.apache.logging.log4j:log4j-core:2.23.1'
implementation 'org.apache.logging.log4j:log4j-api:2.13.3'

testImplementation 'org.hsqldb:hsqldb:2.7.2'

implementation 'org.apache.logging.log4j:log4j-core:2.19.0'
implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.19.0'

implementation 'com.pusher:pusher-java-client:2.4.4'

implementation 'de.vandermeer:asciitable:0.3.2'

implementation 'com.google.http-client:google-http-client-jackson2:1.43.3'

implementation('org.xerial:sqlite-jdbc:3.41.2.2')
implementation('org.xerial:sqlite-jdbc:3.46.1.0')
implementation 'com.google.code.gson:gson:2.8.9'
implementation 'org.jsoup:jsoup:1.12.1'
implementation 'org.bitbucket.cowwoc:diff-match-patch:1.2'
Expand Down Expand Up @@ -139,42 +143,37 @@ dependencies {
implementation 'com.google.apis:google-api-services-drive:v3-rev20220815-2.0.0'
implementation 'com.google.apis:google-api-services-docs:v1-rev20220609-2.0.0'
implementation 'de.erichseifert.gral:gral-core:0.11'
// https://mvnrepository.com/artifact/org.apache.commons/commons-math3
implementation 'org.apache.commons:commons-math3:3.6.1'

implementation 'org.kefirsf:kefirbb:1.5'
implementation ('com.inversoft:prime-transformer:2.1.4') {
exclude group: 'org.freemarker'
}


// https://mvnrepository.com/artifact/gnu.trove/trove
implementation group: 'gnu.trove', name: 'trove', version: '3.0.3'
// https://mvnrepository.com/artifact/it.unimi.dsi/fastutil
implementation group: 'it.unimi.dsi', name: 'fastutil', version: '8.2.1'

// https://mvnrepository.com/artifact/com.opencsv/opencsv
implementation group: 'com.opencsv', name: 'opencsv', version: '3.7'

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
// implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'in.wilsonl.minifyhtml:minify-html:0.15.0'

// implementation "org.springframework.boot:spring-boot-starter-web:2.4.4"
// implementation "org.springframework.boot:spring-boot-starter-data-mongodb:2.4.4"

implementation "com.graphql-java-kickstart:graphql-spring-boot-starter:11.1.0"
implementation "com.graphql-java-kickstart:graphiql-spring-boot-starter:11.1.0"
// implementation "com.graphql-java-kickstart:graphiql-spring-boot-starter:11.1.0"
// implementation 'org.springframework:spring-web:6.1.3'


implementation "com.graphql-java:graphql-java-extended-scalars:16.0.1"
// implementation "com.graphql-java:graphql-java-extended-scalars:16.0.1"
implementation "io.github.kobylynskyi:graphql-java-codegen:5.4.0"

implementation "org.apache.httpcomponents:httpclient:4.5.13"
implementation "javax.validation:validation-api:2.0.1.Final"

implementation "org.mapstruct:mapstruct:1.4.2.Final"
annotationProcessor "org.mapstruct:mapstruct-processor:1.4.2.Final"
// implementation "org.mapstruct:mapstruct:1.4.2.Final"
// annotationProcessor "org.mapstruct:mapstruct-processor:1.4.2.Final"
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.17.2'

// https://mvnrepository.com/artifact/de.siegmar/fastcsv
Expand All @@ -193,11 +192,11 @@ dependencies {
implementation("com.theokanning.openai-gpt3-java:service:0.18.2")
implementation("com.theokanning.openai-gpt3-java:api:0.18.2")

implementation 'com.github.javaparser:javaparser-symbol-solver-core:3.25.3'
implementation 'com.github.javaparser:javaparser-core:3.25.3'
// implementation 'com.github.javaparser:javaparser-symbol-solver-core:3.25.3'
// implementation 'com.github.javaparser:javaparser-core:3.25.3'
implementation 'com.knuddels:jtokkit:0.6.1'
// https://mvnrepository.com/artifact/org.tensorflow/tensorflow
implementation 'org.tensorflow:tensorflow:1.15.0'
// implementation 'org.tensorflow:tensorflow:1.15.0'
// implementation 'org.apache.commons:commons-lang3:3.12.0'
// https://mvnrepository.com/artifact/org.apache.commons/commons-text
// implementation 'org.apache.commons:commons-text:1.10.0'
Expand All @@ -210,7 +209,7 @@ dependencies {
runtimeOnly 'ai.djl.pytorch:pytorch-native-cu121:2.2.2:win-x86_64'
runtimeOnly 'ai.djl.pytorch:pytorch-jni:2.2.2-0.28.0'
// implementation 'net.sourceforge.tess4j:tess4j:4.5.1'
implementation 'org.bytedeco:javacv:1.5.6'
// implementation 'org.bytedeco:javacv:1.5.6'
implementation 'cn.easyproject:easyocr:3.0.4-RELEASE'
implementation 'com.vdurmont:emoji-java:5.1.1'
implementation 'info.debatty:java-string-similarity:2.0.0'
Expand Down Expand Up @@ -436,6 +435,7 @@ sourceSets {
srcDirs "$buildDir/generated-sources"
}
resources {
srcDirs "src/main/resources/log"
srcDirs "src/main/resources/css"
srcDirs "src/main/resources/js"
srcDirs "src/main/resources/img"
Expand Down Expand Up @@ -465,7 +465,7 @@ jar {
}

shadowJar {
// minimize()
minimize()
zip64=true
archiveBaseName = "${name}-${project.name}"
}
Expand Down
15 changes: 2 additions & 13 deletions src/main/java/link/locutus/discord/Locutus.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.async.AsyncLoggerContextSelector;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -147,20 +148,8 @@ public static synchronized Locutus create() {
}
}

private void setInfoLogging() {
// org.apache.log4j.Logger.getRootLogger().setLevel(Level.INFO);
// Configurator.setRootLevel(org.apache.logging.log4j.Level.INFO);
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
loggerConfig.setLevel(Level.INFO);
ctx.updateLoggers();
// ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) org.slf4j.LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
// root.setLevel(ch.qos.logback.classic.Level.INFO);
}

private Locutus() throws SQLException, ClassNotFoundException, LoginException, InterruptedException, NoSuchMethodException {
setInfoLogging();
Logg.setInfoLogging();

if (INSTANCE != null) throw new IllegalStateException("Already running.");
INSTANCE = this;
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/link/locutus/discord/Logg.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package link.locutus.discord;


import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.async.AsyncLoggerContextSelector;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.config.LoggerConfig;
import org.apache.logging.log4j.core.config.builder.api.*;
import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;

public class Logg {
private static final Logger LOGGER;

static {
LOGGER = LogManager.getLogger(Logg.class.getSimpleName());
}
private static final boolean DEBUG = true;

public static void text(Object obj) {
// System.out.println(obj);
LOGGER.error(obj);
}

public static void text(String msg, Object... obj) {
// System.out.println(String.format(msg, obj));
LOGGER.error(msg, obj);
}

public static void setInfoLogging() {
// org.apache.log4j.Logger.getRootLogger().setLevel(Level.INFO);
// Configurator.setRootLevel(org.apache.logging.log4j.Level.INFO);
System.setProperty("Log4jContextSelector", AsyncLoggerContextSelector.class.getName());
System.setProperty("log4j2.enable.threadlocals", "true"); // Enable garbage-free logging
System.setProperty("log4j2.contextSelector", "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");

LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
loggerConfig.setLevel(Level.INFO);

ctx.updateLoggers();
// ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) org.slf4j.LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
// root.setLevel(ch.qos.logback.classic.Level.INFO);
}
}
10 changes: 0 additions & 10 deletions src/main/java/link/locutus/discord/apiv3/PoliticsAndWarV3.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.reflect.TypeToken;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import link.locutus.discord.Locutus;
import link.locutus.discord.RequestTracker;
Expand All @@ -14,8 +12,6 @@
import link.locutus.discord.apiv1.enums.TreatyType;
import link.locutus.discord.apiv3.enums.AlliancePermission;
import link.locutus.discord.config.Settings;
import link.locutus.discord.db.DiscordDB;
import link.locutus.discord.db.entities.DBAlliance;
import link.locutus.discord.pnw.NationOrAlliance;
import link.locutus.discord.util.*;
import link.locutus.discord.util.StringMan;
Expand All @@ -24,10 +20,7 @@
import link.locutus.discord.apiv1.core.ApiKeyPool;
import graphql.GraphQLException;
import link.locutus.discord.util.io.PagePriority;
import net.dv8tion.jda.api.entities.channel.concrete.Category;
import net.dv8tion.jda.api.requests.ErrorResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
Expand All @@ -39,16 +32,13 @@
import org.springframework.web.client.RestTemplate;

import java.net.URI;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;

public class PoliticsAndWarV3 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package link.locutus.discord.commands.manager.v2.impl.pw.commands;

import com.github.javaparser.printer.lexicalpreservation.Added;
import link.locutus.discord.Locutus;
import link.locutus.discord.commands.manager.v2.binding.ValueStore;
import link.locutus.discord.commands.manager.v2.binding.annotation.Command;
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/link/locutus/discord/config/yaml/Config.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package link.locutus.discord.config.yaml;

import link.locutus.discord.Logg;
import link.locutus.discord.util.StringMan;
import link.locutus.discord.config.yaml.file.YamlConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.ByteArrayOutputStream;
import java.io.File;
Expand All @@ -26,8 +27,6 @@

public class Config {

private static final Logger LOGGER = LoggerFactory.getLogger(Config.class.getSimpleName());

public Config() {
save(new PrintWriter(new ByteArrayOutputStream(0)), getClass(), this, 0);
}
Expand All @@ -48,7 +47,7 @@ private <T> T get(String key, Class<?> root) {
}
}
}
LOGGER.error("Failed to get config option: {}", key);
Logg.text("Failed to get config option: {}", key);
return null;
}

Expand Down Expand Up @@ -115,7 +114,7 @@ private void set(String key, Object value, Class<?> root) {
}
}
System.out.println("Failed to set config option: " + key + ": " + value + " | " + instance + " | " + root.getSimpleName() + ".yml");
LOGGER.error("Failed to set config option: {}: {} | {} | {}.yml", key, value, instance, root.getSimpleName());
Logg.text("Failed to set config option: {}: {} | {} | {}.yml", key, value, instance, root.getSimpleName());
}

public boolean load(File file) {
Expand Down Expand Up @@ -356,7 +355,7 @@ private Field getField(String[] split, Object instance) {
setAccessible(field);
return field;
} catch (Throwable ignored) {
LOGGER.warn(
Logg.text(
"Invalid config field: {} for {}",
StringMan.join(split, "."),
toNodeName(instance.getClass().getSimpleName())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package link.locutus.discord.config.yaml.file;

import it.unimi.dsi.fastutil.io.BinIO;
import it.unimi.dsi.fastutil.io.FastBufferedInputStream;
import it.unimi.dsi.fastutil.io.FastByteArrayOutputStream;
import link.locutus.discord.Logg;
import link.locutus.discord.config.yaml.Configuration;
import link.locutus.discord.config.yaml.InvalidConfigurationException;
import link.locutus.discord.config.yaml.MemoryConfiguration;
Expand Down Expand Up @@ -118,9 +122,19 @@ public void load(File file) throws IOException, InvalidConfigurationException {
if (file == null) {
throw new NullPointerException("File cannot be null");
}
long start = System.currentTimeMillis();
try (FileInputStream stream = new FileInputStream(file);
InputStreamReader reader = new InputStreamReader(new FastBufferedInputStream(stream), StandardCharsets.UTF_8);
BufferedReader input = new BufferedReader(reader);
FastByteArrayOutputStream builder = new FastByteArrayOutputStream()) {

try (FileInputStream stream = new FileInputStream(file)) {
load(new InputStreamReader(stream, StandardCharsets.UTF_8));
String line;
while ((line = input.readLine()) != null) {
builder.write(line.getBytes(StandardCharsets.UTF_8));
builder.write('\n');
}
String myStr = new String(builder.array, 0, builder.length, StandardCharsets.UTF_8);
loadFromString(myStr);
}
}

Expand All @@ -138,9 +152,7 @@ public void load(File file) throws IOException, InvalidConfigurationException {
* @throws IllegalArgumentException thrown when reader is null
*/
public void load(Reader reader) throws IOException, InvalidConfigurationException {

StringBuilder builder = new StringBuilder();

try (BufferedReader input = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader)) {
String line;

Expand Down
Loading

0 comments on commit adb4d7f

Please sign in to comment.