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 2008 Sun Microsystems, Inc. 015 * Portions Copyright 2013-2015 ForgeRock AS. 016 */ 017package org.opends.server.loggers; 018 019import java.util.HashMap; 020 021import org.forgerock.i18n.slf4j.LocalizedLogger; 022 023import java.util.HashSet; 024import java.util.List; 025import java.util.Map; 026import java.util.Set; 027 028import org.forgerock.i18n.LocalizableMessage; 029import org.opends.messages.Severity; 030import org.opends.server.admin.std.server.ErrorLogPublisherCfg; 031 032/** 033 * This class defines the set of methods and structures that must be implemented 034 * for a Directory Server error log publisher. 035 * 036 * @param <T> 037 * The type of error log publisher configuration handled by this log 038 * publisher implementation. 039 */ 040@org.opends.server.types.PublicAPI( 041 stability = org.opends.server.types.StabilityLevel.VOLATILE, 042 mayInstantiate = false, mayExtend = true, mayInvoke = false) 043public abstract class ErrorLogPublisher<T extends ErrorLogPublisherCfg> 044 implements LogPublisher<T> 045{ 046 047 private static final LocalizedLogger logger = LocalizedLogger 048 .getLoggerForThisClass(); 049 050 /** 051 * The hash map that will be used to define specific log severities for the 052 * various categories. 053 */ 054 protected Map<String, Set<Severity>> definedSeverities = new HashMap<>(); 055 056 /** 057 * The set of default log severities that will be used if no custom severities 058 * have been defined for the associated category. 059 */ 060 protected Set<Severity> defaultSeverities = new HashSet<>(); 061 062 /** {@inheritDoc} */ 063 @Override 064 public boolean isConfigurationAcceptable(T configuration, 065 List<LocalizableMessage> unacceptableReasons) 066 { 067 // This default implementation does not perform any special 068 // validation. It should be overridden by error log publisher 069 // implementations that wish to perform more detailed validation. 070 return true; 071 } 072 073 /** 074 * Writes a message to the error log using the provided information. 075 * <p> 076 * The category and severity information are used to determine whether to 077 * actually log this message. 078 * <p> 079 * Category is defined using either short name (used for classes in well 080 * defined packages) or fully qualified classname. Conversion to short name is 081 * done automatically when loggers are created, see 082 * {@code LoggingCategoryNames} for list of existing short names. 083 * 084 * @param category 085 * The category of the message, which is either a classname or a 086 * simple category name defined in {@code LoggingCategoryNames} 087 * class. 088 * @param severity 089 * The severity of the message. 090 * @param message 091 * The message to be logged. 092 * @param exception 093 * The exception to be logged. May be {@code null}. 094 */ 095 public abstract void log(String category, Severity severity, 096 LocalizableMessage message, Throwable exception); 097 098 /** 099 * Check if a message should be logged for the provided category and severity. 100 * 101 * @param category 102 * The category of the message, which is either a classname or a 103 * simple category name defined in {@code LoggingCategoryNames} 104 * class. 105 * @param severity 106 * The severity of the message. 107 * @return {@code true} if the message should be logged, {@code false} 108 * otherwise 109 */ 110 public abstract boolean isEnabledFor(String category, Severity severity); 111 112}