Search in sources :

Example 6 with TestLogger

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

the class LoggerTest method getLogger_String_ParameterizedMessageFactory.

@Test
public void getLogger_String_ParameterizedMessageFactory() {
    final ParameterizedMessageFactory messageFactory = ParameterizedMessageFactory.INSTANCE;
    final TestLogger testLogger = (TestLogger) LogManager.getLogger("getLogger_String_ParameterizedMessageFactory", 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 7 with TestLogger

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

the class LoggerTest method getLogger_String_SimpleMessageFactory.

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

Example 8 with TestLogger

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

the class TestLoggerContext method getLogger.

@Override
public ExtendedLogger getLogger(final String name) {
    final ExtendedLogger extendedLogger = map.get(name);
    if (extendedLogger != null) {
        return extendedLogger;
    }
    final ExtendedLogger logger = new TestLogger(name);
    map.put(name, logger);
    return logger;
}
Also used : ExtendedLogger(org.apache.logging.log4j.spi.ExtendedLogger) TestLogger(org.apache.logging.log4j.test.TestLogger)

Example 9 with TestLogger

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

Example 10 with TestLogger

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

the class LoggerTest method getLogger_Class_StringFormatterMessageFactory.

@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 TestLogger testLogger = (TestLogger) LogManager.getLogger(TestStringFormatterMessageFactory.class, StringFormatterMessageFactory.INSTANCE);
    assertNotNull(testLogger);
    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)

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