Java 类org.apache.logging.log4j.message.ParameterizedMessageFactory 实例源码

项目:log4j2    文件:LoggerTest.java   
@Test
public void getLogger_String_MessageFactoryMismatch() {
    final StringFormatterMessageFactory messageFactory = StringFormatterMessageFactory.INSTANCE;
    final TestLogger testLogger = (TestLogger) LogManager.getLogger("getLogger_String_MessageFactoryMismatch",
            messageFactory);
    assertNotNull(testLogger);
    assertEquals(messageFactory, testLogger.getMessageFactory());
    final TestLogger testLogger2 = (TestLogger) LogManager.getLogger("getLogger_String_MessageFactoryMismatch",
            ParameterizedMessageFactory.INSTANCE);
    //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));
}
项目:logging-log4j2    文件:LoggerTest.java   
@Test
public void getLogger_String_MessageFactoryMismatch() {
    final StringFormatterMessageFactory messageFactory = StringFormatterMessageFactory.INSTANCE;
    final TestLogger testLogger = (TestLogger) LogManager.getLogger("getLogger_String_MessageFactoryMismatch",
            messageFactory);
    assertNotNull(testLogger);
    assertEqualMessageFactory(messageFactory, testLogger);
    final TestLogger testLogger2 = (TestLogger) LogManager.getLogger("getLogger_String_MessageFactoryMismatch",
            ParameterizedMessageFactory.INSTANCE);
    assertNotNull(testLogger2);
    //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));
}
项目:monarch    文件:FastLoggerJUnitTest.java   
@Before
public void setUp() {
  this.messageFactory = new ParameterizedMessageFactory();
  this.mockedLogger = mock(ExtendedLogger.class);
  this.mockedMarker = mock(Marker.class);

  when(this.mockedLogger.getMessageFactory()).thenReturn(this.messageFactory);
  when(this.mockedMarker.getName()).thenReturn("MARKER");
}
项目:log4j2    文件:LogManagerTest.java   
@Test
public void testGetLogger() {
    Logger logger = LogManager.getLogger();
    assertNotNull("No Logger returned", logger);
    assertTrue("Incorrect Logger name: " + logger.getName(),LogManagerTest.class.getName().equals(logger.getName()));
    logger = LogManager.getLogger(ParameterizedMessageFactory.INSTANCE);
    assertNotNull("No Logger returned", logger);
    assertTrue("Incorrect Logger name: " + logger.getName(),LogManagerTest.class.getName().equals(logger.getName()));
    logger = LogManager.getLogger((Class<?>) null);
    assertNotNull("No Logger returned", logger);
    assertTrue("Incorrect Logger name: " + logger.getName(),LogManagerTest.class.getName().equals(logger.getName()));
    logger = LogManager.getLogger((Class<?>) null, ParameterizedMessageFactory.INSTANCE);
    assertNotNull("No Logger returned", logger);
    assertTrue("Incorrect Logger name: " + logger.getName(),LogManagerTest.class.getName().equals(logger.getName()));
    logger = LogManager.getLogger((String) null);
    assertNotNull("No Logger returned", logger);
    assertTrue("Incorrect Logger name: " + logger.getName(),LogManagerTest.class.getName().equals(logger.getName()));
    logger = LogManager.getLogger((String) null, ParameterizedMessageFactory.INSTANCE);
    assertNotNull("No Logger returned", logger);
    assertTrue("Incorrect Logger name: " + logger.getName(),LogManagerTest.class.getName().equals(logger.getName()));
    logger = LogManager.getLogger((Object) null);
    assertNotNull("No Logger returned", logger);
    assertTrue("Incorrect Logger name: " + logger.getName(),LogManagerTest.class.getName().equals(logger.getName()));
    logger = LogManager.getLogger((Object) null, ParameterizedMessageFactory.INSTANCE);
    assertNotNull("No Logger returned", logger);
    assertTrue("Incorrect Logger name: " + logger.getName(),LogManagerTest.class.getName().equals(logger.getName()));
}
项目:log4j2    文件:LoggerTest.java   
@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 = ParameterizedMessageFactory.INSTANCE;
    final 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));
}
项目:log4j2    文件:LoggerTest.java   
@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);
    assertEquals(messageFactory, testLogger.getMessageFactory());
    testLogger.debug("{}", Integer.MAX_VALUE);
    assertEquals(1, testLogger.getEntries().size());
    assertEquals(" DEBUG " + Integer.MAX_VALUE, testLogger.getEntries().get(0));
}
项目:log4j2    文件:LoggerTest.java   
@Test
public void getLogger_String_ParameterizedMessageFactory() {
    final ParameterizedMessageFactory messageFactory =  ParameterizedMessageFactory.INSTANCE;
    final 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));
}
项目:log4j2    文件:LoggerTest.java   
@Test
public void getLogger_String_MessageFactoryMismatch() {
    final Logger testLogger = testMessageFactoryMismatch("getLogger_String_MessageFactoryMismatch",
        StringFormatterMessageFactory.INSTANCE, ParameterizedMessageFactory.INSTANCE);
    testLogger.debug("%,d", Integer.MAX_VALUE);
    assertTrue("Incorrect number of events. Expected 1, actual " + list.strList.size(), list.strList.size() == 1);
    assertEquals(String.format("%,d", Integer.MAX_VALUE), list.strList.get(0));
}
项目:log4j2    文件:LoggerTest.java   
@Test
public void getLogger_String_MessageFactoryMismatch() {
    final Logger testLogger = testMessageFactoryMismatch("getLogger_String_MessageFactoryMismatch",
            StringFormatterMessageFactory.INSTANCE, ParameterizedMessageFactory.INSTANCE);
    testLogger.debug("%,d", Integer.MAX_VALUE);
    final List<LogEvent> events = app.getEvents();
    assertTrue("Incorrect number of events. Expected 1, actual " + events.size(), events.size() == 1);
    assertEquals(String.format("%,d", Integer.MAX_VALUE), events.get(0).getMessage().getFormattedMessage());
}
项目:logging-log4j2    文件:AbstractLogger.java   
private static Class<? extends MessageFactory> createClassForProperty(final String property,
        final Class<ReusableMessageFactory> reusableParameterizedMessageFactoryClass,
        final Class<ParameterizedMessageFactory> parameterizedMessageFactoryClass) {
    try {
        final String fallback = Constants.ENABLE_THREADLOCALS ? reusableParameterizedMessageFactoryClass.getName()
                : parameterizedMessageFactoryClass.getName();
        final String clsName = PropertiesUtil.getProperties().getStringProperty(property, fallback);
        return LoaderUtil.loadClass(clsName).asSubclass(MessageFactory.class);
    } catch (final Throwable t) {
        return parameterizedMessageFactoryClass;
    }
}
项目:logging-log4j2    文件:LogManagerTest.java   
@Test
public void testGetLogger() {
    Logger logger = LogManager.getLogger();
    assertNotNull("No Logger returned", logger);
    assertTrue("Incorrect Logger name: " + logger.getName(),LogManagerTest.class.getName().equals(logger.getName()));
    logger = LogManager.getLogger(ParameterizedMessageFactory.INSTANCE);
    assertNotNull("No Logger returned", logger);
    assertTrue("Incorrect Logger name: " + logger.getName(),LogManagerTest.class.getName().equals(logger.getName()));
    logger = LogManager.getLogger((Class<?>) null);
    assertNotNull("No Logger returned", logger);
    assertTrue("Incorrect Logger name: " + logger.getName(),LogManagerTest.class.getName().equals(logger.getName()));
    logger = LogManager.getLogger((Class<?>) null, ParameterizedMessageFactory.INSTANCE);
    assertNotNull("No Logger returned", logger);
    assertTrue("Incorrect Logger name: " + logger.getName(),LogManagerTest.class.getName().equals(logger.getName()));
    logger = LogManager.getLogger((String) null);
    assertNotNull("No Logger returned", logger);
    assertTrue("Incorrect Logger name: " + logger.getName(),LogManagerTest.class.getName().equals(logger.getName()));
    logger = LogManager.getLogger((String) null, ParameterizedMessageFactory.INSTANCE);
    assertNotNull("No Logger returned", logger);
    assertTrue("Incorrect Logger name: " + logger.getName(),LogManagerTest.class.getName().equals(logger.getName()));
    logger = LogManager.getLogger((Object) null);
    assertNotNull("No Logger returned", logger);
    assertTrue("Incorrect Logger name: " + logger.getName(),LogManagerTest.class.getName().equals(logger.getName()));
    logger = LogManager.getLogger((Object) null, ParameterizedMessageFactory.INSTANCE);
    assertNotNull("No Logger returned", logger);
    assertTrue("Incorrect Logger name: " + logger.getName(),LogManagerTest.class.getName().equals(logger.getName()));
}
项目:logging-log4j2    文件:LoggerTest.java   
@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 = ParameterizedMessageFactory.INSTANCE;
    final TestLogger testLogger = (TestLogger) LogManager.getLogger(TestParameterizedMessageFactory.class,
            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));
}
项目:logging-log4j2    文件:LoggerTest.java   
@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));
}
项目:logging-log4j2    文件:LoggerTest.java   
@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));
}
项目:logging-log4j2    文件:LoggerTest.java   
@Test
public void getLogger_String_MessageFactoryMismatch() {
    final Logger testLogger = testMessageFactoryMismatch("getLogger_String_MessageFactoryMismatch",
        StringFormatterMessageFactory.INSTANCE, ParameterizedMessageFactory.INSTANCE);
    testLogger.debug("%,d", Integer.MAX_VALUE);
    assertThat(list.strList, hasSize(1));
    assertThat(list.strList, hasItem(String.format("%,d", Integer.MAX_VALUE)));
}
项目:logging-log4j2    文件:LoggerTest.java   
@Test
public void getLogger_String_MessageFactoryMismatch() {
    final Logger testLogger = testMessageFactoryMismatch(testName.getMethodName(),
            StringFormatterMessageFactory.INSTANCE, ParameterizedMessageFactory.INSTANCE);
    testLogger.debug("%,d", Integer.MAX_VALUE);
    final List<LogEvent> events = app.getEvents();
    assertEventCount(events, 1);
    assertEquals(String.format("%,d", Integer.MAX_VALUE), events.get(0).getMessage().getFormattedMessage());
}
项目:ymate-platform-v2    文件:LogLogger.java   
private static String __getSafeMessages(String msg, Object... args) {
    if (StringUtils.isNotBlank(msg)) {
        return ParameterizedMessageFactory.INSTANCE.newMessage(msg, args).getFormattedMessage();
    }
    return msg;
}
项目:logging-log4j2    文件:AbstractLoggerTest.java   
CountingLogger() {
    super("CountingLogger", new MessageFactory2Adapter(ParameterizedMessageFactory.INSTANCE));
}
项目:logging-log4j2    文件:AbstractLoggerTest.java   
ThrowableExpectingLogger(final boolean expectingThrowables) {
    super("ThrowableExpectingLogger", new MessageFactory2Adapter(ParameterizedMessageFactory.INSTANCE));
    this.expectingThrowables = expectingThrowables;
}