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.lf4osgi.core; 018 019import org.osgi.framework.Bundle; 020import org.osgi.service.log.LoggerFactory; 021 022/** 023 * A base class for logger facades. 024 */ 025public abstract class AbstractLoggerFacade<T extends LoggerFacade> 026 implements LoggerFacade { 027 028 private final String name; 029 private final LoggerGroup group; 030 031 /** 032 * Instantiates a new logger facade. 033 * <P> 034 * A new logger is automatically registered with the 035 * {@link LoggerFacadeManager}. 036 * 037 * @param group the logger group 038 * @param name the name 039 */ 040 public AbstractLoggerFacade(LoggerGroup group, String name) { 041 this.group = group; 042 this.name = name; 043 LoggerFacadeManager.registerFacade(this); 044 } 045 046 /** 047 * Gets the name. 048 * 049 * @return the name 050 */ 051 public String getName() { 052 return name; 053 } 054 055 /** 056 * Gets the bundle. 057 * 058 * @return the bundle 059 */ 060 protected Bundle getBundle() { 061 return group.getBundle(); 062 } 063 064 /** 065 * Called when the logger factory changes. Derived classes 066 * must update the logger that they had previously obtained. 067 * 068 * @param factory the factory 069 */ 070 public abstract void loggerFactoryUpdated(LoggerFactory factory); 071}