001/* 002 * Copyright (C) 2019 Michael N. Lipp (http://www.mnl.de) 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package de.mnl.osgi.log4j2osgi; 018 019import de.mnl.osgi.lf4osgi.core.LoggerCatalogue; 020import java.net.URI; 021import org.apache.logging.log4j.spi.LoggerContext; 022import org.apache.logging.log4j.spi.LoggerContextFactory; 023import org.osgi.framework.Bundle; 024 025/** 026 * A factory for creating OsgiLoggerContext objects. 027 */ 028public class OsgiLoggerContextFactory extends LoggerCatalogue<OsgiLoggerContext> 029 implements LoggerContextFactory { 030 031 /** 032 * Instantiates a new OSGi logger context factory. 033 */ 034 public OsgiLoggerContextFactory() { 035 super(b -> new OsgiLoggerContext(b)); 036 } 037 038 @Override 039 public OsgiLoggerContext getContext(final String fqcn, 040 final ClassLoader loader, final Object externalContext, 041 final boolean currentContext) { 042 Bundle bundle = LoggerCatalogue.findBundle(fqcn).get(); 043 return getLoggerGoup(bundle); 044 } 045 046 @Override 047 public OsgiLoggerContext getContext(final String fqcn, 048 final ClassLoader loader, 049 final Object externalContext, final boolean currentContext, 050 final URI configLocation, final String name) { 051 return getContext(fqcn, loader, externalContext, currentContext); 052 } 053 054 @Override 055 public void removeContext(final LoggerContext ignored) { 056 // Empty 057 } 058}