mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Fabio Pistolesi
16.20.2016 40f79be87b4396fef7ed77a4e44eb2e840490e67
OPENDJ-2725 Only print the message number as msgID in error logs

Do not concatenate the class generating the message with its ordinal number, just use the ordinal number, since
field category is already a short name for the class, where it is defined. Otherwise category will display the class of the message.
If nothing is available, as could be the case with raw messages, display NONE as category.
3 files modified
121 ■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/loggers/LoggingCategoryNames.java 94 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/loggers/TextErrorLogPublisher.java 5 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/loggers/LoggingCategoryNamesTest.java 22 ●●●●● patch | view | raw | blame | history
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 entry.getValue();
    return getCategoryName(className, null);
    }
    return className;
  /**
   * 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 fallbackCategory == null ? DEFAULT_CATEGORY : fallbackCategory;
    }
    final String category = NAMES.get(className);
    return category != null ? category : className;
  }
}
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());
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");
  }
}