Search in sources :

Example 1 with StringFormatterMessageFactory

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

the class SetLoggerTagTest method testDoEndTagStringFactoryVarPageScope.

@Test
public void testDoEndTagStringFactoryVarPageScope() throws Exception {
    this.tag.setLogger("testDoEndTagStringFactoryVarPageScope");
    final MessageFactory factory = new StringFormatterMessageFactory();
    this.tag.setFactory(factory);
    this.tag.setVar("goodbyeCruelWorld");
    assertNull("The default logger should be null.", TagUtils.getDefaultLogger(this.context));
    assertEquals("The return value is not correct.", Tag.EVAL_PAGE, this.tag.doEndTag());
    assertNull("The default logger should still be null.", TagUtils.getDefaultLogger(this.context));
    final Object attribute = this.context.getAttribute("goodbyeCruelWorld", PageContext.PAGE_SCOPE);
    assertNotNull("The attribute should not be null.", attribute);
    assertTrue("The attribute should be a Log4jTaglibLogger.", attribute instanceof Log4jTaglibLogger);
    final Log4jTaglibLogger logger = (Log4jTaglibLogger) attribute;
    assertEquals("The logger name is not correct.", "testDoEndTagStringFactoryVarPageScope", logger.getName());
    checkMessageFactory("The message factory is not correct.", factory, logger);
}
Also used : MessageFactory(org.apache.logging.log4j.message.MessageFactory) StringFormatterMessageFactory(org.apache.logging.log4j.message.StringFormatterMessageFactory) StringFormatterMessageFactory(org.apache.logging.log4j.message.StringFormatterMessageFactory) Test(org.junit.Test)

Example 2 with StringFormatterMessageFactory

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

the class SetLoggerTagTest method testDoEndTagStringFactoryDefault.

@Test
public void testDoEndTagStringFactoryDefault() throws Exception {
    this.tag.setLogger("testDoEndTagStringFactoryDefault");
    final MessageFactory factory = new StringFormatterMessageFactory();
    this.tag.setFactory(factory);
    assertNull("The default logger should be null.", TagUtils.getDefaultLogger(this.context));
    assertEquals("The return value is not correct.", Tag.EVAL_PAGE, this.tag.doEndTag());
    final Log4jTaglibLogger logger = TagUtils.getDefaultLogger(this.context);
    assertNotNull("The default logger should not be null anymore.", logger);
    assertEquals("The logger name is not correct.", "testDoEndTagStringFactoryDefault", logger.getName());
    checkMessageFactory("The message factory is not correct.", factory, logger);
}
Also used : MessageFactory(org.apache.logging.log4j.message.MessageFactory) StringFormatterMessageFactory(org.apache.logging.log4j.message.StringFormatterMessageFactory) StringFormatterMessageFactory(org.apache.logging.log4j.message.StringFormatterMessageFactory) Test(org.junit.Test)

Example 3 with StringFormatterMessageFactory

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

the class SetLoggerTagTest method testDoEndTagStringFactoryVarApplicationScope.

@Test
public void testDoEndTagStringFactoryVarApplicationScope() throws Exception {
    this.tag.setLogger("testDoEndTagStringFactoryVarApplicationScope");
    final MessageFactory factory = new StringFormatterMessageFactory();
    this.tag.setFactory(factory);
    this.tag.setVar("goodbyeCruelWorld");
    this.tag.setScope("application");
    assertNull("The default logger should be null.", TagUtils.getDefaultLogger(this.context));
    assertEquals("The return value is not correct.", Tag.EVAL_PAGE, this.tag.doEndTag());
    assertNull("The default logger should still be null.", TagUtils.getDefaultLogger(this.context));
    final Object attribute = this.context.getAttribute("goodbyeCruelWorld", PageContext.APPLICATION_SCOPE);
    assertNotNull("The attribute should not be null.", attribute);
    assertTrue("The attribute should be a Log4jTaglibLogger.", attribute instanceof Log4jTaglibLogger);
    final Log4jTaglibLogger logger = (Log4jTaglibLogger) attribute;
    assertEquals("The logger name is not correct.", "testDoEndTagStringFactoryVarApplicationScope", logger.getName());
    checkMessageFactory("The message factory is not correct.", factory, logger);
}
Also used : MessageFactory(org.apache.logging.log4j.message.MessageFactory) StringFormatterMessageFactory(org.apache.logging.log4j.message.StringFormatterMessageFactory) StringFormatterMessageFactory(org.apache.logging.log4j.message.StringFormatterMessageFactory) Test(org.junit.Test)

Example 4 with StringFormatterMessageFactory

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

the class LoggerTest method getFormatterLogger_String.

@Test
public void getFormatterLogger_String() {
    final StringFormatterMessageFactory messageFactory = StringFormatterMessageFactory.INSTANCE;
    final TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger("getLogger_String_StringFormatterMessageFactory");
    assertNotNull(testLogger);
    assertMessageFactoryInstanceOf(testLogger.getMessageFactory(), StringFormatterMessageFactory.class);
    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 5 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