001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2014-2015 ForgeRock AS. 015 */ 016package org.opends.server.loggers; 017 018import java.util.Map.Entry; 019import java.util.NavigableMap; 020import java.util.TreeMap; 021 022/** 023 * Provides mapping from class names to simple category names used for logging. 024 * <p> 025 * Given a classname, eg org.forgerock.opendj.server.core.SomeClass, it allows 026 * to get the corresponding simplified category name if it exists, eg "CORE". If 027 * no simplified category name exist, the classname is used as a category name. 028 */ 029public class LoggingCategoryNames 030{ 031 /** 032 * Contains mapping from class names (or package names) to category names. In 033 * most case, package name is sufficient to map to a category name. It is 034 * valid if several entries point to the same category name. 035 */ 036 private static final NavigableMap<String, String> NAMES = new TreeMap<>(); 037 static 038 { 039 // The category used for messages associated with the core server. 040 NAMES.put("org.opends.server.core", "CORE"); 041 NAMES.put("org.forgerock.opendj.ldap", "CORE"); 042 043 // The category used for messages associated with server extensions 044 // (e.g. extended operations, SASL mechanisms, password storage, schemes, password validators, etc.). 045 NAMES.put("org.opends.server.extensions", "EXTENSIONS"); 046 047 // The category used for messages associated with 048 // connection and protocol handling (e.g., ASN.1 and LDAP). 049 NAMES.put("org.opends.server.protocol", "PROTOCOL"); 050 NAMES.put("org.forgerock.opendj.io", "PROTOCOL"); 051 052 // The category used for messages associated with configuration handling. 053 NAMES.put("org.opends.server.config", "CONFIG"); 054 055 // The category used for messages associated with the server loggers. 056 NAMES.put("org.opends.server.loggers", "LOG"); 057 058 // The category used for messages associated with the general server utilities. 059 NAMES.put("org.opends.server.util", "UTIL"); 060 061 // The category used for messages associated with the server schema elements. 062 NAMES.put("org.opends.server.schema", "SCHEMA"); 063 NAMES.put("org.forgerock.opendj.ldap.schema", "SCHEMA"); 064 065 // The category used for messages associated with the server controls. 066 NAMES.put("org.opends.server.controls", "CONTROLS"); 067 NAMES.put("org.forgerock.opendj.ldap.controls", "CONTROLS"); 068 069 // The category that will be used for messages associated with plugin processing. 070 NAMES.put("org.opends.server.plugins", "PLUGIN"); 071 072 // The category used for messages associated with the JE backend. 073 NAMES.put("org.opends.server.backends.jeb", "JEB"); 074 075 // The category used for messages associated with the pluggable backend. 076 NAMES.put("org.opends.server.backends.pluggable", "PLUGGABLE"); 077 078 // The category used for messages associated with the PDB backend. 079 NAMES.put("org.opends.server.backends.pdb", "PDB"); 080 081 // The category used for messages associated with generic backends. 082 NAMES.put("org.opends.server.backends", "BACKEND"); 083 084 // The category used for messages associated with tools 085 NAMES.put("org.opends.server.tools", "TOOLS"); 086 087 // The category used for messages associated with upgrade tool 088 NAMES.put("org.opends.server.tools.upgrade", "UPGRADE"); 089 090 // The category used for messages associated with tasks 091 NAMES.put("org.opends.server.tasks", "TASK"); 092 093 // The category used for messages associated with Access Control 094 NAMES.put("org.opends.server.authorization", "ACCESS_CONTROL"); 095 096 // The category used for messages associated with the administration framework. 097 NAMES.put("org.opends.server.admin", "ADMIN"); 098 099 // The category used for messages associated with the Synchronization 100 NAMES.put("org.opends.server.replication", "SYNC"); 101 102 // The category used for messages associated with quicksetup tools 103 NAMES.put("org.opends.quicksetup", "QUICKSETUP"); 104 105 // The category used for messages associated with the tool like the offline installer and unintaller. 106 NAMES.put("org.opends.quicksetup.offline", "ADMIN_TOOL"); 107 NAMES.put("org.opends.guitools.uninstaller", "ADMIN_TOOL"); 108 109 // The category used for messages associated with the dsconfig 110 // administration tool. 111 NAMES.put("org.opends.admin.ads", "DSCONFIG"); 112 113 // The category used for messages associated with common audit. 114 NAMES.put("org.forgerock.audit", "AUDIT"); 115 } 116 117 /** 118 * Returns the simple category name corresponding to the provided class name 119 * or the class name if no mapping corresponds. 120 * 121 * @param className 122 * The classname to retrieve the category name from. 123 * @return the simple category name, or the provided className if no matching 124 * simple category name is found 125 */ 126 public static String getCategoryName(final String className) 127 { 128 final Entry<String, String> entry = NAMES.floorEntry(className); 129 if (entry != null && className.startsWith(entry.getKey())) 130 { 131 return entry.getValue(); 132 } 133 return className; 134 } 135}