| /******************************************************************************* |
| * Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Pierre Allard, |
| * Regent L'Archeveque - initial API and implementation |
| * |
| * SPDX-License-Identifier: EPL-1.0 |
| *******************************************************************************/ |
| package org.eclipse.apogy.services.logging; |
| |
| import java.io.IOException; |
| import java.net.URL; |
| |
| import org.eclipse.core.runtime.FileLocator; |
| import org.eclipse.core.runtime.Path; |
| import org.osgi.framework.Bundle; |
| import org.osgi.framework.BundleActivator; |
| import org.osgi.framework.BundleContext; |
| import org.slf4j.LoggerFactory; |
| |
| import ch.qos.logback.classic.LoggerContext; |
| import ch.qos.logback.classic.joran.JoranConfigurator; |
| import ch.qos.logback.core.joran.spi.JoranException; |
| |
| public class Activator implements BundleActivator { |
| |
| @Override |
| public void start(BundleContext bundleContext) throws Exception { |
| configureLogbackInBundle(bundleContext.getBundle()); |
| } |
| |
| @Override |
| public void stop(BundleContext bundleContext) throws Exception { |
| } |
| |
| private void configureLogbackInBundle(Bundle bundle) throws JoranException, IOException { |
| LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); |
| JoranConfigurator jc = new JoranConfigurator(); |
| jc.setContext(loggerContext); |
| loggerContext.reset(); |
| |
| // this assumes that the logback.xml file is in the root of the bundle. |
| URL logbackConfigFileUrl = FileLocator.find(bundle, new Path("config/logback.xml"), null); |
| jc.doConfigure(logbackConfigFileUrl.openStream()); |
| } |
| } |