From 40f79be87b4396fef7ed77a4e44eb2e840490e67 Mon Sep 17 00:00:00 2001
From: Fabio Pistolesi <fabio.pistolesi@forgerock.com>
Date: Fri, 17 Jun 2016 16:27:44 +0000
Subject: [PATCH] OPENDJ-2725 Only print the message number as msgID in error logs
---
opendj-server-legacy/src/test/java/org/opends/server/loggers/LoggingCategoryNamesTest.java | 22 ++++-------
opendj-server-legacy/src/main/java/org/opends/server/loggers/TextErrorLogPublisher.java | 5 +-
opendj-server-legacy/src/main/java/org/opends/server/loggers/LoggingCategoryNames.java | 92 ++++++++++++++++++++++------------------------
3 files changed, 54 insertions(+), 65 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/loggers/LoggingCategoryNames.java b/opendj-server-legacy/src/main/java/org/opends/server/loggers/LoggingCategoryNames.java
index e7c9b2a..5e33961 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/loggers/LoggingCategoryNames.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/loggers/LoggingCategoryNames.java
@@ -11,13 +11,12 @@
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions Copyright [year] [name of copyright owner]".
*
- * Copyright 2014-2015 ForgeRock AS.
+ * Copyright 2014-2016 ForgeRock AS.
*/
package org.opends.server.loggers;
-import java.util.Map.Entry;
-import java.util.NavigableMap;
-import java.util.TreeMap;
+import java.util.HashMap;
+import java.util.Map;
/**
* Provides mapping from class names to simple category names used for logging.
@@ -33,82 +32,61 @@
* most case, package name is sufficient to map to a category name. It is
* valid if several entries point to the same category name.
*/
- private static final NavigableMap<String, String> NAMES = new TreeMap<>();
+ private static final Map<String, String> NAMES = new HashMap<>();
+ private static final String DEFAULT_CATEGORY = "NONE";
static
{
// The category used for messages associated with the core server.
- NAMES.put("org.opends.server.core", "CORE");
- NAMES.put("org.forgerock.opendj.ldap", "CORE");
+ NAMES.put("org.opends.messages.core", "CORE");
+ NAMES.put("org.opends.messages.runtime", "CORE");
+ NAMES.put("com.forgerock.opendj.ldap", "CORE");
// The category used for messages associated with server extensions
// (e.g. extended operations, SASL mechanisms, password storage, schemes, password validators, etc.).
- NAMES.put("org.opends.server.extensions", "EXTENSIONS");
+ NAMES.put("org.opends.messages.extension", "EXTENSIONS");
// The category used for messages associated with
// connection and protocol handling (e.g., ASN.1 and LDAP).
- NAMES.put("org.opends.server.protocol", "PROTOCOL");
- NAMES.put("org.forgerock.opendj.io", "PROTOCOL");
+ NAMES.put("org.opends.messages.protocol", "PROTOCOL");
// The category used for messages associated with configuration handling.
- NAMES.put("org.opends.server.config", "CONFIG");
+ NAMES.put("org.opends.messages.config", "CONFIG");
// The category used for messages associated with the server loggers.
- NAMES.put("org.opends.server.loggers", "LOG");
+ NAMES.put("org.opends.messages.logger", "LOG");
// The category used for messages associated with the general server utilities.
- NAMES.put("org.opends.server.util", "UTIL");
+ NAMES.put("org.opends.messages.utility", "UTIL");
// The category used for messages associated with the server schema elements.
- NAMES.put("org.opends.server.schema", "SCHEMA");
- NAMES.put("org.forgerock.opendj.ldap.schema", "SCHEMA");
-
- // The category used for messages associated with the server controls.
- NAMES.put("org.opends.server.controls", "CONTROLS");
- NAMES.put("org.forgerock.opendj.ldap.controls", "CONTROLS");
+ NAMES.put("org.opends.messages.schema", "SCHEMA");
// The category that will be used for messages associated with plugin processing.
- NAMES.put("org.opends.server.plugins", "PLUGIN");
-
- // The category used for messages associated with the JE backend.
- NAMES.put("org.opends.server.backends.jeb", "JEB");
-
- // The category used for messages associated with the pluggable backend.
- NAMES.put("org.opends.server.backends.pluggable", "PLUGGABLE");
-
- // The category used for messages associated with the PDB backend.
- NAMES.put("org.opends.server.backends.pdb", "PDB");
+ NAMES.put("org.opends.messages.plugin", "PLUGIN");
// The category used for messages associated with generic backends.
- NAMES.put("org.opends.server.backends", "BACKEND");
+ NAMES.put("org.opends.messages.backend", "BACKEND");
// The category used for messages associated with tools
- NAMES.put("org.opends.server.tools", "TOOLS");
-
- // The category used for messages associated with upgrade tool
- NAMES.put("org.opends.server.tools.upgrade", "UPGRADE");
+ NAMES.put("org.opends.messages.tool", "TOOLS");
// The category used for messages associated with tasks
- NAMES.put("org.opends.server.tasks", "TASK");
+ NAMES.put("org.opends.messages.task", "TASK");
// The category used for messages associated with Access Control
- NAMES.put("org.opends.server.authorization", "ACCESS_CONTROL");
+ NAMES.put("org.opends.messages.access_control", "ACCESS_CONTROL");
// The category used for messages associated with the administration framework.
- NAMES.put("org.opends.server.admin", "ADMIN");
+ NAMES.put("org.opends.messages.admin", "ADMIN");
// The category used for messages associated with the Synchronization
NAMES.put("org.opends.server.replication", "SYNC");
// The category used for messages associated with quicksetup tools
- NAMES.put("org.opends.quicksetup", "QUICKSETUP");
+ NAMES.put("org.opends.messages.quickSetup", "QUICKSETUP");
// The category used for messages associated with the tool like the offline installer and unintaller.
- NAMES.put("org.opends.quicksetup.offline", "ADMIN_TOOL");
- NAMES.put("org.opends.guitools.uninstaller", "ADMIN_TOOL");
-
- // The category used for messages associated with the dsconfig
- // administration tool.
- NAMES.put("org.opends.admin.ads", "DSCONFIG");
+ NAMES.put("org.opends.messages.admin_tool", "ADMIN_TOOL");
// The category used for messages associated with common audit.
NAMES.put("org.forgerock.audit", "AUDIT");
@@ -125,11 +103,29 @@
*/
public static String getCategoryName(final String className)
{
- final Entry<String, String> entry = NAMES.floorEntry(className);
- if (entry != null && className.startsWith(entry.getKey()))
+ return getCategoryName(className, null);
+ }
+
+ /**
+ * Returns the simple category name corresponding to the provided class name
+ * or a class name if no mapping corresponds.
+ * The returned class name will be {@code fallbackCategory} if the class name is
+ * null.
+ *
+ * @param className
+ * The classname to retrieve the category name from.
+ * @param fallbackCategory
+ * The category to return when className is null.
+ * @return the simple category name, or the provided className if no matching
+ * simple category name is found
+ */
+ public static String getCategoryName(final String className, String fallbackCategory)
+ {
+ if (className == null)
{
- return entry.getValue();
+ return fallbackCategory == null ? DEFAULT_CATEGORY : fallbackCategory;
}
- return className;
+ final String category = NAMES.get(className);
+ return category != null ? category : className;
}
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/loggers/TextErrorLogPublisher.java b/opendj-server-legacy/src/main/java/org/opends/server/loggers/TextErrorLogPublisher.java
index 403522c..a03e19b 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/loggers/TextErrorLogPublisher.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/loggers/TextErrorLogPublisher.java
@@ -448,8 +448,9 @@
}
@Override
- public void log(String category, Severity severity, LocalizableMessage message, Throwable exception)
+ public void log(String source, Severity severity, LocalizableMessage message, Throwable exception)
{
+ String category = LoggingCategoryNames.getCategoryName(message.resourceName(), source);
if (isEnabledFor(category, severity))
{
StringBuilder sb = new StringBuilder()
@@ -460,8 +461,6 @@
.append(" severity=")
.append(severity)
.append(" msgID=")
- .append(message.resourceName())
- .append('.')
.append(message.ordinal())
.append(" msg=")
.append(message.toString());
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/loggers/LoggingCategoryNamesTest.java b/opendj-server-legacy/src/test/java/org/opends/server/loggers/LoggingCategoryNamesTest.java
index ea73a67..4ab6ee8 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/loggers/LoggingCategoryNamesTest.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/loggers/LoggingCategoryNamesTest.java
@@ -11,12 +11,11 @@
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions Copyright [year] [name of copyright owner]".
*
- * Copyright 2014-2015 ForgeRock AS.
+ * Copyright 2014-2016 ForgeRock AS.
*/
package org.opends.server.loggers;
import org.opends.server.DirectoryServerTestCase;
-import org.opends.server.core.DirectoryServer;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@@ -25,17 +24,15 @@
@SuppressWarnings("javadoc")
public class LoggingCategoryNamesTest extends DirectoryServerTestCase
{
- private static final String CORE_PACKAGE = DirectoryServer.class.getPackage().getName();
+ private static final String CORE_PACKAGE = "org.opends.messages.core";
private static final String CORE_PACKAGE_NAME = "CORE";
@DataProvider
public Object[][] matchingNames()
{
return new Object[][] {
- { CORE_PACKAGE },
- { CORE_PACKAGE + ".SomeClass" },
- { CORE_PACKAGE + ".pack1.SomeClass"},
- { CORE_PACKAGE + ".pack1.pack2.SomeClass" },
+ { CORE_PACKAGE, CORE_PACKAGE_NAME },
+ { CORE_PACKAGE_NAME + ".dummy", CORE_PACKAGE_NAME + ".dummy"}
};
}
@@ -53,9 +50,9 @@
}
@Test(dataProvider = "matchingNames")
- public void testMatching(String classname) throws Exception
+ public void testMatching(String classname, String category) throws Exception
{
- assertEquals(LoggingCategoryNames.getCategoryName(classname), CORE_PACKAGE_NAME);
+ assertEquals(LoggingCategoryNames.getCategoryName(classname), category);
}
@Test(dataProvider = "nonMatchingNames")
@@ -65,11 +62,8 @@
}
@Test
- public void testSubPackages() throws Exception
+ public void testNoCategory() throws Exception
{
- assertEquals(LoggingCategoryNames.getCategoryName("org.opends.server.backends.jeb.foo"), "JEB");
- assertEquals(LoggingCategoryNames.getCategoryName("org.opends.server.backends.jeb"), "JEB");
- assertEquals(LoggingCategoryNames.getCategoryName("org.opends.server.backends"), "BACKEND");
- assertEquals(LoggingCategoryNames.getCategoryName("org.opends.server"), "org.opends.server");
+ assertNotNull(LoggingCategoryNames.getCategoryName(null), "Category for null message should be NONE");
}
}
--
Gitblit v1.10.0