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;
020
021import java.net.URI;
022
023import org.apache.logging.log4j.spi.LoggerContext;
024import org.apache.logging.log4j.spi.LoggerContextFactory;
025import org.osgi.framework.Bundle;
026
027public class OsgiLoggerContextFactory extends LoggerCatalogue<OsgiLoggerContext>
028        implements LoggerContextFactory {
029
030    public OsgiLoggerContextFactory() {
031        super(b -> new OsgiLoggerContext(b));
032    }
033
034    @Override
035    public OsgiLoggerContext getContext(final String fqcn,
036            final ClassLoader loader, final Object externalContext,
037            final boolean currentContext) {
038        Bundle bundle = LoggerCatalogue.findBundle(fqcn).get();
039        return getLoggerGoup(bundle);
040    }
041
042    @Override
043    public OsgiLoggerContext getContext(final String fqcn,
044            final ClassLoader loader,
045            final Object externalContext, final boolean currentContext,
046            final URI configLocation, final String name) {
047        return getContext(fqcn, loader, externalContext, currentContext);
048    }
049
050    @Override
051    public void removeContext(final LoggerContext ignored) {
052    }
053}