1 package com.atlassian.plugin.osgi.container.felix;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.felix.framework.Logger;
5 import org.apache.felix.framework.util.FelixConstants;
6 import org.osgi.framework.BundleException;
7
8 import java.util.List;
9 import java.util.Arrays;
10
11
12
13
14 public class FelixLoggerBridge extends Logger {
15 private final Log log;
16
17 private static final List<String> messagesToIgnore = Arrays.asList(
18 "BeanInfo",
19 "sun.beans.editors.",
20 "add an import for 'org.springframework.osgi.service.",
21 "Class 'org.springframework.util.Assert'",
22 "Class '[Lorg.springframework.osgi.service",
23 "org.springframework.core.InfrastructureProxy",
24 "org.springframework.aop.SpringProxy",
25 "org.springframework.aop.IntroductionInfo",
26 "Class 'org.apache.commons.logging.impl.Log4JLogger'",
27 "org.springframework.util.Assert",
28 "org.springframework.osgi.service.importer.ServiceReferenceProxy",
29 "org.springframework.osgi.service.importer.ImportedOsgiServiceProxy",
30 "org.springframework.osgi.service.importer.support.ImportContextClassLoaderEditor",
31 "[Lorg.springframework.osgi.service.importer.OsgiServiceLifecycleListener;Editor"
32 );
33
34 public FelixLoggerBridge(Log log) {
35 this.log = log;
36 setLogLevel(
37 log.isDebugEnabled() ? Logger.LOG_DEBUG :
38 log.isInfoEnabled() ? Logger.LOG_WARNING :
39 Logger.LOG_ERROR);
40 }
41
42 protected void doLog(org.osgi.framework.ServiceReference serviceReference, int level, java.lang.String message, java.lang.Throwable throwable) {
43 if (serviceReference != null)
44 message = "Service " + serviceReference + ": " + message;
45
46 switch (level) {
47 case LOG_DEBUG:
48 log.debug(message);
49 break;
50 case LOG_ERROR:
51 if (throwable != null) {
52 if ((throwable instanceof BundleException) &&
53 (((BundleException) throwable).getNestedException() != null)) {
54 throwable = ((BundleException) throwable).getNestedException();
55 }
56 log.error(message, throwable);
57 } else
58 log.error(message);
59 break;
60 case LOG_INFO:
61 logInfoUnlessLame(message);
62 break;
63 case LOG_WARNING:
64 logInfoUnlessLame(message);
65 break;
66 default:
67 log.debug("UNKNOWN[" + level + "]: " + message);
68 }
69 }
70
71 protected void logInfoUnlessLame(String message)
72 {
73 if (message != null)
74 {
75
76 for (String dumbBit : messagesToIgnore)
77 if (message.contains(dumbBit))
78 return;
79 }
80 log.info(message);
81 }
82 }