From 06e25f4f042873f5eb14fa588413d76a8e17e4a3 Mon Sep 17 00:00:00 2001 From: Marc Herschel Date: Wed, 8 Jan 2020 16:24:02 +0100 Subject: [PATCH] better logging if omdb api fails internally --- VERSION | 2 +- build.gradle | 2 +- src/main/java/updatetool/Main.java | 5 ++++- .../imdb/ImdbDockerImplementation.java | 18 ++++++++++++++++++ .../java/updatetool/imdb/ImdbOmdbWorker.java | 4 +++- src/main/resources/VERSION | 2 +- 6 files changed, 28 insertions(+), 5 deletions(-) diff --git a/VERSION b/VERSION index e2cac26..b966e81 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.2.3 \ No newline at end of file +1.2.4 \ No newline at end of file diff --git a/build.gradle b/build.gradle index 415c54b..14fb9f6 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { id 'eclipse' } -version = '1.2.3' +version = '1.2.4' sourceCompatibility = '11' new File(projectDir, "VERSION").text = version; diff --git a/src/main/java/updatetool/Main.java b/src/main/java/updatetool/Main.java index 87d44fa..60f8cbb 100644 --- a/src/main/java/updatetool/Main.java +++ b/src/main/java/updatetool/Main.java @@ -30,6 +30,10 @@ public class Main { } } + public static String version() { + return VERSION; + } + public enum Implementations { IMDB_DOCKER("imdb-docker", "Watchdog mode implementation, will update ratings every n hours", @@ -102,7 +106,6 @@ public static void main(String[] args) throws Exception { System.exit(-1); } - Logger.info("Running version: " + VERSION); var constructor = impls.get(0).entry.getConstructor(new Class[0]); constructor.newInstance().invoke(args); } diff --git a/src/main/java/updatetool/imdb/ImdbDockerImplementation.java b/src/main/java/updatetool/imdb/ImdbDockerImplementation.java index 73f74e2..94ec6df 100644 --- a/src/main/java/updatetool/imdb/ImdbDockerImplementation.java +++ b/src/main/java/updatetool/imdb/ImdbDockerImplementation.java @@ -4,6 +4,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayDeque; +import java.util.List; import java.util.Objects; import java.util.Set; import java.util.concurrent.ExecutorService; @@ -11,6 +12,7 @@ import java.util.concurrent.TimeUnit; import java.util.function.Function; import org.tinylog.Logger; +import org.tinylog.configuration.Configuration; import updatetool.Main; import updatetool.api.Implementation; import updatetool.api.JobReport.StatusCode; @@ -36,6 +38,22 @@ public void invoke(String[] args) throws Exception { Objects.requireNonNull(apikeyOmdb, "Environment variable OMDB_API_KEY is not set"); Objects.requireNonNull(data, "Environment variable PLEX_DATA_DIR is not set"); + var levels = List.of("trace", "debug", "info", "error", "warn"); + String logging = System.getenv("LOG_LEVEL"); + + if(logging != null) { + logging = logging.toLowerCase(); + if(levels.contains(logging.toLowerCase())) { + Configuration.set("writer.level", logging); + Configuration.set("writer2.level", logging); + System.out.println("Logging level changed to: " + logging); + } else { + Logger.warn("Ignoring custom log level. Logging level {} not in allowed levels: {}", logging, levels); + } + } + + Logger.info("Running version: {}", Main.version()); + plexdata = Path.of(data); if(!Files.exists(plexdata) && !Files.isDirectory(plexdata)) { diff --git a/src/main/java/updatetool/imdb/ImdbOmdbWorker.java b/src/main/java/updatetool/imdb/ImdbOmdbWorker.java index 77fbd5e..ab3ee6d 100644 --- a/src/main/java/updatetool/imdb/ImdbOmdbWorker.java +++ b/src/main/java/updatetool/imdb/ImdbOmdbWorker.java @@ -66,8 +66,10 @@ public Void call() throws Exception { if(response.statusCode() == 401) throw new RatelimitException(); - if(response.statusCode() != 200 || !result.Response) + if(response.statusCode() != 200 || !result.Response) { + Logger.error("OMDB_API_FAIL := TITLE -> {} | IMDB_ID -> {} | GUID -> {} | RESPONSE_CODE -> {} | RESPONSE_BODY -> {}", item.title, item.imdbId, item.guid, response.statusCode(), response.body()); throw new ApiCallFailedException("API call failed with code " + response.statusCode() + " after + " + RETRY_BEFORE_FAILURE + " attempt(s): " + response.body()); + } int c = counter.incrementAndGet(); if(c % 100 == 0) diff --git a/src/main/resources/VERSION b/src/main/resources/VERSION index e2cac26..b966e81 100644 --- a/src/main/resources/VERSION +++ b/src/main/resources/VERSION @@ -1 +1 @@ -1.2.3 \ No newline at end of file +1.2.4 \ No newline at end of file