org.apache.logging.log4j.message.ParameterizedMessageFactory Java Examples
The following examples show how to use
org.apache.logging.log4j.message.ParameterizedMessageFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LoggerTest.java From logging-log4j2 with Apache License 2.0 | 6 votes |
@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)); }
Example #2
Source File: AbstractLogger.java From logging-log4j2 with Apache License 2.0 | 5 votes |
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; } }
Example #3
Source File: LogManagerTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@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())); }
Example #4
Source File: LoggerTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@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)); }
Example #5
Source File: LoggerTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@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)); }
Example #6
Source File: LoggerTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@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)); }
Example #7
Source File: LoggerTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@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))); }
Example #8
Source File: LoggerTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@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()); }
Example #9
Source File: Logoo.java From ymate-platform-v2 with Apache License 2.0 | 4 votes |
public static String fmtMessage(String format, Object... arguments) { if (StringUtils.isNotBlank(format)) { return ParameterizedMessageFactory.INSTANCE.newMessage(format, arguments).getFormattedMessage(); } return format; }
Example #10
Source File: LogLogger.java From ymate-platform-v2 with Apache License 2.0 | 4 votes |
private static String __getSafeMessages(String msg, Object... args) { if (StringUtils.isNotBlank(msg)) { return ParameterizedMessageFactory.INSTANCE.newMessage(msg, args).getFormattedMessage(); } return msg; }
Example #11
Source File: MaskingRewritePolicyTest.java From owasp-security-logging with Apache License 2.0 | 4 votes |
@Before public void setUp() { LOGGER = LogManager.getLogger(MaskingRewritePolicyTest.class, new ParameterizedMessageFactory()); appender = context.getListAppender("List"); }
Example #12
Source File: AbstractLoggerTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
CountingLogger() { super("CountingLogger", ParameterizedMessageFactory.INSTANCE); }
Example #13
Source File: AbstractLoggerTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
ThrowableExpectingLogger(final boolean expectingThrowables) { super("ThrowableExpectingLogger", ParameterizedMessageFactory.INSTANCE); this.expectingThrowables = expectingThrowables; }