View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package org.slf4j.test_osgi;
15  
16  import java.util.ArrayList;
17  import java.util.List;
18  
19  import org.osgi.framework.FrameworkEvent;
20  import org.osgi.framework.FrameworkListener;
21  
22  public class FrameworkErrorListener implements FrameworkListener {
23  
24      public List<FrameworkEvent> errorList = new ArrayList<FrameworkEvent>();
25  
26      public void frameworkEvent(FrameworkEvent fe) {
27          if (fe.getType() == FrameworkEvent.ERROR) {
28              errorList.add(fe);
29          }
30      }
31  
32      private void dump(FrameworkEvent fe) {
33          Throwable t = fe.getThrowable();
34          String tString = null;
35          if (t != null) {
36              tString = t.toString();
37          }
38          System.out.println("Framework ERROR:" + ", source " + fe.getSource() + ", bundle=" + fe.getBundle() + ", ex=" + tString);
39          if (t != null) {
40              t.printStackTrace();
41          }
42      }
43  
44      public void dumpAll() {
45          for (int i = 0; i < errorList.size(); i++) {
46              FrameworkEvent fe = (FrameworkEvent) errorList.get(i);
47              dump(fe);
48          }
49      }
50  }