Skip to content

Commit

Permalink
Add another logging destination (#1847)
Browse files Browse the repository at this point in the history
Introduces logging of ETL to a separate file.
  • Loading branch information
dr0i committed Oct 6, 2023
1 parent 694446f commit 82939e8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.3.11</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.3.11</version>
</dependency>
</dependencies>
<build>
<resources>
Expand Down
21 changes: 12 additions & 9 deletions web/app/controllers/resources/WebhookAlmaFix.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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;
import play.mvc.Result;
Expand All @@ -20,6 +19,9 @@
import java.util.List;
import java.util.Objects;

import ch.qos.logback.classic.Logger;
import org.slf4j.LoggerFactory;

/**
* Webhook listener starting update/basedump process for the Alma Fix ETL. Also use
* to switch ES index alias. Reloads "webhook" configs dynamically, i.e. every
Expand Down Expand Up @@ -55,6 +57,7 @@ public class WebhookAlmaFix extends Controller {
+ MSG_ETL_PROCESS_IS_ALREADY_RUNNING;
private static final String MSG_CALLED_FROM_REMOTE_ADDRESS = "Called from: '%s' ";
private static final String FIX_FILENAME = "conf/alma/alma.fix";
private static final Logger etl = (ch.qos.logback.classic.Logger)LoggerFactory.getLogger(WebhookAlmaFix.class);
// If null, create default values from Global settings
public static String clusterHost = null;
public static String clusterName = null;
Expand Down Expand Up @@ -84,7 +87,7 @@ public static Result updateAlma(final String GIVEN_TOKEN) {
try {
msg = composeMessage(MSG_FILE_TOO_SMALL);
if (Files.size(Paths.get(filenameUpdate.split(";")[0])) < 512) {
Logger.error(msg);
etl.error(msg);
AlmaMarcXmlFix2lobidJsonEs.sendMail("Triggering of " + ETL_OF + KIND, false,
msg);
return status(500, msg);
Expand All @@ -103,7 +106,7 @@ public static Result updateAlma(final String GIVEN_TOKEN) {
return status(423, msg);
}
msg = composeMessage(String.format(msgStartEtl, KIND));
Logger.info(msg);
etl.info(msg);
AlmaMarcXmlFix2lobidJsonEs.setKindOfEtl(KIND);
AlmaMarcXmlFix2lobidJsonEs.setSwitchAliasAfterETL(false);
AlmaMarcXmlFix2lobidJsonEs.main(filenameUpdate, indexNameOfUpdate,
Expand All @@ -117,7 +120,7 @@ public static Result updateAlma(final String GIVEN_TOKEN) {

private static void reloadConfigs() {
Config config = ConfigFactory.parseFile(new File(RESOURCES_CONF)).resolve();
Logger.info("reload configs:" + RESOURCES_CONF);
etl.info("reload configs:" + RESOURCES_CONF);
filenameUpdate = config.getString("webhook.alma.update.filename");
filenameBasedump = config.getString("webhook.alma.basedump.filename");
indexNameOfBasedump = config.getString("webhook.alma.basedump.indexname");
Expand Down Expand Up @@ -153,7 +156,7 @@ public static Result basedumpAlma(final String GIVEN_TOKEN) {
try {
if (Files.size(Paths.get(filenameBasedump)) < 512) {
msg = composeMessage(MSG_FILE_TOO_SMALL);
Logger.error(msg);
etl.error(msg);
AlmaMarcXmlFix2lobidJsonEs.sendMail("Triggering of " + ETL_OF + KIND, false,
msg);
return status(500, msg);
Expand All @@ -170,7 +173,7 @@ public static Result basedumpAlma(final String GIVEN_TOKEN) {
return status(423, msg);
}
msg = composeMessage(String.format(msgStartEtl, KIND));
Logger.info(msg);
etl.info(msg);
AlmaMarcXmlFix2lobidJsonEs.setKindOfEtl(KIND);
if (basedumpSwitchAutomatically.equals("true")) {
AlmaMarcXmlFix2lobidJsonEs.setSwitchAliasAfterETL(true);
Expand Down Expand Up @@ -198,9 +201,9 @@ public static Result switchEsAlias(final String GIVEN_TOKEN) {
reloadConfigs();
String subject = "switch aliases '" + alias1 + "' with '" + alias2 + "'";
String msg = composeMessage(subject);
Logger.info(msg);
etl.info(msg);
if (!GIVEN_TOKEN.equals(token)) {
Logger.info("Wrong token: " + GIVEN_TOKEN);
etl.info("Wrong token: " + GIVEN_TOKEN);
return wrongToken(subject, GIVEN_TOKEN);
}
boolean success;
Expand All @@ -222,7 +225,7 @@ public static Result switchEsAlias(final String GIVEN_TOKEN) {
private static Result wrongToken(final String KIND,
final String GIVEN_TOKEN) {
String msg = composeMessage(String.format(msgWrongToken, GIVEN_TOKEN, KIND));
Logger.error(msg);
etl.error(msg);
AlmaMarcXmlFix2lobidJsonEs.sendMail(KIND, false, msg);
return forbidden(msg);
}
Expand Down
25 changes: 23 additions & 2 deletions web/conf/logback.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<configuration>
<conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<appender name="FILE_APPLICATION" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>./logs/application.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- Daily rollover with compression -->
Expand All @@ -13,6 +13,21 @@
<encoder>
<pattern>%date{yyyy-MM-dd HH:mm:ss ZZZZ} [%level] from %logger in %thread - %message%n%xException</pattern>
</encoder>
</appender>

<appender name="FILE_ETL" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>./logs/etl.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- Daily rollover with compression -->
<fileNamePattern>etl-log-%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
<!-- keep 3 weeks worth of history -->
<maxHistory>21</maxHistory>
<!-- roll log file > 100MB -->
<maxFileSize>100MB</maxFileSize>
</rollingPolicy>
<encoder>
<pattern>%date{yyyy-MM-dd HH:mm:ss ZZZZ} [%level] from %logger in %thread - %message%n%xException</pattern>
</encoder>
</appender>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
Expand All @@ -22,7 +37,7 @@
</appender>

<appender name="ASYNCFILE" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="FILE" />
<appender-ref ref="FILE_APPLICATION" />
</appender>

<appender name="ASYNCSTDOUT" class="ch.qos.logback.classic.AsyncAppender">
Expand All @@ -35,6 +50,12 @@
<logger name="com.avaje.ebeaninternal.server.lib.BackgroundThread" level="OFF" />
<logger name="com.gargoylesoftware.htmlunit.javascript" level="OFF" />

<logger name="play" level="INFO" />
<logger name="application" level="INFO" />
<logger name="etl" level="INFO" >
<appender-ref ref="FILE_ETL" />
</logger>

<root level="INFO">
<appender-ref ref="ASYNCFILE" />
<appender-ref ref="ASYNCSTDOUT" />
Expand Down

0 comments on commit 82939e8

Please sign in to comment.