Author: fmeschbe Date: Thu Oct 29 09:22:22 2009 New Revision: 830870 URL: http://svn.apache.org/viewvc?rev=830870&view=rev Log: 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.
Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java?rev=830870&r1=830869&r2=830870&view=diff ============================================================================== --- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java (original) +++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java Thu Oct 29 09:22:22 2009 @@ -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 )