Search in sources :

Example 6 with StringFormatterMessageFactory

use of org.apache.logging.log4j.message.StringFormatterMessageFactory in project logging-log4j2 by apache.

the class LoggerTest method getLogger_String_StringFormatterMessageFactory.

@Test
public void getLogger_String_StringFormatterMessageFactory() {
    final StringFormatterMessageFactory messageFactory = StringFormatterMessageFactory.INSTANCE;
    final TestLogger testLogger = (TestLogger) LogManager.getLogger("getLogger_String_StringFormatterMessageFactory", messageFactory);
    assertNotNull(testLogger);
    assertEqualMessageFactory(messageFactory, testLogger);
    testLogger.debug("%,d", Integer.MAX_VALUE);
    assertEquals(1, testLogger.getEntries().size());
    assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0));
}
Also used : StringFormatterMessageFactory(org.apache.logging.log4j.message.StringFormatterMessageFactory) Test(org.junit.Test)

Example 7 with StringFormatterMessageFactory

use of org.apache.logging.log4j.message.StringFormatterMessageFactory in project logging-log4j2 by apache.

the class LoggerTest method getLogger_Object_StringFormatterMessageFactory.

@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 = StringFormatterMessageFactory.INSTANCE;
    final TestLogger testLogger = (TestLogger) LogManager.getLogger(new TestStringFormatterMessageFactory(), messageFactory);
    assertNotNull(testLogger);
    assertEqualMessageFactory(messageFactory, testLogger);
    testLogger.debug("%,d", Integer.MAX_VALUE);
    assertEquals(1, testLogger.getEntries().size());
    assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0));
}
Also used : StringFormatterMessageFactory(org.apache.logging.log4j.message.StringFormatterMessageFactory) Test(org.junit.Test)

Example 8 with StringFormatterMessageFactory

use of org.apache.logging.log4j.message.StringFormatterMessageFactory in project logging-log4j2 by apache.

the class FormatterLoggerBenchmark method up.

@Setup(Level.Trial)
public void up() {
    new File("perftest.log").delete();
    System.setProperty("log4j.configurationFile", "perf3PlainNoLoc.xml");
    logger = LogManager.getLogger(getClass());
    formatterLogger = LogManager.getLogger("formatter", new StringFormatterMessageFactory());
}
Also used : StringFormatterMessageFactory(org.apache.logging.log4j.message.StringFormatterMessageFactory) File(java.io.File) Setup(org.openjdk.jmh.annotations.Setup)

Aggregations

StringFormatterMessageFactory (org.apache.logging.log4j.message.StringFormatterMessageFactory)8 Test (org.junit.Test)7 MessageFactory (org.apache.logging.log4j.message.MessageFactory)3 File (java.io.File)1 Setup (org.openjdk.jmh.annotations.Setup)1