[java-identity-provider COMMIT] in /trunk/idp-profile-impl/src: main/java/net/shibboleth/idp/profile/impl/WriteAuditL...
noreply at shibboleth.net
noreply at shibboleth.net
Tue Aug 12 14:16:30 EDT 2014
Author: scantor
Date: Tue Aug 12 14:16:30 2014
New Revision: 6416
URL: http://svn.shibboleth.net/view/java-identity-provider?rev=6416&view=rev
Log:
IDP-375 - unit test for audit logger
Added:
trunk/idp-profile-impl/src/test/java/net/shibboleth/idp/profile/impl/WriteAuditLogTest.java (with props)
Modified:
trunk/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/WriteAuditLog.java
Modified: trunk/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/WriteAuditLog.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/WriteAuditLog.java?rev=6416&r1=6415&r2=6416&view=diff
==============================================================================
--- trunk/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/WriteAuditLog.java (original)
+++ trunk/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/WriteAuditLog.java Tue Aug 12 14:16:30 2014
@@ -19,6 +19,7 @@
import java.util.Collection;
import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
import javax.annotation.Nonnull;
@@ -28,6 +29,8 @@
import net.shibboleth.idp.profile.context.AuditContext;
import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotLive;
+import net.shibboleth.utilities.java.support.annotation.constraint.Unmodifiable;
import net.shibboleth.utilities.java.support.component.ComponentSupport;
import net.shibboleth.utilities.java.support.logic.Constraint;
import net.shibboleth.utilities.java.support.logic.ConstraintViolationException;
@@ -40,6 +43,7 @@
import com.google.common.base.Function;
import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
/**
@@ -95,6 +99,15 @@
categoryBase = Constraint.isNotNull(StringSupport.trimOrNull(base),
"Logging category base cannot be null or empty");
+ }
+
+ /**
+ * Get the list of formatting tokens for log entries.
+ *
+ * @return list of formatting tokens
+ */
+ @Nonnull @NonnullElements @NotLive @Unmodifiable public List<String> getFormat() {
+ return ImmutableList.copyOf(format);
}
/**
@@ -125,7 +138,6 @@
field.setLength(0);
inToken = false;
}
-
} else if (ch == '%') {
if (field.length() > 0) {
format.add(field.toString());
@@ -166,16 +178,34 @@
for (final String token : format) {
if (token.startsWith("%")) {
- final Collection<String> values = auditCtx.getFieldValues(token.substring(1));
- for (final String val : values) {
- entry.append(val).append(',');
+ if (token.length() == 1 || token.charAt(1) == '%') {
+ entry.append('%');
+ } else {
+ final Iterator<String> iter = auditCtx.getFieldValues(token.substring(1)).iterator();
+ while (iter.hasNext()) {
+ entry.append(iter.next());
+ if (iter.hasNext()) {
+ entry.append(',');
+ }
+ }
}
} else {
entry.append(token);
}
}
+ filter(entry);
+
LoggerFactory.getLogger(categoryBase + profileRequestContext.getLoggingId()).info(entry.toString());
}
+ /**
+ * Optional override to filter the outgoing log message, does nothing by default.
+ *
+ * @param entry log entry
+ */
+ protected void filter(@Nonnull final StringBuilder entry) {
+
+ }
+
}
More information about the commits
mailing list