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-2016 ForgeRock AS. 015 */ 016package org.opends.server.loggers.slf4j; 017 018import java.util.concurrent.ConcurrentHashMap; 019import java.util.concurrent.ConcurrentMap; 020 021import org.slf4j.ILoggerFactory; 022import org.slf4j.Logger; 023 024/** Factory to retrieve an openDJ implementation of SLF4J Logger. */ 025public final class OpenDJLoggerFactory implements ILoggerFactory { 026 private final ConcurrentMap<String, Logger> loggerMap; 027 028 /** Create the factory. */ 029 public OpenDJLoggerFactory() { 030 loggerMap = new ConcurrentHashMap<>(); 031 } 032 033 @Override 034 public Logger getLogger(String name) { 035 if (name.equalsIgnoreCase(Logger.ROOT_LOGGER_NAME)) { 036 name = "org.forgerock"; 037 } 038 039 Logger slf4jLogger = loggerMap.get(name); 040 if (slf4jLogger != null) { 041 return slf4jLogger; 042 } 043 Logger newInstance = new OpenDJLoggerAdapter(name); 044 Logger oldInstance = loggerMap.putIfAbsent(name, newInstance); 045 return oldInstance == null ? newInstance : oldInstance; 046 } 047}