ceki 2004/11/02 11:37:19 Modified: docs/css site.css docs HISTORY faq.html . build.xml src/xdocs faq.xml src/java/org/apache/log4j Logger.java Added: tests/src/java/org/apache/log4j/helpers MessageFormatterTest.java tests/src/java/org/apache/log4j/performance LoggingLoop.java Removed: tests/src/java/org/apache/log4j/helpers/mcomposer MessageComposerTest.java Log: - Added new printing methods in Logger with support for message formatting. Updated HISTORY and faq accordingly. - Moved o.a.l.helpers.mcompose.MessageComposerTest to o.a.l.helpers.MessageFormatterTest Updated tests/build.xml accordingly Revision Changes Path 1.4 +4 -0 logging-log4j/docs/css/site.css Index: site.css =================================================================== RCS file: /home/cvs/logging-log4j/docs/css/site.css,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- site.css 20 Sep 2004 19:44:56 -0000 1.3 +++ site.css 2 Nov 2004 19:37:18 -0000 1.4 @@ -65,6 +65,10 @@ border-top: 1px solid #DDDDDD;
border-bottom: 1px solid #DDDDDD; background:#eee; + font-family: Courier, "MS Courier New", Prestige, Everson Monocourrier, monospace; + padding-bottom: 0.5ex; + padding-top: 0.5ex; + padding-left: 2ex; } table.ls { 1.118 +4 -1 logging-log4j/docs/HISTORY Index: HISTORY =================================================================== RCS file: /home/cvs/logging-log4j/docs/HISTORY,v retrieving revision 1.117 retrieving revision 1.118 diff -u -r1.117 -r1.118 --- HISTORY 1 Nov 2004 20:45:50 -0000 1.117 +++ HISTORY 2 Nov 2004 19:37:19 -0000 1.118 @@ -8,7 +8,10 @@ [D] Changes affect a method or property which was previously marked as deprecated. - + - Added new printing methods message supporiting pattern parsing. These new forms + avoid superflous parameter construction and yield a significant performance + increase in case the log statement is disabled. [*] + - Added new ListAppender & ListModelAppender classes to the org.apache.log4j.varia package. These are rather simplistic Appender implementations that store LoggingEvents in an internal buffer (java.util.List and a DefaultListModel respectively) which can 1.2 +35 -0 logging-log4j/docs/faq.html Index: faq.html =================================================================== RCS file: /home/cvs/logging-log4j/docs/faq.html,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- faq.html 20 Sep 2004 19:37:23 -0000 1.1 +++ faq.html 2 Nov 2004 19:37:19 -0000 1.2 @@ -506,6 +506,41 @@ statement. </p> + <h3>Better alternative based on message patterns</h3> + <p>As of log4j version 1.3, there is a significantly more + convenient alternative based on message patterns. Assuming + <code>entry</code> is a non-primitive object, you can write: + </p> + + <p class="source"> + l.debug("The new entry is {}.", entry); + </p> + + <p>After evaluting whether to log or not, and only if the + decision is affirmative, the logger instace will format the + message and replace the '{}' pair with the string value of the + <code>entry</code> parameter within the message pattern. + </p> + + <p>Thus, the following two lines will yield the exact sane + output. However, the second form will perform at least 30 + times faster in case the logger is disabled for DEBUG. + </p> + + <p class="source"> + l.debug("The new entry is "+entry+"."); <br /> + l.debug("The new entry is {}.", entry); + </p> + + <p>A 2 argument variant is also availalble. Thus, you can also + write: + </p> + <p class="source"> + l.debug("The new entry is {}. It replaces {}.", entry, oldEntry); + </p> + + + <div class="question"> <a name="2.4">2.4 Are there any suggested ways for naming loggers?</a> 1.1 logging-log4j/tests/src/java/org/apache/log4j/helpers/MessageFormatterTest.java Index: MessageFormatterTest.java =================================================================== /* * Copyright 1999,2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.log4j.helpers; import org.apache.log4j.helpers.MessageFormatter; import junit.framework.TestCase; /** * @author Ceki Gulcu * */ public class MessageFormatterTest extends TestCase { public void test1Param() { String result; Integer i3 = new Integer(3); result = MessageFormatter.format("Value is {}.", i3); assertEquals("Value is 3.", result); result = MessageFormatter.format("Value is {", i3); assertEquals("Value is {", result); result = MessageFormatter.format("Value is {}.", null); assertEquals("Value is null.", result); result = MessageFormatter.format("{} is larger than 2.", i3); assertEquals("3 is larger than 2.", result); result = MessageFormatter.format("No subst", i3); assertEquals("No subst", result); result = MessageFormatter.format("Incorrect {subst", i3); assertEquals("Incorrect {subst", result); result = MessageFormatter.format("Escaped \\{} subst", i3); assertEquals("Escaped \\{} subst", result); result = MessageFormatter.format("\\{Escaped", i3); assertEquals("\\{Escaped", result); result = MessageFormatter.format("\\{}Escaped", i3); assertEquals("\\{}Escaped", result); } public void test2Param() { String result; Integer i1 = new Integer(1); Integer i2 = new Integer(2); result = MessageFormatter.format("Value {} is larger than {}.", i1, i2); assertEquals("Value 1 is larger than 2.", result); result = MessageFormatter.format("Value {} is larger than {}", i1, i2); assertEquals("Value 1 is larger than 2", result); result = MessageFormatter.format("{}{}", i1, i2); assertEquals("12", result); result = MessageFormatter.format("Val1={}, Val2={", i1, i2); assertEquals("Val1=1, Val2={", result); } } 1.1 logging-log4j/tests/src/java/org/apache/log4j/performance/LoggingLoop.java Index: LoggingLoop.java =================================================================== /* * Copyright 1999,2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.log4j.performance; import org.apache.log4j.Appender; import org.apache.log4j.Level; import org.apache.log4j.Logger; /** * Logs in a loop a number of times and measure the elapsed time. * * @author Ceki Gülcü */ public class LoggingLoop { static int runLength; static int command; static final Logger logger = Logger.getLogger(LoggingLoop.class); static final double MILLION = 1000 * 1000.0; static final int ALL = 0; static final int NOLOG_BAD = 1; static final int NOLOG_BETTER = 2; static final int NOLOG_NOPARAM = 3; static final int LOG_BAD = 4; static final int LOG_BETTER = 5; static final int LOG_NOPARAM = 6; public static void main(String[] args) throws Exception { Logger root = Logger.getRootLogger(); if (args.length == 2) { init(args[0], args[1]); } else { usage("Wrong number of arguments."); } switch(command) { case ALL: case NOLOG_BAD: root.setLevel(Level.OFF); loopBad(); if(command != ALL) break; case NOLOG_BETTER: root.setLevel(Level.OFF); loopBetter(); if(command != ALL) break; case NOLOG_NOPARAM: root.setLevel(Level.OFF); loopNoParam(); if(command != ALL) break; case LOG_BAD: setNullAppender(); loopBad(); if(command != ALL) break; case LOG_BETTER: setNullAppender(); loopBetter(); if(command != ALL) break; case LOG_NOPARAM: setNullAppender(); loopNoParam(); if(command != ALL) break; } } static void usage(String msg) { System.err.println(msg); System.err.println( "Usage: java " + LoggingLoop.class.getName() + " runLength configFile"); System.err.println("\trunLength (integer) is the length of test loop."); System.exit(1); } static void init(String runLengthStr, String commandStr) throws Exception { runLength = Integer.parseInt(runLengthStr); if ("nolog-bad".equalsIgnoreCase(commandStr)) { command = NOLOG_BAD; } else if ("nolog-better".equalsIgnoreCase(commandStr)) { command = NOLOG_BETTER; } else if ("nolog-noparam".equalsIgnoreCase(commandStr)) { command = NOLOG_NOPARAM; } else if ("log-bad".equalsIgnoreCase(commandStr)) { command = LOG_BAD; } else if ("log-better".equalsIgnoreCase(commandStr)) { command = LOG_BETTER; } else if ("log-noparam".equalsIgnoreCase(commandStr)) { command = LOG_NOPARAM; } else if ("all".equalsIgnoreCase(commandStr)) { command = ALL; } } static void setNullAppender() throws Exception { Appender na = new NullAppender(); //ConsoleAppender na = new ConsoleAppender(new PatternLayout()); //Appender na = new FileAppender(new PatternLayout(), "toto.log"); Logger root = Logger.getRootLogger(); root.removeAllAppenders(); root.addAppender(na); root.setLevel(Level.DEBUG); } static void loopBad() { String msg = "Some message of medium length. i = "; for (int i = 0; i < 1000; i++) { //logger.debug(msg + i); } long before = System.currentTimeMillis(); for (int i = 0; i < runLength; i++) { logger.debug(msg + i); } long elapsedTime = System.currentTimeMillis() - before; double average = (elapsedTime * MILLION) / runLength; System.out.println( "Bad loop completed in [" + elapsedTime + "] milliseconds, or [" + average + "] nanoseconds per log."); } static void loopBetter() { String msg = "Some message of medium length. i = {}"; for (int i = 0; i < 1000; i++) { // logger.debug(msg, "x"); } long before = System.currentTimeMillis(); for (int i = 0; i < runLength; i++) { logger.debug(msg, "x"); logger.debug("sad", new Exception()); } long elapsedTime = System.currentTimeMillis() - before; double average = (elapsedTime * MILLION) / runLength; System.out.println( "Better loop completed in [" + elapsedTime + "] milliseconds, or [" + average + "] nanoseconds per log."); } static void loopNoParam() { String msg = "Some message of medium length."; long before = System.currentTimeMillis(); for (int i = 0; i < runLength; i++) { logger.debug(msg); } long elapsedTime = System.currentTimeMillis() - before; double average = (elapsedTime * MILLION) / runLength; System.out.println( "No parameter loop completed in [" + elapsedTime + "] milliseconds, or [" + average + "] nanoseconds per log."); } } 1.113 +7 -49 logging-log4j/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/logging-log4j/build.xml,v retrieving revision 1.112 retrieving revision 1.113 diff -u -r1.112 -r1.113 --- build.xml 27 Oct 2004 12:36:52 -0000 1.112 +++ build.xml 2 Nov 2004 19:37:19 -0000 1.113 @@ -25,6 +25,9 @@ <!-- build/ --> <property name="packaging.dir" value="build"/> + <!-- Deprecation warning? --> + <property name="deprecation" value="on"/> + <!-- Destination for compiled files --> <property name="javac.dest" value="dist/classes"/> @@ -222,7 +225,7 @@ </target> <target name="build" description="Compile all log4j components." - depends="init, build.core, build.lf5, build.examples, + depends="init, build.core, build.examples, build.xml, build.javamail, build.jms, build.jmx, build.avalonFramework, build.servletAPI, build.db, build.chainsaw"/> @@ -231,12 +234,12 @@ <mkdir dir="${javac.dest}" /> <javac srcdir="${java.source.dir}" destdir="${javac.dest}" + deprecation="on" includes="${stem}/**/*.java, org/apache/joran/**/*.java, ${stem}/xml/XMLLayout.java," excludes="misc/*, **/UnitTest*.java, **/StressCategory.java, **/doc-files/*, ${stem}/db/**, - ${stem}/lf5/**, ${stem}/chainsaw/**, ${stem}/xml/**, ${stem}/test/serialization/**, @@ -250,29 +253,14 @@ ${stem}/varia/ExpressionFilter.java, ${stem}/or/jms/*.java, ${stem}/selector/servlet/*.java" - deprecation="${deprecation}" debug="on"> <classpath refid="compile.classpath"/> </javac> </target> <!-- ================================================= --> - <!-- Compile LF5 classes --> + <!-- Compile examples --> <!-- ================================================= --> - <target name="build.lf5" depends="build.core"> - <javac deprecation="${deprecation}" - srcdir="${java.source.dir}" - destdir="${javac.dest}" - includes="${stem}/lf5/**/*.java" - excludes=""> - <classpath refid="compile.classpath"/> - </javac> - - <copy todir="${javac.dest}"> - <fileset dir="${java.source.dir}" includes="${stem}/lf5/**/*.properties"/> - <fileset dir="${java.source.dir}" includes="${stem}/lf5/viewer/images/*"/> - </copy> - </target> <target name="build.examples" depends="build.core"> <mkdir dir="${examples.javac.dest}" /> @@ -465,7 +453,7 @@ <!-- ================================================================= --> <!-- Aactual work is done in the dependencies. --> <!-- ================================================================= --> - <target name="jar" depends="log4j.jar, chainsaw.jar, log4j-lf5.jar"> + <target name="jar" depends="log4j.jar, chainsaw.jar"> </target> <!-- ================================================================= --> @@ -590,36 +578,6 @@ <attribute name="Implementation-Vendor" value="Apache Software Foundation"/> </section> <attribute name="Main-Class" value="org.apache.log4j.chainsaw.LogUI"/> - <attribute name="Class-Path" value="${log4j.jar}"/> - </manifest> - </jar> - </target> - - - <!-- ================================================================= --> - <!-- Create log4j-lf5.jar, excluding everything else --> - <!-- ================================================================= --> - <target name="log4j-lf5.jar" depends="build"> - <delete> - <fileset dir="${jar.dest}"> - <include name="${log4j-lf5.jar}"/> - </fileset> - </delete> - - <jar jarfile="${jar.dest}/${log4j-lf5.jar}" basedir="${javac.dest}" - includes="${stem}/lf5/**/*.class, - ${stem}/lf5/**/*.properties, - ${stem}/lf5/**/*.gif" - excludes="**/UnitTest**"> - - <manifest> - <attribute name="Manifest-version" value="1.0"/> - <section name="org/apache/log4j/"> - <attribute name="Implementation-Title" value="log4j"/> - <attribute name="Implementation-Version" value="${version}"/> - <attribute name="Implementation-Vendor" value="APache Software Foundation"/> - </section> - <attribute name="Main-Class" value="org.apache.log4j.lf5.StartLogFactor5"/> <attribute name="Class-Path" value="${log4j.jar}"/> </manifest> </jar> 1.4 +35 -0 logging-log4j/src/xdocs/faq.xml Index: faq.xml =================================================================== RCS file: /home/cvs/logging-log4j/src/xdocs/faq.xml,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- faq.xml 16 Sep 2004 14:28:18 -0000 1.3 +++ faq.xml 2 Nov 2004 19:37:19 -0000 1.4 @@ -330,6 +330,41 @@ statement. </p> + <h3>Better alternative based on message patterns</h3> + <p>As of log4j version 1.3, there is a significantly more + convenient alternative based on message patterns. Assuming + <code>entry</code> is a non-primitive object, you can write: + </p> + + <p class="source"> + l.debug("The new entry is {}.", entry); + </p> + + <p>After evaluting whether to log or not, and only if the + decision is affirmative, the logger instace will format the + message and replace the '{}' pair with the string value of the + <code>entry</code> parameter within the message pattern. + </p> + + <p>Thus, the following two lines will yield the exact sane + output. However, the second form will perform at least 30 + times faster in case the logger is disabled for DEBUG. + </p> + + <p class="source"> + l.debug("The new entry is "+entry+"."); <br/> + l.debug("The new entry is {}.", entry); + </p> + + <p>A 2 argument variant is also availalble. Thus, you can also + write: + </p> + <p class="source"> + l.debug("The new entry is {}. It replaces {}.", entry, oldEntry); + </p> + + + </answer> </question> 1.25 +353 -19 logging-log4j/src/java/org/apache/log4j/Logger.java Index: Logger.java =================================================================== RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/Logger.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- Logger.java 29 Oct 2004 11:51:45 -0000 1.24 +++ Logger.java 2 Nov 2004 19:37:19 -0000 1.25 @@ -1,12 +1,12 @@ /* * Copyright 1999,2004 The Apache Software Foundation. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,18 +16,24 @@ package org.apache.log4j; +import org.apache.log4j.helpers.MessageFormatter; import org.apache.log4j.spi.LoggerFactory; /** - This is the central class in the log4j package. Most logging - operations, except configuration, are done through this class. - - @since log4j 1.2 - - @author Ceki Gülcü + * This is the central class in the log4j package. Most logging + * operations, except configuration, are done through this class. + * <p> + * + * @author Ceki Gülcü + * @since log4j 1.2 */ public class Logger extends Category { + /** + * The fully qualified name of the Logger class. See also the [EMAIL PROTECTED] #getFQCN} + * method. + */ + private static final String FQCN = Logger.class.getName(); /** * This constructor creates a new <code>Logger</code> instance and sets @@ -40,20 +46,18 @@ * * @param name The name of the logger. */ - protected Logger(String name) { - super(name); - } - - + protected Logger(String name) { + super(name); + } /** - * Retrieve a logger by name. If the named logger already exists, then the - * existing instance will be reutrned. Otherwise, a new instance is created. - * - * <p>By default, loggers do not have a set level but inherit it from their + * Retrieve a logger by name. If the named logger already exists, then the + * existing instance will be reutrned. Otherwise, a new instance is created. + * + * <p>By default, loggers do not have a set level but inherit it from their * ancestors. This is one of the central features of log4j. * </p> - * + * * @param name The name of the logger to retrieve. */ public static Logger getLogger(String name) { @@ -104,6 +108,336 @@ public static Logger getLogger(String name, LoggerFactory factory) { return LogManager.getLogger(name, factory); } + + /** + * Log a message with the <code>TRACE</code> level with message formatting + * done according to the value of <code>messagePattern</code> and + * <code>arg</code> parameters. + * <p> + * This form avoids superflous parameter construction. Whenever possible, + * you should use this form instead of constructing the message parameter + * using string concatenation. + * + * @param messagePattern The message pattern which will be parsed and formatted + * @param arg The argument to replace the formatting element, i,e, + * the '{}' pair within <code>messagePattern</code>. + * @since 1.3 + */ + public void trace(Object messagePattern, Object arg) { + if (repository.isDisabled(Level.TRACE_INT)) { + return; + } + + if (Level.TRACE.isGreaterOrEqual(this.getEffectiveLevel())) { + if (messagePattern instanceof String){ + String msgStr = (String) messagePattern; + msgStr = MessageFormatter.format(msgStr, arg); + forcedLog(FQCN, Level.TRACE, msgStr, null); + } else { + // To be failsafe, we handle the case where 'messagePattern' is not + // a String. Unless the user makes a mistake, this should never happen. + forcedLog(FQCN, Level.TRACE, messagePattern, null); + } + } + } + /** + * Log a message with the <code>TRACE</code> level with message formatting + * done according to the messagePattern and the arguments arg1 and arg2. + * <p> + * This form avoids superflous parameter construction. Whenever possible, + * you should use this form instead of constructing the message parameter + * using string concatenation. + * + * @param messagePattern The message pattern which will be parsed and formatted + * @param arg1 The first argument to replace the first formatting element + * @param arg2 The second argument to replace the second formatting element + * @since 1.3 + */ + public void trace(String messagePattern, Object arg1, Object arg2) { + if (repository.isDisabled(Level.TRACE_INT)) { + return; + } + if (Level.TRACE.isGreaterOrEqual(this.getEffectiveLevel())) { + messagePattern = MessageFormatter.format(messagePattern, arg1, arg2); + forcedLog(FQCN, Level.TRACE, messagePattern, null); + } + } + + /** + * Log a message with the <code>DEBUG</code> level with message formatting + * done according to the value of <code>messagePattern</code> and + * <code>arg</code> parameters. + * <p> + * This form avoids superflous parameter construction. Whenever possible, + * you should use this form instead of constructing the message parameter + * using string concatenation. + * + * @param messagePattern The message pattern which will be parsed and formatted + * @param arg The argument to replace the formatting element, i,e, + * the '{}' pair within <code>messagePattern</code>. + * @since 1.3 + */ + public void debug(Object messagePattern, Object arg) { + if (repository.isDisabled(Level.DEBUG_INT)) { + return; + } + + if (Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel())) { + if (messagePattern instanceof String){ + String msgStr = (String) messagePattern; + msgStr = MessageFormatter.format(msgStr, arg); + forcedLog(FQCN, Level.DEBUG, msgStr, null); + } else { + // To be failsafe, we handle the case where 'messagePattern' is not + // a String. Unless the user makes a mistake, this should never happen. + forcedLog(FQCN, Level.DEBUG, messagePattern, null); + } + } + } + + /** + * Log a message with the <code>DEBUG</code> level with message formatting + * done according to the messagePattern and the arguments arg1 and arg2. + * <p> + * This form avoids superflous parameter construction. Whenever possible, + * you should use this form instead of constructing the message parameter + * using string concatenation. + * + * @param messagePattern The message pattern which will be parsed and formatted + * @param arg1 The first argument to replace the first formatting element + * @param arg2 The second argument to replace the second formatting element + * @since 1.3 + */ + public void debug(String messagePattern, Object arg1, Object arg2) { + if (repository.isDisabled(Level.DEBUG_INT)) { + return; + } + if (Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel())) { + messagePattern = MessageFormatter.format(messagePattern, arg1, arg2); + forcedLog(FQCN, Level.DEBUG, messagePattern, null); + } + } + + /** + * Log a message with the <code>INFO</code> level with message formatting + * done according to the value of <code>messagePattern</code> and + * <code>arg</code> parameters. + * <p> + * This form avoids superflous parameter construction. Whenever possible, + * you should use this form instead of constructing the message parameter + * using string concatenation. + * + * @param messagePattern The message pattern which will be parsed and formatted + * @param arg The argument to replace the formatting element, i,e, + * the '{}' pair within <code>messagePattern</code>. + * @since 1.3 + */ + public void info(Object messagePattern, Object arg) { + if (repository.isDisabled(Level.INFO_INT)) { + return; + } + + if (Level.INFO.isGreaterOrEqual(this.getEffectiveLevel())) { + if (messagePattern instanceof String){ + String msgStr = (String) messagePattern; + msgStr = MessageFormatter.format(msgStr, arg); + forcedLog(FQCN, Level.INFO, msgStr, null); + } else { + // To be failsafe, we handle the case where 'messagePattern' is not + // a String. Unless the user makes a mistake, this should never happen. + forcedLog(FQCN, Level.INFO, messagePattern, null); + } + } + } + + /** + * Log a message with the <code>INFO</code> level with message formatting + * done according to the messagePattern and the arguments arg1 and arg2. + * <p> + * This form avoids superflous parameter construction. Whenever possible, + * you should use this form instead of constructing the message parameter + * using string concatenation. + * + * @param messagePattern The message pattern which will be parsed and formatted + * @param arg1 The first argument to replace the first formatting element + * @param arg2 The second argument to replace the second formatting element + * @since 1.3 + */ + public void info(String messagePattern, Object arg1, Object arg2) { + if (repository.isDisabled(Level.INFO_INT)) { + return; + } + if (Level.INFO.isGreaterOrEqual(this.getEffectiveLevel())) { + messagePattern = MessageFormatter.format(messagePattern, arg1, arg2); + forcedLog(FQCN, Level.INFO, messagePattern, null); + } + } + + /** + * Log a message with the <code>WARN</code> level with message formatting + * done according to the value of <code>messagePattern</code> and + * <code>arg</code> parameters. + * <p> + * This form avoids superflous parameter construction. Whenever possible, + * you should use this form instead of constructing the message parameter + * using string concatenation. + * + * @param messagePattern The message pattern which will be parsed and formatted + * @param arg The argument to replace the formatting element, i,e, + * the '{}' pair within <code>messagePattern</code>. + * @since 1.3 + */ + public void warn(Object messagePattern, Object arg) { + if (repository.isDisabled(Level.WARN_INT)) { + return; + } + + if (Level.WARN.isGreaterOrEqual(this.getEffectiveLevel())) { + if (messagePattern instanceof String){ + String msgStr = (String) messagePattern; + msgStr = MessageFormatter.format(msgStr, arg); + forcedLog(FQCN, Level.WARN, msgStr, null); + } else { + // To be failsafe, we handle the case where 'messagePattern' is not + // a String. Unless the user makes a mistake, this should never happen. + forcedLog(FQCN, Level.WARN, messagePattern, null); + } + } + } + + /** + * Log a message with the <code>WARN</code> level with message formatting + * done according to the messagePattern and the arguments arg1 and arg2. + * <p> + * This form avoids superflous parameter construction. Whenever possible, + * you should use this form instead of constructing the message parameter + * using string concatenation. + * + * @param messagePattern The message pattern which will be parsed and formatted + * @param arg1 The first argument to replace the first formatting element + * @param arg2 The second argument to replace the second formatting element + * @since 1.3 + */ + public void warn(String messagePattern, Object arg1, Object arg2) { + if (repository.isDisabled(Level.WARN_INT)) { + return; + } + if (Level.WARN.isGreaterOrEqual(this.getEffectiveLevel())) { + messagePattern = MessageFormatter.format(messagePattern, arg1, arg2); + forcedLog(FQCN, Level.WARN, messagePattern, null); + } + } + + /** + * Log a message with the <code>ERROR</code> level with message formatting + * done according to the value of <code>messagePattern</code> and + * <code>arg</code> parameters. + * <p> + * This form avoids superflous parameter construction. Whenever possible, + * you should use this form instead of constructing the message parameter + * using string concatenation. + * + * @param messagePattern The message pattern which will be parsed and formatted + * @param arg The argument to replace the formatting element, i,e, + * the '{}' pair within <code>messagePattern</code>. + * @since 1.3 + */ + public void error(Object messagePattern, Object arg) { + if (repository.isDisabled(Level.ERROR_INT)) { + return; + } + + if (Level.ERROR.isGreaterOrEqual(this.getEffectiveLevel())) { + if (messagePattern instanceof String){ + String msgStr = (String) messagePattern; + msgStr = MessageFormatter.format(msgStr, arg); + forcedLog(FQCN, Level.ERROR, msgStr, null); + } else { + // To be failsafe, we handle the case where 'messagePattern' is not + // a String. Unless the user makes a mistake, this should never happen. + forcedLog(FQCN, Level.ERROR, messagePattern, null); + } + } + } + + /** + * Log a message with the <code>ERROR</code> level with message formatting + * done according to the messagePattern and the arguments arg1 and arg2. + * <p> + * This form avoids superflous parameter construction. Whenever possible, + * you should use this form instead of constructing the message parameter + * using string concatenation. + * + * @param messagePattern The message pattern which will be parsed and formatted + * @param arg1 The first argument to replace the first formatting element + * @param arg2 The second argument to replace the second formatting element + * @since 1.3 + */ + public void error(String messagePattern, Object arg1, Object arg2) { + if (repository.isDisabled(Level.ERROR_INT)) { + return; + } + if (Level.ERROR.isGreaterOrEqual(this.getEffectiveLevel())) { + messagePattern = MessageFormatter.format(messagePattern, arg1, arg2); + forcedLog(FQCN, Level.ERROR, messagePattern, null); + } + } + + /** + * Log a message with the <code>FATAL</code> level with message formatting + * done according to the value of <code>messagePattern</code> and + * <code>arg</code> parameters. + * <p> + * This form avoids superflous parameter construction. Whenever possible, + * you should use this form instead of constructing the message parameter + * using string concatenation. + * + * @param messagePattern The message pattern which will be parsed and formatted + * @param arg The argument to replace the formatting element, i,e, + * the '{}' pair within <code>messagePattern</code>. + * @since 1.3 + */ + public void fatal(Object messagePattern, Object arg) { + if (repository.isDisabled(Level.FATAL_INT)) { + return; + } + + if (Level.FATAL.isGreaterOrEqual(this.getEffectiveLevel())) { + if (messagePattern instanceof String){ + String msgStr = (String) messagePattern; + msgStr = MessageFormatter.format(msgStr, arg); + forcedLog(FQCN, Level.FATAL, msgStr, null); + } else { + // To be failsafe, we handle the case where 'messagePattern' is not + // a String. Unless the user makes a mistake, this should never happen. + forcedLog(FQCN, Level.FATAL, messagePattern, null); + } + } + } + + /** + * Log a message with the <code>FATAL</code> level with message formatting + * done according to the messagePattern and the arguments arg1 and arg2. + * <p> + * This form avoids superflous parameter construction. Whenever possible, + * you should use this form instead of constructing the message parameter + * using string concatenation. + * + * @param messagePattern The message pattern which will be parsed and formatted + * @param arg1 The first argument to replace the first formatting element + * @param arg2 The second argument to replace the second formatting element + * @since 1.3 + */ + public void fatal(String messagePattern, Object arg1, Object arg2) { + if (repository.isDisabled(Level.FATAL_INT)) { + return; + } + if (Level.FATAL.isGreaterOrEqual(this.getEffectiveLevel())) { + messagePattern = MessageFormatter.format(messagePattern, arg1, arg2); + forcedLog(FQCN, Level.FATAL, messagePattern, null); + } + } + } // End of class: Logger.java --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]