diff --git a/build.gradle b/build.gradle index 87e5240..6737ce7 100644 --- a/build.gradle +++ b/build.gradle @@ -24,7 +24,9 @@ repositories { dependencies { implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.18.2' implementation group: 'io.javalin', name: 'javalin', version: '3.13.13' - implementation group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.32' + implementation group: 'org.tinylog', name: 'slf4j-tinylog', version: '2.7.0' + implementation group: 'org.tinylog', name: 'tinylog-api', version: '2.7.0' + implementation group: 'org.tinylog', name: 'tinylog-impl', version: '2.7.0' implementation group: 'commons-io', name: 'commons-io', version: '2.14.0' implementation group: 'com.vdurmont', name: 'semver4j', version: '3.1.0' implementation group: 'it.unimi.dsi', name: 'fastutil', version: '8.5.13' diff --git a/src/main/java/net/ornithemc/meta/OrnitheMeta.java b/src/main/java/net/ornithemc/meta/OrnitheMeta.java index 6384eb4..dd7f8ae 100644 --- a/src/main/java/net/ornithemc/meta/OrnitheMeta.java +++ b/src/main/java/net/ornithemc/meta/OrnitheMeta.java @@ -23,6 +23,8 @@ import net.ornithemc.meta.data.VersionDatabase; import net.ornithemc.meta.data.VersionDatabaseOld; import net.ornithemc.meta.web.WebServer; +import org.tinylog.Logger; +import org.tinylog.TaggedLogger; import javax.xml.stream.XMLStreamException; import java.io.IOException; @@ -36,8 +38,10 @@ public class OrnitheMeta public static volatile VersionDatabaseOld databaseOld; public static volatile VersionDatabase database; public static final ObjectMapper MAPPER = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT); + public static final TaggedLogger LOGGER = Logger.tag("ornithe-meta"); public static void main(String[] args) { + LOGGER.warn("Starting up!"); update(); @@ -52,7 +56,7 @@ private static void update(){ databaseOld = VersionDatabaseOld.generate(); database = VersionDatabase.generate(); } catch (IOException | XMLStreamException e) { - e.printStackTrace(); + Logger.error(e); } } diff --git a/src/main/java/net/ornithemc/meta/data/VersionDatabase.java b/src/main/java/net/ornithemc/meta/data/VersionDatabase.java index 5859683..e0d1c3a 100644 --- a/src/main/java/net/ornithemc/meta/data/VersionDatabase.java +++ b/src/main/java/net/ornithemc/meta/data/VersionDatabase.java @@ -177,7 +177,7 @@ public static VersionDatabase generate() throws IOException, XMLStreamException database.oslModules.put(module, parser.getMeta(MavenVersion::new, "net.ornithemc.osl:" + module + ":")); } database.loadMcData(); - System.out.println("DB update took " + (System.currentTimeMillis() - start) + "ms"); + OrnitheMeta.LOGGER.info("DB update took {}ms", System.currentTimeMillis() - start); return database; } @@ -205,7 +205,7 @@ private void loadMcData() throws IOException { // Remove entries that do not match a valid mc version. value.removeIf(o -> { if (launcherMeta.getVersions().stream().noneMatch(metaVersion -> metaVersion.getId().equals(o.getVersionNoSide()))) { - System.out.println("Removing " + o.getVersion() + " from intermediary v3" + (gen < 1 ? "" : " gen" + gen) + " as it does not match a mc version"); + OrnitheMeta.LOGGER.info("Removing {} from intermediary v3{} as it does not match a mc version", o.getVersion(), (gen < 1 ? "" : " gen" + gen)); return true; } return false; @@ -222,7 +222,7 @@ private void loadMcData() throws IOException { // Remove entries that do not match a valid mc version. value.removeIf(o -> { if (launcherMeta.getVersions().stream().noneMatch(metaVersion -> metaVersion.getId().equals(o.getVersionNoSide()))) { - System.out.println("Removing " + o.getGameVersion() + " from v3 feather" + " gen" + gen + " as it does not match a mc version"); + OrnitheMeta.LOGGER.info("Removing {} from v3 feather gen{} as it does not match a mc version", o.getGameVersion(), gen); return true; } return false; @@ -248,7 +248,7 @@ private void loadMcData() throws IOException { return false; } } - System.out.println("Removing " + o.getGameVersion() + " from " + src + " as it does not match a mc version"); + OrnitheMeta.LOGGER.info("Removing {} from {} as it does not match a mc version", o.getGameVersion(), src); return true; }; }; diff --git a/src/main/java/net/ornithemc/meta/data/VersionDatabaseOld.java b/src/main/java/net/ornithemc/meta/data/VersionDatabaseOld.java index 141d860..60e52c2 100644 --- a/src/main/java/net/ornithemc/meta/data/VersionDatabaseOld.java +++ b/src/main/java/net/ornithemc/meta/data/VersionDatabaseOld.java @@ -18,6 +18,7 @@ package net.ornithemc.meta.data; +import net.ornithemc.meta.OrnitheMeta; import net.ornithemc.meta.utils.MinecraftLauncherMeta; import net.ornithemc.meta.utils.PomParser; import net.ornithemc.meta.web.models.BaseVersion; @@ -63,7 +64,7 @@ public static VersionDatabaseOld generate() throws IOException, XMLStreamExcepti }); database.installer = INSTALLER_PARSER.getMeta(MavenUrlVersion::new, "net.ornithemc:ornithe-installer-old:"); database.loadMcData(); - System.out.println("DB update took " + (System.currentTimeMillis() - start) + "ms"); + OrnitheMeta.LOGGER.info("DB update took {}ms", System.currentTimeMillis() - start); return database; } @@ -88,7 +89,7 @@ private void loadMcData() throws IOException { } if (launcherMeta.getVersions().stream().noneMatch(metaVersion -> metaVersion.getId().equals(iVersion))) { - System.out.println("Removing " + o.getVersion() + " as it is not match an mc version (v2)"); + OrnitheMeta.LOGGER.info("Removing {} as it is not match an mc version (v2)", o.getVersion()); return true; } return false; diff --git a/src/main/java/net/ornithemc/meta/utils/LoaderMetaV2.java b/src/main/java/net/ornithemc/meta/utils/LoaderMetaV2.java index b22dbb5..997d939 100644 --- a/src/main/java/net/ornithemc/meta/utils/LoaderMetaV2.java +++ b/src/main/java/net/ornithemc/meta/utils/LoaderMetaV2.java @@ -43,10 +43,10 @@ public static JsonNode getMeta(LoaderInfoBase loaderInfo) { if (!launcherMetaFile.exists()) { try { String url = String.format("%s%s/%s", VersionDatabaseOld.ORNITHE_MAVEN_URL, path, filename); - System.out.println("Downloading " + url); + OrnitheMeta.LOGGER.info("Downloading {}", url); FileUtils.copyURLToFile(new URL(url), launcherMetaFile); } catch (IOException e) { - e.printStackTrace(); + OrnitheMeta.LOGGER.error(e); return null; } } @@ -54,7 +54,7 @@ public static JsonNode getMeta(LoaderInfoBase loaderInfo) { try { return OrnitheMeta.MAPPER.readTree(new FileReader(launcherMetaFile)); } catch (IOException e) { - e.printStackTrace(); + OrnitheMeta.LOGGER.error(e); return null; } } diff --git a/src/main/java/net/ornithemc/meta/utils/LoaderMetaV3.java b/src/main/java/net/ornithemc/meta/utils/LoaderMetaV3.java index e6033d8..7d17ecc 100644 --- a/src/main/java/net/ornithemc/meta/utils/LoaderMetaV3.java +++ b/src/main/java/net/ornithemc/meta/utils/LoaderMetaV3.java @@ -43,10 +43,10 @@ public static JsonNode getMeta(LoaderInfoBase loaderInfo) { if (!launcherMetaFile.exists()) { try { String url = String.format("%s%s/%s", loaderMavenUrl, path, filename); - System.out.println("Downloading " + url); + OrnitheMeta.LOGGER.info("Downloading {}", url); FileUtils.copyURLToFile(new URL(url), launcherMetaFile); } catch (IOException e) { - e.printStackTrace(); + OrnitheMeta.LOGGER.error(e); return null; } } @@ -54,7 +54,7 @@ public static JsonNode getMeta(LoaderInfoBase loaderInfo) { try { return OrnitheMeta.MAPPER.readTree(new FileReader(launcherMetaFile)); } catch (IOException e) { - e.printStackTrace(); + OrnitheMeta.LOGGER.error(e); return null; } } diff --git a/src/main/resources/tinylog.properties b/src/main/resources/tinylog.properties new file mode 100644 index 0000000..9f96223 --- /dev/null +++ b/src/main/resources/tinylog.properties @@ -0,0 +1,21 @@ +writer1 = console +writer1.level = info +writer1.format = {date} {level}: {message} + +writer2 = rolling file +writer2.level = info +writer2.format = {date} {level}: {class}.{method}()\t{message} +writer2.file = logs/info-{date}.log +writer2.latest = logs/info-latest.log +writer2.policies = startup, size: 10mb +writer2.backups = 100 +writer2.convert = gzip +writer2.writingthread = true + +writer3 = rolling file +writer3.level = warn +writer3.format = {date} {level}: {class}.{method}()\t{message} +writer3.file = logs/warn-{date}.log +writer3.latest = logs/warn-latest.log +writer3.policies = startup, monthly +writer3.writingthread = true \ No newline at end of file