org.apache.logging.log4j.message.ParameterizedMessageFactory源码实例Demo

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

下面列出了org.apache.logging.log4j.message.ParameterizedMessageFactory 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: 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));
}
 
源代码2 项目: 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;
    }
}
 
源代码3 项目: 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()));
}
 
源代码4 项目: 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));
}
 
源代码5 项目: 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));
}
 
源代码6 项目: 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));
}
 
源代码7 项目: 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)));
}
 
源代码8 项目: 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());
}
 
源代码9 项目: ymate-platform-v2   文件: Logoo.java
public static String fmtMessage(String format, Object... arguments) {
    if (StringUtils.isNotBlank(format)) {
        return ParameterizedMessageFactory.INSTANCE.newMessage(format, arguments).getFormattedMessage();
    }
    return format;
}
 
源代码10 项目: 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;
}
 
@Before
public void setUp() {
	LOGGER = LogManager.getLogger(MaskingRewritePolicyTest.class, new ParameterizedMessageFactory());
	appender = context.getListAppender("List");
}
 
源代码12 项目: logging-log4j2   文件: AbstractLoggerTest.java
CountingLogger() {
    super("CountingLogger", ParameterizedMessageFactory.INSTANCE);
}
 
源代码13 项目: logging-log4j2   文件: AbstractLoggerTest.java
ThrowableExpectingLogger(final boolean expectingThrowables) {
    super("ThrowableExpectingLogger", ParameterizedMessageFactory.INSTANCE);
    this.expectingThrowables = expectingThrowables;
}
 
如果文章对您有帮助,请点击页面广告。以鼓励作者做出的努力。
 类所在包
 类方法
 同包方法