felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1813537 - in /felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl: Activator.java logger/LoggerUtil.java logger/ScrLogger.java
Date Fri, 27 Oct 2017 13:40:45 GMT
Author: cziegeler
Date: Fri Oct 27 13:40:45 2017
New Revision: 1813537

URL: http://svn.apache.org/viewvc?rev=1813537&view=rev
Log:
FELIX-5457 : [R7] Logger Support. Clean up logging

Removed:
    felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/logger/LoggerUtil.java
Modified:
    felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
    felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/logger/ScrLogger.java

Modified: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/Activator.java?rev=1813537&r1=1813536&r2=1813537&view=diff
==============================================================================
--- felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/Activator.java (original)
+++ felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/Activator.java Fri Oct
27 13:40:45 2017
@@ -27,7 +27,6 @@ import java.util.concurrent.locks.Reentr
 
 import org.apache.felix.scr.impl.config.ScrConfigurationImpl;
 import org.apache.felix.scr.impl.inject.ClassUtils;
-import org.apache.felix.scr.impl.logger.LoggerUtil;
 import org.apache.felix.scr.impl.logger.ScrLogger;
 import org.apache.felix.scr.impl.runtime.ServiceComponentRuntimeImpl;
 import org.apache.felix.utils.extender.AbstractExtender;
@@ -257,7 +256,7 @@ public class Activator extends AbstractE
                 {
                     Thread.currentThread().interrupt();
                     logger.log(LogService.LOG_WARNING,  "The wait for {0} being destroyed
before destruction has been interrupted.", e,
-                            LoggerUtil.getBundleIdentifier(bundle) );
+                            bundle );
                 }
                 loadComponents( ScrExtension.this.bundle );
             }
@@ -285,7 +284,7 @@ public class Activator extends AbstractE
                 {
                     Thread.currentThread().interrupt();
                     logger.log(LogService.LOG_WARNING,  "The wait for {0} being started before
destruction has been interrupted.", e,
-                            LoggerUtil.getBundleIdentifier(bundle) );
+                            bundle );
 
                 }
                 disposeComponents( bundle );
@@ -321,8 +320,7 @@ public class Activator extends AbstractE
         BundleContext context = bundle.getBundleContext();
         if ( context == null )
         {
-            logger.log(LogService.LOG_DEBUG,  "Cannot get BundleContext of {0}.", null,
-                    LoggerUtil.getBundleIdentifier(bundle) );
+            logger.log(LogService.LOG_DEBUG,  "Cannot get BundleContext of {0}.", null, bundle);
 
             return;
         }
@@ -338,7 +336,7 @@ public class Activator extends AbstractE
                 if ( !m_bundle.adapt( BundleRevision.class ).equals( wire.getProvider() )
)
                 {
                     logger.log(LogService.LOG_DEBUG,  "{0} wired to a different extender:
{1}.", null,
-                            LoggerUtil.getBundleIdentifier(bundle), LoggerUtil.getBundleIdentifier(wire.getProvider().getBundle())
);
+                            bundle, wire.getProvider().getBundle());
 
                     return;
                 }
@@ -370,7 +368,7 @@ public class Activator extends AbstractE
         if ( loaded )
         {
             logger.log(LogService.LOG_DEBUG,  "Components for {0} already loaded. Nothing
to do.", null,
-                    LoggerUtil.getBundleIdentifier(bundle) );
+                    bundle );
 
             return;
         }
@@ -399,12 +397,11 @@ public class Activator extends AbstractE
             if ( e instanceof IllegalStateException && bundle.getState() != Bundle.ACTIVE
)
             {
                 logger.log(LogService.LOG_DEBUG,  "{0} has been stopped while trying to activate
its components. Trying again when the bundles gets started again.", e,
-                        LoggerUtil.getBundleIdentifier(bundle) );
+                        bundle );
             }
             else
             {
-                logger.log(LogService.LOG_ERROR,  "Error while loading components of {0}",
e,
-                        LoggerUtil.getBundleIdentifier(bundle) );
+                logger.log(LogService.LOG_ERROR,  "Error while loading components of {0}",
e, bundle);
             }
         }
     }
@@ -431,8 +428,7 @@ public class Activator extends AbstractE
             }
             catch ( Exception e )
             {
-                logger.log(LogService.LOG_ERROR,  "Error while disposing components of {0}",
e,
-                    LoggerUtil.getBundleIdentifier(bundle) );
+                logger.log(LogService.LOG_ERROR,  "Error while disposing components of {0}",
e, bundle);
             }
         }
     }
@@ -442,7 +438,14 @@ public class Activator extends AbstractE
     {
         if ( logger.isLogEnabled(LogService.LOG_DEBUG) )
         {
-            logger.log( LogService.LOG_DEBUG, format(bundle, msg), null );
+            if ( bundle != null )
+            {
+                logger.log( LogService.LOG_DEBUG, "{0} : " + msg, null, bundle );
+            }
+            else
+            {
+                logger.log( LogService.LOG_DEBUG, msg, null );
+            }
         }
     }
 
@@ -451,7 +454,14 @@ public class Activator extends AbstractE
     {
         if ( logger.isLogEnabled(LogService.LOG_WARNING) )
         {
-            logger.log( LogService.LOG_WARNING, format(bundle, msg), t );
+            if ( bundle != null )
+            {
+                logger.log( LogService.LOG_WARNING, "{0} : " + msg, t, bundle );
+            }
+            else
+            {
+                logger.log( LogService.LOG_WARNING, msg, t );
+            }
         }
     }
 
@@ -463,16 +473,4 @@ public class Activator extends AbstractE
             logger.log( LogService.LOG_ERROR, msg, t );
         }
     }
-
-    private String format(final Bundle bundle, final String msg)
-    {
-        if ( bundle != null )
-        {
-            final StringBuilder sb = new StringBuilder();
-            sb.append(LoggerUtil.getBundleIdentifier(bundle));
-            sb.append(": ");
-            sb.append(msg);
-        }
-        return msg;
-    }
 }
\ No newline at end of file

Modified: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/logger/ScrLogger.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/logger/ScrLogger.java?rev=1813537&r1=1813536&r2=1813537&view=diff
==============================================================================
--- felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/logger/ScrLogger.java
(original)
+++ felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/logger/ScrLogger.java
Fri Oct 27 13:40:45 2017
@@ -22,6 +22,7 @@ import java.io.PrintStream;
 import java.text.MessageFormat;
 
 import org.apache.felix.scr.impl.manager.ScrConfiguration;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.log.LogService;
 import org.osgi.util.tracker.ServiceTracker;
@@ -42,10 +43,31 @@ public class ScrLogger
 
     private final String bundleId;
 
+    private static String getBundleIdentifier(final Bundle bundle)
+    {
+        final StringBuilder sb = new StringBuilder("bundle ");
+        // symbolic name might be null
+        if ( bundle.getSymbolicName() != null )
+        {
+            sb.append(bundle.getSymbolicName());
+            sb.append(':');
+            sb.append(bundle.getVersion());
+            sb.append( " (" );
+            sb.append( bundle.getBundleId() );
+            sb.append( ")" );
+        }
+        else
+        {
+            sb.append( bundle.getBundleId() );
+        }
+
+        return sb.toString();
+    }
+
     public ScrLogger(final BundleContext bundleContext, final ScrConfiguration config)
     {
         this.config = config;
-        this.bundleId = LoggerUtil.getBundleIdentifier(bundleContext.getBundle());
+        this.bundleId = getBundleIdentifier(bundleContext.getBundle());
         logServiceTracker = new ServiceTracker<>( bundleContext, LOGSERVICE_CLASS,
null );
         logServiceTracker.open();
     }
@@ -76,7 +98,22 @@ public class ScrLogger
     {
         if ( isLogEnabled( level ) )
         {
-            final String message = MessageFormat.format( pattern, arguments );
+            final String message;
+            if ( arguments == null || arguments.length == 0 )
+            {
+                message = pattern;
+            }
+            else
+            {
+                for(int i=0;i<arguments.length;i++)
+                {
+                    if ( arguments[i] instanceof Bundle )
+                    {
+                        arguments[i] = getBundleIdentifier((Bundle)arguments[i]);
+                    }
+                }
+                message = MessageFormat.format( pattern, arguments );
+            }
             log( level, message, ex );
         }
     }
@@ -153,7 +190,7 @@ public class ScrLogger
             }
             else
             {
-                logger.log( level, message, ex );
+                logger.log( level, this.bundleId + " : " + message, ex );
             }
         }
     }



Mime
View raw message