You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2018/09/22 06:23:07 UTC

[2/6] logging-log4j-audit git commit: [LOG4J2-2417] reuse maxLength extraction routine

[LOG4J2-2417] reuse maxLength extraction routine


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/commit/3e3bf9d3
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/tree/3e3bf9d3
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/diff/3e3bf9d3

Branch: refs/heads/master
Commit: 3e3bf9d34f5468d474924c2a07e8865893831347
Parents: 882d45a
Author: Andrei Ivanov <an...@arnia.ro>
Authored: Mon Sep 17 14:57:59 2018 +0300
Committer: Andrei Ivanov <an...@arnia.ro>
Committed: Mon Sep 17 14:57:59 2018 +0300

----------------------------------------------------------------------
 .../org/apache/logging/log4j/audit/LogEventFactory.java   | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/3e3bf9d3/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/LogEventFactory.java
----------------------------------------------------------------------
diff --git a/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/LogEventFactory.java b/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/LogEventFactory.java
index 1b2f9ac..d275335 100644
--- a/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/LogEventFactory.java
+++ b/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/LogEventFactory.java
@@ -92,8 +92,7 @@ public class LogEventFactory {
 		Class<?>[] interfaces = new Class<?>[] { intrface };
 
         String eventId = NamingUtils.lowerFirst(intrface.getSimpleName());
-        MaxLength maxLength = intrface.getAnnotation(MaxLength.class);
-        int msgLength = maxLength == null ? DEFAULT_MAX_LENGTH : maxLength.value();
+        int msgLength = getMaxLength(intrface);
         AuditMessage msg = new AuditMessage(eventId, msgLength);
 		AuditEvent audit = (AuditEvent) Proxy.newProxyInstance(intrface
 				.getClassLoader(), interfaces, new AuditProxy(msg, intrface));
@@ -101,6 +100,11 @@ public class LogEventFactory {
 		return (T) audit;
 	}
 
+    private static <T> int getMaxLength(Class<T> intrface) {
+        MaxLength maxLength = intrface.getAnnotation(MaxLength.class);
+        return maxLength == null ? DEFAULT_MAX_LENGTH : maxLength.value();
+    }
+
     /**
      *
      * This method is used to construct and AuditMessage from a set of properties and the Event interface
@@ -124,7 +128,7 @@ public class LogEventFactory {
         validateContextConstraints(intrface, errors);
 
         String eventId = NamingUtils.lowerFirst(intrface.getSimpleName());
-        int maxLength = intrface.getAnnotation(MaxLength.class).value();
+        int maxLength = getMaxLength(intrface);
         AuditMessage msg = new AuditMessage(eventId, maxLength);
         List<Property> props = getProperties(intrface);
         Map<String, Property> propertyMap = new HashMap<>();