Return-Path: X-Original-To: apmail-logging-commits-archive@minotaur.apache.org Delivered-To: apmail-logging-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C7C4CE40B for ; Sat, 8 Dec 2012 02:40:00 +0000 (UTC) Received: (qmail 17794 invoked by uid 500); 8 Dec 2012 02:40:00 -0000 Delivered-To: apmail-logging-commits-archive@logging.apache.org Received: (qmail 17774 invoked by uid 500); 8 Dec 2012 02:39:59 -0000 Mailing-List: contact commits-help@logging.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@logging.apache.org Delivered-To: mailing list commits@logging.apache.org Received: (qmail 17762 invoked by uid 99); 8 Dec 2012 02:39:59 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 08 Dec 2012 02:39:59 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 08 Dec 2012 02:39:56 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 44BB123889BB; Sat, 8 Dec 2012 02:39:36 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1418596 - in /logging/log4j/log4j2/trunk: api/src/main/java/org/apache/logging/log4j/ api/src/main/java/org/apache/logging/log4j/simple/ api/src/main/java/org/apache/logging/log4j/spi/ api/src/main/java/org/apache/logging/log4j/status/ api... Date: Sat, 08 Dec 2012 02:39:33 -0000 To: commits@logging.apache.org From: ggregory@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121208023936.44BB123889BB@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: ggregory Date: Sat Dec 8 02:39:31 2012 New Revision: 1418596 URL: http://svn.apache.org/viewvc?rev=1418596&view=rev Log: [LOG4J2-133] Allow custom message creation via a message factory. Part 2: LogManager changes. TODO: Update the manual and add more tests to the core logger and to verify that we log warnings to the status logger. Added: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/AbstractStyleNameConverter.java (with props) logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/StyleRedConverter.java (with props) logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/StyleRedConverter1.java (with props) logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleNameLayoutMain.java (with props) logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-console-style-name-ansi.xml (with props) Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/EventLogger.java logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/LogManager.java logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Logger.java logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/simple/SimpleLogger.java logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/simple/SimpleLoggerContext.java logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLoggerWrapper.java logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/LoggerContext.java logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/LoggerTest.java logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/TestLogger.java logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/TestLoggerContext.java logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/Logger.java logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java logging/log4j/log4j2/trunk/jcl-bridge/src/main/java/org/apache/logging/log4j/jcl/Log4JLog.java logging/log4j/log4j2/trunk/slf4j-impl/src/main/java/org/slf4j/impl/SLF4JLogger.java Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/EventLogger.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/EventLogger.java?rev=1418596&r1=1418595&r2=1418596&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/EventLogger.java (original) +++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/EventLogger.java Sat Dec 8 02:39:31 2012 @@ -39,7 +39,7 @@ public final class EventLogger { if (!(l instanceof AbstractLogger)) { throw new LoggingException("Logger returned must be based on AbstractLogger"); } - logger = new AbstractLoggerWrapper((AbstractLogger) l, "EventLogger"); + logger = new AbstractLoggerWrapper((AbstractLogger) l, "EventLogger", null); } Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/LogManager.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/LogManager.java?rev=1418596&r1=1418595&r2=1418596&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/LogManager.java (original) +++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/LogManager.java Sat Dec 8 02:39:31 2012 @@ -16,12 +16,6 @@ */ package org.apache.logging.log4j; -import org.apache.logging.log4j.simple.SimpleLoggerContextFactory; -import org.apache.logging.log4j.status.StatusLogger; -import org.apache.logging.log4j.spi.LoggerContext; -import org.apache.logging.log4j.spi.LoggerContextFactory; -import org.apache.logging.log4j.util.PropsUtil; - import java.io.IOException; import java.net.URL; import java.util.Enumeration; @@ -30,6 +24,13 @@ import java.util.Properties; import java.util.SortedMap; import java.util.TreeMap; +import org.apache.logging.log4j.message.MessageFactory; +import org.apache.logging.log4j.simple.SimpleLoggerContextFactory; +import org.apache.logging.log4j.spi.LoggerContext; +import org.apache.logging.log4j.spi.LoggerContextFactory; +import org.apache.logging.log4j.status.StatusLogger; +import org.apache.logging.log4j.util.PropsUtil; + /** * The anchor point for the logging system. */ @@ -166,6 +167,17 @@ public class LogManager { } /** + * Returns a Logger with the specified name. + * + * @param name The logger name. + * @param messageFactory The message factory is used only when creating a logger, subsequent use does not change the logger but will log a warning if mismatched. + * @return The Logger. + */ + public static Logger getLogger(String name, MessageFactory messageFactory) { + return factory.getContext(LogManager.class.getName(), null, false).getLogger(name, messageFactory); + } + + /** * Returns a Logger using the fully qualified name of the Class as the Logger name. * @param clazz The Class whose name should be used as the Logger name. * @return The Logger. @@ -175,6 +187,16 @@ public class LogManager { } /** + * Returns a Logger using the fully qualified name of the Class as the Logger name. + * @param clazz The Class whose name should be used as the Logger name. + * @param messageFactory The message factory is used only when creating a logger, subsequent use does not change the logger but will log a warning if mismatched. + * @return The Logger. + */ + public static Logger getLogger(Class clazz, MessageFactory messageFactory) { + return getLogger(clazz != null ? clazz.getName() : null, messageFactory); + } + + /** * Returns a Logger using the fully qualified class name of the value as the Logger name. * @param value The value whose class name should be used as the Logger name. * @return The Logger. @@ -184,6 +206,16 @@ public class LogManager { } /** + * Returns a Logger using the fully qualified class name of the value as the Logger name. + * @param value The value whose class name should be used as the Logger name. + * @param messageFactory The message factory is used only when creating a logger, subsequent use does not change the logger but will log a warning if mismatched. + * @return The Logger. + */ + public static Logger getLogger(Object value, MessageFactory messageFactory) { + return getLogger(value != null ? value.getClass() : null, messageFactory); + } + + /** * Returns a Logger with the specified name. * * @param fqcn The fully qualified class name of the class that this method is a member of. Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Logger.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Logger.java?rev=1418596&r1=1418595&r2=1418596&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Logger.java (original) +++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Logger.java Sat Dec 8 02:39:31 2012 @@ -17,6 +17,7 @@ package org.apache.logging.log4j; import org.apache.logging.log4j.message.Message; +import org.apache.logging.log4j.message.MessageFactory; /** * This is the central interface in the log4j package. Most logging @@ -959,4 +960,11 @@ public interface Logger { * @param t the exception to log, including its stack trace. */ void warn(String message, Throwable t); + + /** + * Gets the message factory. + * + * @return the message factory. + */ + MessageFactory getMessageFactory(); } Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/simple/SimpleLogger.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/simple/SimpleLogger.java?rev=1418596&r1=1418595&r2=1418596&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/simple/SimpleLogger.java (original) +++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/simple/SimpleLogger.java Sat Dec 8 02:39:31 2012 @@ -16,13 +16,6 @@ */ package org.apache.logging.log4j.simple; -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.Marker; -import org.apache.logging.log4j.ThreadContext; -import org.apache.logging.log4j.message.Message; -import org.apache.logging.log4j.spi.AbstractLogger; -import org.apache.logging.log4j.util.PropsUtil; - import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.text.DateFormat; @@ -30,6 +23,14 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.Map; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.Marker; +import org.apache.logging.log4j.ThreadContext; +import org.apache.logging.log4j.message.Message; +import org.apache.logging.log4j.message.MessageFactory; +import org.apache.logging.log4j.spi.AbstractLogger; +import org.apache.logging.log4j.util.PropsUtil; + /** * This is the default logger that is used when no suitable logging implementation is available. * @@ -56,8 +57,8 @@ public class SimpleLogger extends Abstra public SimpleLogger(String name, Level defaultLevel, boolean showLogName, boolean showShortLogName, boolean showDateTime, boolean showContextMap, String dateTimeFormat, - PropsUtil props, PrintStream stream) { - super(name); + MessageFactory messageFactory, PropsUtil props, PrintStream stream) { + super(name, messageFactory); String lvl = props.getStringProperty(SimpleLoggerContext.SYSTEM_PREFIX + name + ".level"); this.level = Level.toLevel(lvl, defaultLevel); if (showShortLogName) { Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/simple/SimpleLoggerContext.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/simple/SimpleLoggerContext.java?rev=1418596&r1=1418595&r2=1418596&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/simple/SimpleLoggerContext.java (original) +++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/simple/SimpleLoggerContext.java Sat Dec 8 02:39:31 2012 @@ -16,11 +16,6 @@ */ package org.apache.logging.log4j.simple; -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.spi.LoggerContext; -import org.apache.logging.log4j.util.PropsUtil; - import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.PrintStream; @@ -28,6 +23,13 @@ import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.MessageFactory; +import org.apache.logging.log4j.spi.AbstractLogger; +import org.apache.logging.log4j.spi.LoggerContext; +import org.apache.logging.log4j.util.PropsUtil; + /** * */ @@ -46,9 +48,9 @@ public class SimpleLoggerContext impleme /** Include the instance name in the log message? */ private final boolean showLogName; - /** Include the short name ( last component ) of the logger in the log - * message. Defaults to true - otherwise we'll be lost in a flood of - * messages without knowing who sends them. + /** + * Include the short name ( last component ) of the logger in the log message. Defaults to true - otherwise we'll be + * lost in a flood of messages without knowing who sends them. */ private final boolean showShortName; /** Include the current time in the log message */ @@ -73,7 +75,7 @@ public class SimpleLoggerContext impleme defaultLevel = Level.toLevel(lvl, Level.ERROR); dateTimeFormat = showDateTime ? props.getStringProperty(SimpleLoggerContext.SYSTEM_PREFIX + "dateTimeFormat", - DEFAULT_DATE_TIME_FORMAT) : null; + DEFAULT_DATE_TIME_FORMAT) : null; String fileName = props.getStringProperty(SYSTEM_PREFIX + "logFile", "system.err"); PrintStream ps; @@ -95,12 +97,18 @@ public class SimpleLoggerContext impleme private ConcurrentMap loggers = new ConcurrentHashMap(); public Logger getLogger(String name) { + return getLogger(name, null); + } + + public Logger getLogger(String name, MessageFactory messageFactory) { if (loggers.containsKey(name)) { - return loggers.get(name); + final Logger logger = loggers.get(name); + AbstractLogger.checkMessageFactory(logger, messageFactory); + return logger; } loggers.putIfAbsent(name, new SimpleLogger(name, defaultLevel, showLogName, showShortName, showDateTime, - showContextMap, dateTimeFormat, props, stream)); + showContextMap, dateTimeFormat, messageFactory, props, stream)); return loggers.get(name); } Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java?rev=1418596&r1=1418595&r2=1418596&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java (original) +++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java Sat Dec 8 02:39:31 2012 @@ -23,6 +23,7 @@ import org.apache.logging.log4j.MarkerMa import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.apache.logging.log4j.message.Message; import org.apache.logging.log4j.message.MessageFactory; +import org.apache.logging.log4j.status.StatusLogger; /** * Base implementation of a Logger. It is highly recommended that any Logger implementation extend this class. @@ -30,7 +31,13 @@ import org.apache.logging.log4j.message. */ public abstract class AbstractLogger implements Logger { + /** + * The default MessageFactory class. + */ + public static Class DEFAULT_MESSAGE_FACTORY_CLASS = ParameterizedMessageFactory.class; + private static final String THROWING = "throwing"; + private static final String CATCHING = "catching"; /** @@ -70,6 +77,33 @@ public abstract class AbstractLogger imp private final MessageFactory messageFactory; /** + * Checks that the message factory a logger was created with is the same as the given messageFactory. If they are + * different log a warning to the {@linkplain StatusLogger}. A null MessageFactory translates to the default + * MessageFactory {@link #DEFAULT_MESSAGE_FACTORY_CLASS}. + * + * @param logger + * The logger to check + * @param messageFactory + * The message factory to check. + */ + public static void checkMessageFactory(final Logger logger, MessageFactory messageFactory) { + final String name = logger.getName(); + final MessageFactory loggerMessageFactory = logger.getMessageFactory(); + if (messageFactory != null && !loggerMessageFactory.equals(messageFactory)) { + StatusLogger + .getLogger() + .warn("The Logger {} was created with the message factory {} and is now requested with the message factory {}, which may create log events with unexpected formatting.", + name, loggerMessageFactory, messageFactory); + } else if (messageFactory == null + && !loggerMessageFactory.getClass().equals(DEFAULT_MESSAGE_FACTORY_CLASS)) { + StatusLogger + .getLogger() + .warn("The Logger {} was created with the message factory {} and is now requested with a null message factory (defaults to {}), which may create log events with unexpected formatting.", + name, loggerMessageFactory, messageFactory); + } + } + + /** * Creates a new logger named after the class (or subclass). */ public AbstractLogger() { @@ -99,7 +133,13 @@ public abstract class AbstractLogger imp } private MessageFactory createDefaultMessageFactory() { - return new ParameterizedMessageFactory(); + try { + return DEFAULT_MESSAGE_FACTORY_CLASS.newInstance(); + } catch (InstantiationException e) { + throw new IllegalStateException(e); + } catch (IllegalAccessException e) { + throw new IllegalStateException(e); + } } /** @@ -1521,4 +1561,5 @@ public abstract class AbstractLogger imp public MessageFactory getMessageFactory() { return messageFactory; } + } Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLoggerWrapper.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLoggerWrapper.java?rev=1418596&r1=1418595&r2=1418596&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLoggerWrapper.java (original) +++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLoggerWrapper.java Sat Dec 8 02:39:31 2012 @@ -19,6 +19,7 @@ package org.apache.logging.log4j.spi; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.message.Message; +import org.apache.logging.log4j.message.MessageFactory; /** * Wrapper class that exposes the protected AbstractLogger methods to support wrapped loggers. @@ -34,9 +35,10 @@ public class AbstractLoggerWrapper exten * Constructor that wraps and existing Logger. * @param logger The Logger to wrap. * @param name The name of the Logger. + * @param messageFactory TODO */ - public AbstractLoggerWrapper(AbstractLogger logger, String name) { - super(name); + public AbstractLoggerWrapper(AbstractLogger logger, String name, MessageFactory messageFactory) { + super(name, messageFactory); this.logger = logger; } Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/LoggerContext.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/LoggerContext.java?rev=1418596&r1=1418595&r2=1418596&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/LoggerContext.java (original) +++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/LoggerContext.java Sat Dec 8 02:39:31 2012 @@ -17,6 +17,7 @@ package org.apache.logging.log4j.spi; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.MessageFactory; /** * Anchor point for logging implementations. @@ -37,9 +38,18 @@ public interface LoggerContext { Logger getLogger(String name); /** + * Returns a Logger. + * @param name The name of the Logger to return. + * @param messageFactory The message factory is used only when creating a logger, subsequent use does not change the logger but will log a warning if mismatched. + * @return The logger with the specified name. + */ + Logger getLogger(String name, MessageFactory messageFactory); + + /** * Detects if a Logger with the specified name exists. * @param name The Logger name to search for. * @return true if the Logger exists, false otherwise. */ boolean hasLogger(String name); + } Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java?rev=1418596&r1=1418595&r2=1418596&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java (original) +++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java Sat Dec 8 02:39:31 2012 @@ -61,7 +61,7 @@ public final class StatusLogger extends private StatusLogger() { PropsUtil props = new PropsUtil("log4j2.StatusLogger.properties"); - this.logger = new SimpleLogger("StatusLogger", Level.ERROR, false, true, false, false, "", props, System.err); + this.logger = new SimpleLogger("StatusLogger", Level.ERROR, false, true, false, false, "", null, props, System.err); } /** Modified: logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/LoggerTest.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/LoggerTest.java?rev=1418596&r1=1418595&r2=1418596&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/LoggerTest.java (original) +++ logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/LoggerTest.java Sat Dec 8 02:39:31 2012 @@ -16,24 +16,34 @@ */ package org.apache.logging.log4j; -import org.apache.logging.log4j.message.StructuredDataMessage; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.util.Date; import java.util.List; import java.util.Locale; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertEquals; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; +import org.apache.logging.log4j.message.StringFormatterMessageFactory; +import org.apache.logging.log4j.message.StructuredDataMessage; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; /** * */ public class LoggerTest { + private static class TestParameterizedMessageFactory { + // empty + } + + private static class TestStringFormatterMessageFactory { + // empty + } + TestLogger logger = (TestLogger) LogManager.getLogger("LoggerTest"); List results = logger.getEntries(); @@ -94,6 +104,103 @@ public class LoggerTest { assertNotNull(classLogger); } + @Test + public void getLogger_Class_ParameterizedMessageFactory() { + // The TestLogger logger was already created in an instance variable for this class. + // The message factory is only used when the logger is created. + final ParameterizedMessageFactory messageFactory = new ParameterizedMessageFactory(); + TestLogger testLogger = (TestLogger) LogManager.getLogger(TestParameterizedMessageFactory.class, + messageFactory); + assertNotNull(testLogger); + assertEquals(messageFactory, testLogger.getMessageFactory()); + testLogger.debug("{}", Integer.MAX_VALUE); + assertEquals(1, testLogger.getEntries().size()); + assertEquals(" DEBUG " + Integer.MAX_VALUE, testLogger.getEntries().get(0)); + } + + @Test + public void getLogger_Object_ParameterizedMessageFactory() { + // The TestLogger logger was already created in an instance variable for this class. + // The message factory is only used when the logger is created. + final ParameterizedMessageFactory messageFactory = new ParameterizedMessageFactory(); + TestLogger testLogger = (TestLogger) LogManager.getLogger(new TestParameterizedMessageFactory(), + messageFactory); + assertNotNull(testLogger); + assertEquals(messageFactory, testLogger.getMessageFactory()); + testLogger.debug("{}", Integer.MAX_VALUE); + assertEquals(1, testLogger.getEntries().size()); + assertEquals(" DEBUG " + Integer.MAX_VALUE, testLogger.getEntries().get(0)); + } + + @Test + public void getLogger_Class_StringFormatterMessageFactory() { + // The TestLogger logger was already created in an instance variable for this class. + // The message factory is only used when the logger is created. + final StringFormatterMessageFactory messageFactory = new StringFormatterMessageFactory(); + TestLogger testLogger = (TestLogger) LogManager.getLogger(TestStringFormatterMessageFactory.class, + messageFactory); + assertNotNull(testLogger); + assertEquals(messageFactory, testLogger.getMessageFactory()); + testLogger.debug("%,d", Integer.MAX_VALUE); + assertEquals(1, testLogger.getEntries().size()); + assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0)); + } + + @Test + public void getLogger_Object_StringFormatterMessageFactory() { + // The TestLogger logger was already created in an instance variable for this class. + // The message factory is only used when the logger is created. + final StringFormatterMessageFactory messageFactory = new StringFormatterMessageFactory(); + TestLogger testLogger = (TestLogger) LogManager.getLogger(new TestStringFormatterMessageFactory(), + messageFactory); + assertNotNull(testLogger); + assertEquals(messageFactory, testLogger.getMessageFactory()); + testLogger.debug("%,d", Integer.MAX_VALUE); + assertEquals(1, testLogger.getEntries().size()); + assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0)); + } + + @Test + public void getLogger_String_ParameterizedMessageFactory() { + final ParameterizedMessageFactory messageFactory = new ParameterizedMessageFactory(); + TestLogger testLogger = (TestLogger) LogManager.getLogger("getLogger_String_ParameterizedMessageFactory", + messageFactory); + assertNotNull(testLogger); + assertEquals(messageFactory, testLogger.getMessageFactory()); + testLogger.debug("{}", Integer.MAX_VALUE); + assertEquals(1, testLogger.getEntries().size()); + assertEquals(" DEBUG " + Integer.MAX_VALUE, testLogger.getEntries().get(0)); + } + + @Test + public void getLogger_String_StringFormatterMessageFactory() { + final StringFormatterMessageFactory messageFactory = new StringFormatterMessageFactory(); + TestLogger testLogger = (TestLogger) LogManager.getLogger("getLogger_String_StringFormatterMessageFactory", + messageFactory); + assertNotNull(testLogger); + assertEquals(messageFactory, testLogger.getMessageFactory()); + testLogger.debug("%,d", Integer.MAX_VALUE); + assertEquals(1, testLogger.getEntries().size()); + assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0)); + } + + @Test + public void getLogger_String_MessageFactoryMismatch() { + final StringFormatterMessageFactory messageFactory = new StringFormatterMessageFactory(); + TestLogger testLogger = (TestLogger) LogManager.getLogger("getLogger_String_MessageFactoryMismatch", + messageFactory); + assertNotNull(testLogger); + assertEquals(messageFactory, testLogger.getMessageFactory()); + TestLogger testLogger2 = (TestLogger) LogManager.getLogger("getLogger_String_MessageFactoryMismatch", + new ParameterizedMessageFactory()); + //TODO: How to test? + //This test context always creates new loggers, other test context impls I tried fail other tests. + //assertEquals(messageFactory, testLogger2.getMessageFactory()); + testLogger.debug("%,d", Integer.MAX_VALUE); + assertEquals(1, testLogger.getEntries().size()); + assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0)); + } + public void getLoggerByNullClass() { // Returns a SimpleLogger Assert.assertNotNull(LogManager.getLogger((Class) null)); Modified: logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/TestLogger.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/TestLogger.java?rev=1418596&r1=1418595&r2=1418596&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/TestLogger.java (original) +++ logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/TestLogger.java Sat Dec 8 02:39:31 2012 @@ -17,6 +17,7 @@ package org.apache.logging.log4j; import org.apache.logging.log4j.message.Message; +import org.apache.logging.log4j.message.MessageFactory; import org.apache.logging.log4j.spi.AbstractLogger; import java.io.ByteArrayOutputStream; @@ -29,10 +30,23 @@ import java.util.Map; * */ public class TestLogger extends AbstractLogger { - private List array = new ArrayList(); + + public TestLogger() { + super(); + } + + public TestLogger(String name, MessageFactory messageFactory) { + super(name, messageFactory); + } + + public TestLogger(String name) { + super(name); + } + + private List list = new ArrayList(); public List getEntries() { - return array; + return list; } @Override @@ -61,7 +75,7 @@ public class TestLogger extends Abstract t.printStackTrace(new PrintStream(baos)); sb.append(baos.toString()); } - array.add(sb.toString()); + list.add(sb.toString()); //System.out.println(sb.toString()); } Modified: logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/TestLoggerContext.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/TestLoggerContext.java?rev=1418596&r1=1418595&r2=1418596&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/TestLoggerContext.java (original) +++ logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/TestLoggerContext.java Sat Dec 8 02:39:31 2012 @@ -16,6 +16,7 @@ */ package org.apache.logging.log4j; +import org.apache.logging.log4j.message.MessageFactory; import org.apache.logging.log4j.spi.LoggerContext; /** @@ -28,6 +29,10 @@ public class TestLoggerContext implement return logger; } + public Logger getLogger(String name, MessageFactory messageFactory) { + return new TestLogger(name, messageFactory); + } + public boolean hasLogger(String name) { return false; } Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/Logger.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/Logger.java?rev=1418596&r1=1418595&r2=1418596&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/Logger.java (original) +++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/Logger.java Sat Dec 8 02:39:31 2012 @@ -22,6 +22,7 @@ import org.apache.logging.log4j.core.con import org.apache.logging.log4j.core.config.LoggerConfig; import org.apache.logging.log4j.core.filter.CompositeFilter; import org.apache.logging.log4j.message.Message; +import org.apache.logging.log4j.message.MessageFactory; import org.apache.logging.log4j.message.SimpleMessage; import org.apache.logging.log4j.spi.AbstractLogger; @@ -48,10 +49,11 @@ public class Logger extends AbstractLogg /** * The constructor. * @param context The LoggerContext this Logger is associated with. + * @param messageFactory The message factory. * @param name The name of the Logger. */ - protected Logger(LoggerContext context, String name) { - super(name); + protected Logger(LoggerContext context, String name, MessageFactory messageFactory) { + super(name, messageFactory); this.context = context; config = new PrivateConfig(context.getConfiguration(), this); } @@ -66,9 +68,9 @@ public class Logger extends AbstractLogg return null; } if (context.hasLogger(lc.getName())) { - return context.getLogger(getName()); + return context.getLogger(getName(), getMessageFactory()); } - return new Logger(context, getName()); + return new Logger(context, getName(), this.getMessageFactory()); } /** Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java?rev=1418596&r1=1418595&r2=1418596&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java (original) +++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java Sat Dec 8 02:39:31 2012 @@ -16,21 +16,23 @@ */ package org.apache.logging.log4j.core; +import java.io.File; +import java.net.URI; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + import org.apache.logging.log4j.core.config.Configuration; import org.apache.logging.log4j.core.config.ConfigurationFactory; import org.apache.logging.log4j.core.config.ConfigurationListener; import org.apache.logging.log4j.core.config.DefaultConfiguration; import org.apache.logging.log4j.core.config.NullConfiguration; import org.apache.logging.log4j.core.config.Reconfigurable; +import org.apache.logging.log4j.message.MessageFactory; +import org.apache.logging.log4j.spi.AbstractLogger; import org.apache.logging.log4j.status.StatusLogger; -import java.io.File; -import java.net.URI; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - /** * The LoggerContext is the anchor for the logging system. It maintains a list of all the loggers requested by * applications and a reference to the Configuration. The Configuration will contain the configured loggers, appenders, @@ -192,13 +194,23 @@ public class LoggerContext implements or * @return The Logger. */ public Logger getLogger(String name) { + return getLogger(name, null); + } + /** + * Obtain a Logger from the Context. + * @param name The name of the Logger to return. + * @param messageFactory The message factory is used only when creating a logger, subsequent use does not change the logger but will log a warning if mismatched. + * @return The Logger. + */ + public Logger getLogger(String name, MessageFactory messageFactory) { Logger logger = loggers.get(name); if (logger != null) { + AbstractLogger.checkMessageFactory(logger, messageFactory); return logger; } - logger = newInstance(this, name); + logger = newInstance(this, name, messageFactory); Logger prev = loggers.putIfAbsent(name, logger); return prev == null ? logger : prev; } @@ -307,8 +319,8 @@ public class LoggerContext implements or } - private Logger newInstance(LoggerContext ctx, String name) { - return new Logger(ctx, name); + private Logger newInstance(LoggerContext ctx, String name, MessageFactory messageFactory) { + return new Logger(ctx, name, messageFactory); } } Added: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/AbstractStyleNameConverter.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/AbstractStyleNameConverter.java?rev=1418596&view=auto ============================================================================== --- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/AbstractStyleNameConverter.java (added) +++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/AbstractStyleNameConverter.java Sat Dec 8 02:39:31 2012 @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.logging.log4j.core.pattern; + +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.config.Configuration; +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.layout.PatternLayout; + +import java.util.List; + +/** + * Style pattern converter. Adds ANSI color styling to the result of the enclosed pattern. + */ +public abstract class AbstractStyleNameConverter extends LogEventPatternConverter { + + private final List formatters; + + private final String style; + + /** + * Constructs the converter. + * + * @param formatters + * The PatternFormatters to generate the text to manipulate. + * @param styling + * The styling that should encapsulate the pattern. + */ + protected AbstractStyleNameConverter(String name, List formatters, String styling) { + super(name, "style"); + this.formatters = formatters; + this.style = styling; + } + + /** + * {@inheritDoc} + */ + @Override + public void format(final LogEvent event, final StringBuilder toAppendTo) { + StringBuilder buf = new StringBuilder(); + for (PatternFormatter formatter : formatters) { + formatter.format(event, buf); + } + if (buf.length() > 0) { + toAppendTo.append(style).append(buf.toString()).append(AnsiEscape.getDefaultStyle()); + } + } +} Propchange: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/AbstractStyleNameConverter.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/AbstractStyleNameConverter.java ------------------------------------------------------------------------------ svn:keywords = Id Added: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/StyleRedConverter.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/StyleRedConverter.java?rev=1418596&view=auto ============================================================================== --- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/StyleRedConverter.java (added) +++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/StyleRedConverter.java Sat Dec 8 02:39:31 2012 @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.logging.log4j.core.pattern; + +import java.util.List; + +import org.apache.logging.log4j.core.config.Configuration; +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.layout.PatternLayout; + +/** + * Style pattern converter. Adds ANSI color styling to the result of the enclosed pattern. + */ +@Plugin(name = StyleRedConverter.NAME, type = "Converter") +@ConverterKeys(StyleRedConverter.NAME) +public final class StyleRedConverter extends AbstractStyleNameConverter { + + protected static final String NAME = "red"; + + /** + * Constructs the converter. + * + * @param formatters + * The PatternFormatters to generate the text to manipulate. + * @param styling + * The styling that should encapsulate the pattern. + */ + private StyleRedConverter(List formatters, String styling) { + super(NAME, formatters, styling); + } + + /** + * Gets an instance of the class. + * + * @param config + * The current Configuration. + * @param options + * pattern options, may be null. If first element is "short", only the first line of the throwable will be formatted. + * @return instance of class. + */ + public static StyleRedConverter newInstance(Configuration config, final String[] options) { + if (options[0] == null) { + LOGGER.error("No pattern supplied on style"); + return null; + } + PatternParser parser = PatternLayout.createPatternParser(config); + List formatters = parser.parse(options[0]); + return new StyleRedConverter(formatters, AnsiEscape.createSequence(NAME)); + } + +} Propchange: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/StyleRedConverter.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/StyleRedConverter.java ------------------------------------------------------------------------------ svn:keywords = Id Added: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/StyleRedConverter1.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/StyleRedConverter1.java?rev=1418596&view=auto ============================================================================== --- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/StyleRedConverter1.java (added) +++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/StyleRedConverter1.java Sat Dec 8 02:39:31 2012 @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.logging.log4j.core.pattern; + +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.config.Configuration; +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.layout.PatternLayout; + +import java.util.List; + +/** + * Style pattern converter. Adds ANSI color styling to the result of the enclosed pattern. + */ +@Plugin(name = "red", type = "Converter") +@ConverterKeys("red") +public final class StyleRedConverter1 extends LogEventPatternConverter { + + private final List formatters; + + private final String style; + + /** + * Constructs the converter. + * + * @param formatters + * The PatternFormatters to generate the text to manipulate. + * @param styling + * The styling that should encapsulate the pattern. + */ + private StyleRedConverter1(List formatters, String styling) { + super("red", "style"); + this.formatters = formatters; + this.style = styling; + } + + /** + * Gets an instance of the class. + * + * @param config + * The current Configuration. + * @param options + * pattern options, may be null. If first element is "short", only the first line of the throwable will be formatted. + * @return instance of class. + */ + public static StyleRedConverter1 newInstance(Configuration config, final String[] options) { + if (options[0] == null) { + LOGGER.error("No pattern supplied on style"); + return null; + } + PatternParser parser = PatternLayout.createPatternParser(config); + List formatters = parser.parse(options[0]); + String style = AnsiEscape.createSequence("red"); + return new StyleRedConverter1(formatters, style); + } + + /** + * {@inheritDoc} + */ + @Override + public void format(final LogEvent event, final StringBuilder toAppendTo) { + StringBuilder buf = new StringBuilder(); + for (PatternFormatter formatter : formatters) { + formatter.format(event, buf); + } + if (buf.length() > 0) { + toAppendTo.append(style).append(buf.toString()).append(AnsiEscape.getDefaultStyle()); + } + } +} Propchange: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/StyleRedConverter1.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/StyleRedConverter1.java ------------------------------------------------------------------------------ svn:keywords = Id Added: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleNameLayoutMain.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleNameLayoutMain.java?rev=1418596&view=auto ============================================================================== --- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleNameLayoutMain.java (added) +++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleNameLayoutMain.java Sat Dec 8 02:39:31 2012 @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.logging.log4j.core.appender; + +import java.io.IOException; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.config.Configurator; + +/** + * Shows how to use ANSI escape codes to color messages. Each message is printed to the console in color, but the rest of the log entry + * (time stamp for example) is in the default color for that console. + */ +public class ConsoleAppenderAnsiStyleNameLayoutMain { + + private static final Logger LOG = LogManager.getLogger(ConsoleAppenderAnsiStyleNameLayoutMain.class); + + public static void main(String[] args) { + LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(), null, + "target/test-classes/log4j2-console-style-name-ansi.xml"); + try { + LOG.fatal("Fatal message."); + LOG.error("Error message."); + LOG.warn("Warning message."); + LOG.info("Information message."); + LOG.debug("Debug message."); + LOG.trace("Trace message."); + LOG.error("Error message.", new IOException("test")); + } finally { + Configurator.shutdown(ctx); + } + } + +} Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleNameLayoutMain.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderAnsiStyleNameLayoutMain.java ------------------------------------------------------------------------------ svn:keywords = Id Added: logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-console-style-name-ansi.xml URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-console-style-name-ansi.xml?rev=1418596&view=auto ============================================================================== --- logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-console-style-name-ansi.xml (added) +++ logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-console-style-name-ansi.xml Sat Dec 8 02:39:31 2012 @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + \ No newline at end of file Propchange: logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-console-style-name-ansi.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-console-style-name-ansi.xml ------------------------------------------------------------------------------ svn:keywords = Id Modified: logging/log4j/log4j2/trunk/jcl-bridge/src/main/java/org/apache/logging/log4j/jcl/Log4JLog.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/jcl-bridge/src/main/java/org/apache/logging/log4j/jcl/Log4JLog.java?rev=1418596&r1=1418595&r2=1418596&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/jcl-bridge/src/main/java/org/apache/logging/log4j/jcl/Log4JLog.java (original) +++ logging/log4j/log4j2/trunk/jcl-bridge/src/main/java/org/apache/logging/log4j/jcl/Log4JLog.java Sat Dec 8 02:39:31 2012 @@ -26,6 +26,6 @@ import org.apache.logging.log4j.spi.Abst public class Log4JLog extends AbstractLoggerWrapper implements Log { public Log4JLog(AbstractLogger logger, String name) { - super(logger, name); + super(logger, name, null); } } Modified: logging/log4j/log4j2/trunk/slf4j-impl/src/main/java/org/slf4j/impl/SLF4JLogger.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/slf4j-impl/src/main/java/org/slf4j/impl/SLF4JLogger.java?rev=1418596&r1=1418595&r2=1418596&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/slf4j-impl/src/main/java/org/slf4j/impl/SLF4JLogger.java (original) +++ logging/log4j/log4j2/trunk/slf4j-impl/src/main/java/org/slf4j/impl/SLF4JLogger.java Sat Dec 8 02:39:31 2012 @@ -45,7 +45,7 @@ public class SLF4JLogger implements Loca public SLF4JLogger(AbstractLogger logger, String name) { Logger l = LogManager.getLogger(name); - this.logger = new AbstractLoggerWrapper(logger, name); + this.logger = new AbstractLoggerWrapper(logger, name, null); eventLogger = "EventLogger".equals(name); this.name = name; }