Search in sources :

Example 1 with TestLogger

use of org.apache.logging.log4j.test.TestLogger in project logging-log4j2 by apache.

the class LoggerTest method getFormatterLogger_Object.

@Test
public void getFormatterLogger_Object() {
    // 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 TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger(new TestStringFormatterMessageFactory());
    assertNotNull(testLogger);
    assertMessageFactoryInstanceOf(testLogger.getMessageFactory(), StringFormatterMessageFactory.class);
    assertEqualMessageFactory(StringFormatterMessageFactory.INSTANCE, 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 : TestLogger(org.apache.logging.log4j.test.TestLogger) Test(org.junit.jupiter.api.Test)

Example 2 with TestLogger

use of org.apache.logging.log4j.test.TestLogger in project logging-log4j2 by apache.

the class LoggerTest method getFormatterLogger.

@Test
public void getFormatterLogger() {
    // 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 TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger();
    final TestLogger altLogger = (TestLogger) LogManager.getFormatterLogger(getClass());
    assertEquals(testLogger.getName(), altLogger.getName());
    assertNotNull(testLogger);
    assertMessageFactoryInstanceOf(testLogger.getMessageFactory(), StringFormatterMessageFactory.class);
    assertEqualMessageFactory(StringFormatterMessageFactory.INSTANCE, 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 : TestLogger(org.apache.logging.log4j.test.TestLogger) Test(org.junit.jupiter.api.Test)

Example 3 with TestLogger

use of org.apache.logging.log4j.test.TestLogger in project logging-log4j2 by apache.

the class LoggerTest method getFormatterLogger_Class.

@Test
public void getFormatterLogger_Class() {
    // 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 TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger(TestStringFormatterMessageFactory.class);
    assertNotNull(testLogger);
    assertMessageFactoryInstanceOf(testLogger.getMessageFactory(), StringFormatterMessageFactory.class);
    assertEqualMessageFactory(StringFormatterMessageFactory.INSTANCE, 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 : TestLogger(org.apache.logging.log4j.test.TestLogger) Test(org.junit.jupiter.api.Test)

Example 4 with TestLogger

use of org.apache.logging.log4j.test.TestLogger in project logging-log4j2 by apache.

the class LoggerTest method getLogger_Object_ParameterizedMessageFactory.

@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 = ParameterizedMessageFactory.INSTANCE;
    final TestLogger testLogger = (TestLogger) LogManager.getLogger(new TestParameterizedMessageFactory(), messageFactory);
    assertNotNull(testLogger);
    assertEqualMessageFactory(messageFactory, testLogger);
    testLogger.debug("{}", Integer.MAX_VALUE);
    assertEquals(1, testLogger.getEntries().size());
    assertEquals(" DEBUG " + Integer.MAX_VALUE, testLogger.getEntries().get(0));
}
Also used : TestLogger(org.apache.logging.log4j.test.TestLogger) ParameterizedMessageFactory(org.apache.logging.log4j.message.ParameterizedMessageFactory) Test(org.junit.jupiter.api.Test)

Example 5 with TestLogger

use of org.apache.logging.log4j.test.TestLogger 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) TestLogger(org.apache.logging.log4j.test.TestLogger) Test(org.junit.jupiter.api.Test)

Aggregations

TestLogger (org.apache.logging.log4j.test.TestLogger)15 Test (org.junit.jupiter.api.Test)14 StringFormatterMessageFactory (org.apache.logging.log4j.message.StringFormatterMessageFactory)4 ParameterizedMessageFactory (org.apache.logging.log4j.message.ParameterizedMessageFactory)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 DiagnosticCollector (javax.tools.DiagnosticCollector)2 JavaCompiler (javax.tools.JavaCompiler)2 JavaFileObject (javax.tools.JavaFileObject)2 StandardJavaFileManager (javax.tools.StandardJavaFileManager)2 MessageFactory (org.apache.logging.log4j.message.MessageFactory)2 ExtendedLogger (org.apache.logging.log4j.spi.ExtendedLogger)2 MessageSupplier (org.apache.logging.log4j.util.MessageSupplier)2 Supplier (org.apache.logging.log4j.util.Supplier)2 SimpleMessageFactory (org.apache.logging.log4j.message.SimpleMessageFactory)1