summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2021-07-17 22:31:48 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2021-07-17 22:31:48 +0200
commitff1fc09f1c5d974d12fbc14f70bd43ea5469152e (patch)
treecd36f6e612e90f1cdbf878d83d4ea9671cbb2f65
parent46022abb71e2038a145cf54916e709b262ad8b90 (diff)
KB66 Use a MessageLogger for logging.
Change-Id: Ice21e79d23725beb104a3dcf999f5e68960e9435
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/login/LoginResource.java3
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSubscriptionExpirer.java6
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterUnsubscriber.java11
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java5
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java3
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java3
-rw-r--r--src/main/java/eu/mulk/mulkcms2/common/logging/Messages.java31
7 files changed, 37 insertions, 25 deletions
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/login/LoginResource.java b/src/main/java/eu/mulk/mulkcms2/benki/login/LoginResource.java
index 53fbcf6..6ab9c70 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/login/LoginResource.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/login/LoginResource.java
@@ -8,13 +8,10 @@ import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
-import org.jboss.logging.Logger;
@Path("/login")
public class LoginResource {
- private static final Logger log = Logger.getLogger(LoginResource.class);
-
@GET
@Authenticated
public Response getRoot(@HeaderParam("referer") @DefaultValue("/posts") String referer)
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSubscriptionExpirer.java b/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSubscriptionExpirer.java
index a9dda9c..6bc54b8 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSubscriptionExpirer.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSubscriptionExpirer.java
@@ -1,16 +1,14 @@
package eu.mulk.mulkcms2.benki.newsletter;
+import eu.mulk.mulkcms2.common.logging.Messages;
import io.quarkus.scheduler.Scheduled;
import java.time.OffsetDateTime;
import javax.enterprise.context.Dependent;
import javax.transaction.Transactional;
-import org.jboss.logging.Logger;
@Dependent
public class NewsletterSubscriptionExpirer {
- private static final Logger log = Logger.getLogger(NewsletterUnsubscriber.class);
-
@Scheduled(every = "PT1H")
@Transactional
void run() {
@@ -18,7 +16,7 @@ public class NewsletterSubscriptionExpirer {
NewsletterSubscription.delete(
"registrationKey IS NOT NULL AND startDate < ?1", OffsetDateTime.now().minusWeeks(1));
if (subscriptionsDeleted > 0) {
- log.infof("%d expired newsletter subscriptions deleted.", subscriptionsDeleted);
+ Messages.log.expiredSubscriptionsDeleted(subscriptionsDeleted);
}
}
}
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterUnsubscriber.java b/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterUnsubscriber.java
index 89e292e..294127f 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterUnsubscriber.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterUnsubscriber.java
@@ -1,5 +1,6 @@
package eu.mulk.mulkcms2.benki.newsletter;
+import eu.mulk.mulkcms2.common.logging.Messages;
import io.quarkus.mailer.MailTemplate.MailTemplateInstance;
import io.quarkus.qute.CheckedTemplate;
import java.util.concurrent.ExecutionException;
@@ -11,13 +12,10 @@ import javax.transaction.Transactional;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.component.mail.MailMessage;
-import org.jboss.logging.Logger;
@Dependent
public class NewsletterUnsubscriber implements Processor {
- private static final Logger log = Logger.getLogger(NewsletterUnsubscriber.class);
-
@CheckedTemplate
static class Templates {
public static native MailTemplateInstance unsubscribedMail();
@@ -31,7 +29,7 @@ public class NewsletterUnsubscriber implements Processor {
for (var sender : mail.getFrom()) {
if (!(sender instanceof InternetAddress)) {
- log.warnf("Tried to unsubscribe, but not an InternetAddress: %s", sender);
+ Messages.log.unsubscribeBadInternetAddress(sender);
continue;
}
@@ -51,13 +49,12 @@ public class NewsletterUnsubscriber implements Processor {
s.delete();
- log.infof("Unsubscribed: %s (#%d)", s.email, s.id);
+ Messages.log.unsubscribed(s.email, s.id);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw new RuntimeException(e);
}
},
- () ->
- log.warnf("Tried to unsubscribe, but no subscription found: %s", sender.toString()));
+ () -> Messages.log.unsubscribeSubscriptionNotFound(sender));
}
}
}
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java b/src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java
index 6c87096..241f005 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java
@@ -53,7 +53,6 @@ import javax.persistence.criteria.Predicate;
import org.hibernate.Session;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
-import org.jboss.logging.Logger;
@Entity
@Table(name = "posts", schema = "benki")
@@ -61,8 +60,6 @@ import org.jboss.logging.Logger;
@TypeDef(name = "pg_enum", typeClass = PostgreSQLEnumType.class)
public abstract class Post<Text extends PostText<?>> extends PanacheEntityBase {
- private static final Logger log = Logger.getLogger(Post.class);
-
public enum Scope {
top_level,
comment
@@ -344,8 +341,6 @@ public abstract class Post<Text extends PostText<?>> extends PanacheEntityBase {
forwardQuery.setMaxResults(count + 1);
}
- log.debug(forwardQuery.unwrap(org.hibernate.query.Query.class).getQueryString());
-
@CheckForNull Integer prevCursor = null;
@CheckForNull Integer nextCursor = null;
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java
index e1ba1aa..e808b9c 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java
@@ -59,13 +59,10 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.hibernate.Session;
-import org.jboss.logging.Logger;
import org.jsoup.Jsoup;
public abstract class PostResource {
- private static final Logger log = Logger.getLogger(PostResource.class);
-
private static final DateTimeFormatter htmlDateTimeFormatter =
DateTimeFormatter.ISO_OFFSET_DATE_TIME;
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java
index d50cdc5..1622334 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java
@@ -31,15 +31,12 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
-import org.jboss.logging.Logger;
import org.jsoup.Jsoup;
import org.jsoup.safety.Whitelist;
@Path("/wiki")
public class WikiResource {
- private static final Logger log = Logger.getLogger(WikiResource.class);
-
private static final DateTimeFormatter htmlDateFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
private static final DateTimeFormatter humanDateFormatter =
diff --git a/src/main/java/eu/mulk/mulkcms2/common/logging/Messages.java b/src/main/java/eu/mulk/mulkcms2/common/logging/Messages.java
new file mode 100644
index 0000000..8a2d3b1
--- /dev/null
+++ b/src/main/java/eu/mulk/mulkcms2/common/logging/Messages.java
@@ -0,0 +1,31 @@
+package eu.mulk.mulkcms2.common.logging;
+
+import javax.mail.Address;
+import org.jboss.logging.BasicLogger;
+import org.jboss.logging.Logger;
+import org.jboss.logging.Logger.Level;
+import org.jboss.logging.annotations.LogMessage;
+import org.jboss.logging.annotations.Message;
+import org.jboss.logging.annotations.MessageLogger;
+
+@MessageLogger(projectCode = "MLKCMS", length = 5)
+public interface Messages extends BasicLogger {
+
+ Messages log = Logger.getMessageLogger(Messages.class, "eu.mulk.mulkcms2");
+
+ @Message(id = 1, value = "%d expired newsletter subscriptions deleted")
+ @LogMessage(level = Level.INFO)
+ void expiredSubscriptionsDeleted(long expiredSubscriptionCount);
+
+ @Message(id = 2, value = "Tried to unsubscribe, but not an InternetAddress: %s")
+ @LogMessage(level = Level.WARN)
+ void unsubscribeBadInternetAddress(Address senderAddress);
+
+ @Message(id = 3, value = "Unsubscribed: %s (#%d)")
+ @LogMessage(level = Level.INFO)
+ void unsubscribed(String email, int subscriptionId);
+
+ @Message(id = 4, value = "Tried to unsubscribe, but no subscription found: %s")
+ @LogMessage(level = Level.WARN)
+ void unsubscribeSubscriptionNotFound(Address senderAddress);
+}