FELIX-1186 Provide functionality to defer constructing messages until
really logging. The implementation uses the java.text.MessageFormat
class which provides elaborate means to construct messages.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@830870 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java b/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java
index d2cfcbb..f5f60e1 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java
@@ -24,6 +24,7 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.URL;
+import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.Iterator;
@@ -518,6 +519,38 @@
 
 
     /**
+     * Returns <code>true</code> if logging for the given level is enabled.
+     */
+    public boolean isLogEnabled( int level )
+    {
+        return m_logLevel >= level;
+    }
+
+
+    /**
+     * Method to actually emit the log message. If the LogService is available,
+     * the message will be logged through the LogService. Otherwise the message
+     * is logged to stdout (or stderr in case of LOG_ERROR level messages),
+     *
+     * @param level The log level to log the message at
+     * @param pattern The <code>java.text.MessageFormat</code> message format
+     *      string for preparing the message
+     * @param arguments The format arguments for the <code>pattern</code>
+     *      string.
+     * @param ex An optional <code>Throwable</code> whose stack trace is written,
+     *      or <code>null</code> to not log a stack trace.
+     */
+    public void log( int level, String pattern, Object[] arguments, ComponentMetadata metadata, Throwable ex )
+    {
+        if ( isLogEnabled( level ) )
+        {
+            final String message = MessageFormat.format( pattern, arguments );
+            log( level, message, metadata, ex );
+        }
+    }
+
+
+    /**
      * Method to actually emit the log message. If the LogService is available,
      * the message will be logged through the LogService. Otherwise the message
      * is logged to stdout (or stderr in case of LOG_ERROR level messages),
@@ -529,8 +562,7 @@
      */
     public void log( int level, String message, ComponentMetadata metadata, Throwable ex )
     {
-
-        if ( m_logLevel >= level )
+        if ( isLogEnabled( level ) )
         {
             // prepend the metadata name to the message
             if ( metadata != null )