From f64239b7d7312ce5ad2f9b2c1de9952fcef761df Mon Sep 17 00:00:00 2001 From: Pascal Christoph Date: Fri, 6 Oct 2023 08:59:49 +0200 Subject: [PATCH] Add another logging destination; switch logger (#1847) - switch to logback - use only one logback.xml config file - introduce logging of ETL to a separate file - change log pattern to be more concise - exclude some logging libraries from dependencies - use adapter "log4j-to-slf4j" to log elasticsearch log4j2 logs - add mnising log messages --- pom.xml | 42 ++++++++++- .../java/de/hbz/lobid/helper/Etikett.java | 2 +- src/main/resources/log4j.xml | 21 ------ src/main/resources/log4j2.xml | 23 ------ src/main/resources/logback.xml | 72 +++++++++++++++++++ .../controllers/resources/WebhookAlmaFix.java | 20 ++++-- web/conf/logback.xml | 46 ------------ 7 files changed, 129 insertions(+), 97 deletions(-) delete mode 100644 src/main/resources/log4j.xml delete mode 100644 src/main/resources/log4j2.xml create mode 100644 src/main/resources/logback.xml delete mode 100644 web/conf/logback.xml diff --git a/pom.xml b/pom.xml index a3897d2e9b..87f3fdb564 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ UTF-8 1.8 4.8.2 - 0.9.30 + 1.3.11 @@ -26,6 +26,12 @@ org.metafacture metafacture-json 5.6.0 + + + commons-logging + commons-logging + + org.metafacture @@ -132,12 +138,26 @@ log4j log4j-api + + commons-logging + commons-logging + + + org.apache.logging.log4j + log4j-api + org.elasticsearch.client transport 5.6.3 + + + commons-logging + commons-logging + + junit @@ -164,6 +184,26 @@ jaxb-api 2.3.0 + + ch.qos.logback + logback-classic + ${logback.version} + + + ch.qos.logback + logback-core + ${logback.version} + + + org.slf4j + slf4j-api + 2.0.9 + + + org.apache.logging.log4j + log4j-to-slf4j + 2.9.0 + diff --git a/src/main/java/de/hbz/lobid/helper/Etikett.java b/src/main/java/de/hbz/lobid/helper/Etikett.java index 23d282e61d..7641d49426 100644 --- a/src/main/java/de/hbz/lobid/helper/Etikett.java +++ b/src/main/java/de/hbz/lobid/helper/Etikett.java @@ -233,4 +233,4 @@ public Map getMultilangLabel() { return multilangLabel; } -} \ No newline at end of file +} diff --git a/src/main/resources/log4j.xml b/src/main/resources/log4j.xml deleted file mode 100644 index 412b596f74..0000000000 --- a/src/main/resources/log4j.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml deleted file mode 100644 index 09de0a31e8..0000000000 --- a/src/main/resources/log4j2.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 0000000000..84513ea5dd --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,72 @@ + + + ./logs/play.log + + + play-log-%d{yyyy-MM-dd}.%i.gz + + 21 + + 100MB + + + %date{yyyy-MM-dd HH:mm:ss ZZZZ} [%level] from %logger{36} - %message%n%xException + + + + + ./logs/etl.log + + + etl-log-%d{yyyy-MM-dd}.%i.gz + + 21 + + 100MB + + + %date{yyyy-MM-dd HH:mm:ss} [%level] %logger{52} in %thread - %message%n%xException + + + + + + %logger{15} - %message%n%xException{10} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/web/app/controllers/resources/WebhookAlmaFix.java b/web/app/controllers/resources/WebhookAlmaFix.java index fe742b1230..f779aaaa4c 100644 --- a/web/app/controllers/resources/WebhookAlmaFix.java +++ b/web/app/controllers/resources/WebhookAlmaFix.java @@ -5,6 +5,7 @@ import com.typesafe.config.Config; import com.typesafe.config.ConfigFactory; import org.lobid.resources.run.AlmaMarcXmlFix2lobidJsonEs; + import play.Logger; import play.mvc.Controller; import play.mvc.Http; @@ -87,19 +88,22 @@ public static Result updateAlma(final String GIVEN_TOKEN) { Logger.error(msg); AlmaMarcXmlFix2lobidJsonEs.sendMail("Triggering of " + ETL_OF + KIND, false, msg); + Logger.warn(msg); return status(500, msg); } } catch (IOException e) { - msg = composeMessage(e.getMessage()); + msg = composeMessage("Problems with data file\n" + e.getMessage()); AlmaMarcXmlFix2lobidJsonEs.sendMail("Triggering of " + ETL_OF + KIND, false, msg); - return status(500, "Problems with data file\n" + msg); + Logger.warn(msg); + return status(500, msg); } if (AlmaMarcXmlFix2lobidJsonEs.threadAlreadyStarted) { msg = composeMessage(String.format(MSG_UPDATE_ALREADY_RUNNING, indexNameOfUpdate)); AlmaMarcXmlFix2lobidJsonEs.sendMail(ETL_OF + KIND, false, msg); + Logger.warn(msg); return status(423, msg); } msg = composeMessage(String.format(msgStartEtl, KIND)); @@ -156,17 +160,21 @@ public static Result basedumpAlma(final String GIVEN_TOKEN) { Logger.error(msg); AlmaMarcXmlFix2lobidJsonEs.sendMail("Triggering of " + ETL_OF + KIND, false, msg); + Logger.warn(msg); return status(500, msg); } } catch (IOException e) { - return status(500, "Problems with data file\n" + e); + msg = composeMessage("IO Problems with data file\n" + e); + Logger.warn(msg); + return status(500, msg); } createIndexNameOfBasedump = indexNameOfBasedump + "-" + LocalDateTime.now() .format(DateTimeFormatter.ofPattern("yyyyMMdd-kkmm")); if (AlmaMarcXmlFix2lobidJsonEs.threadAlreadyStarted) { msg = composeMessage(String.format(MSG_CREATE_INDEX_ALREADY_RUNNING, createIndexNameOfBasedump)); AlmaMarcXmlFix2lobidJsonEs.sendMail(ETL_OF + KIND, false, msg); + Logger.warn(msg); return status(423, msg); } msg = composeMessage(String.format(msgStartEtl, KIND)); @@ -200,29 +208,31 @@ public static Result switchEsAlias(final String GIVEN_TOKEN) { String msg = composeMessage(subject); Logger.info(msg); if (!GIVEN_TOKEN.equals(token)) { - Logger.info("Wrong token: " + GIVEN_TOKEN); return wrongToken(subject, GIVEN_TOKEN); } boolean success; if (AlmaMarcXmlFix2lobidJsonEs.threadAlreadyStarted) { msg = composeMessage(String.format(MSG_CREATE_INDEX_ALREADY_RUNNING, createIndexNameOfBasedump)); AlmaMarcXmlFix2lobidJsonEs.sendMail("Failed: " + subject, false, msg); + Logger.warn(msg); return status(423, msg); } AlmaMarcXmlFix2lobidJsonEs.setSwitchVariables(alias1, alias2, clusterHost, basedumpSwitchMindocs, basedumpSwitchMinsize); success = AlmaMarcXmlFix2lobidJsonEs.switchAlias(); if (success) { msg = composeMessage(AlmaMarcXmlFix2lobidJsonEs.MSG_SUCCESS + subject); + Logger.info(msg); return ok(msg); } msg = composeMessage(AlmaMarcXmlFix2lobidJsonEs.MSG_FAIL + subject); + Logger.warn(msg); return internalServerError(msg); } private static Result wrongToken(final String KIND, final String GIVEN_TOKEN) { String msg = composeMessage(String.format(msgWrongToken, GIVEN_TOKEN, KIND)); - Logger.error(msg); + Logger.warn(msg); AlmaMarcXmlFix2lobidJsonEs.sendMail(KIND, false, msg); return forbidden(msg); } diff --git a/web/conf/logback.xml b/web/conf/logback.xml deleted file mode 100644 index 9a4127b714..0000000000 --- a/web/conf/logback.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - ./logs/application.log - - - application-log-%d{yyyy-MM-dd}.%i.gz - - 21 - - 100MB - - - %date{yyyy-MM-dd HH:mm:ss ZZZZ} [%level] from %logger in %thread - %message%n%xException - - - - - - %coloredLevel %logger{15} - %message%n%xException{10} - - - - - - - - - - - - - - - - - - - - - - - - - -