use of org.apache.logging.log4j.message.MessageFactory in project logging-log4j2 by apache.
the class Logger method getParent.
/**
* This method is only used for 1.x compatibility. Returns the parent of this Logger. If it doesn't already exist
* return a temporary Logger.
*
* @return The parent Logger.
*/
public Logger getParent() {
final LoggerConfig lc = privateConfig.loggerConfig.getName().equals(getName()) ? privateConfig.loggerConfig.getParent() : privateConfig.loggerConfig;
if (lc == null) {
return null;
}
final String lcName = lc.getName();
final MessageFactory messageFactory = getMessageFactory();
if (context.hasLogger(lcName, messageFactory)) {
return context.getLogger(lcName, messageFactory);
}
return new Logger(context, lcName, messageFactory);
}
use of org.apache.logging.log4j.message.MessageFactory in project logging-log4j2 by apache.
the class LoggerTest method assertEqualMessageFactory.
private void assertEqualMessageFactory(final MessageFactory messageFactory, final TestLogger testLogger) {
MessageFactory actual = testLogger.getMessageFactory();
if (actual instanceof MessageFactory2Adapter) {
actual = ((MessageFactory2Adapter) actual).getOriginal();
}
assertEquals(messageFactory, actual);
}
use of org.apache.logging.log4j.message.MessageFactory in project logging-log4j2 by apache.
the class LoggerTest method checkMessageFactory.
private static void checkMessageFactory(final MessageFactory messageFactory1, final Logger testLogger1) {
if (messageFactory1 == null) {
assertEquals(AbstractLogger.DEFAULT_MESSAGE_FACTORY_CLASS, testLogger1.getMessageFactory().getClass());
} else {
MessageFactory actual = testLogger1.getMessageFactory();
if (actual instanceof MessageFactory2Adapter) {
actual = ((MessageFactory2Adapter) actual).getOriginal();
}
assertEquals(messageFactory1, actual);
}
}
use of org.apache.logging.log4j.message.MessageFactory in project logging-log4j2 by apache.
the class SetLoggerTagTest method checkMessageFactory.
private static void checkMessageFactory(final String msg, final MessageFactory messageFactory1, final Logger testLogger1) {
if (messageFactory1 == null) {
assertEquals(msg, AbstractLogger.DEFAULT_MESSAGE_FACTORY_CLASS, testLogger1.getMessageFactory().getClass());
} else {
MessageFactory actual = testLogger1.getMessageFactory();
if (actual instanceof MessageFactory2Adapter) {
actual = ((MessageFactory2Adapter) actual).getOriginal();
}
assertEquals(msg, messageFactory1, actual);
}
}
use of org.apache.logging.log4j.message.MessageFactory in project logging-log4j2 by apache.
the class AbstractLogger method checkMessageFactory.
/**
* Checks that the message factory a logger was created with is the same as the given messageFactory. If they are
* different log a warning to the {@linkplain StatusLogger}. A null MessageFactory translates to the default
* MessageFactory {@link #DEFAULT_MESSAGE_FACTORY_CLASS}.
*
* @param logger The logger to check
* @param messageFactory The message factory to check.
*/
public static void checkMessageFactory(final ExtendedLogger logger, final MessageFactory messageFactory) {
final String name = logger.getName();
final MessageFactory loggerMessageFactory = logger.getMessageFactory();
if (messageFactory != null && !loggerMessageFactory.equals(messageFactory)) {
StatusLogger.getLogger().warn("The Logger {} was created with the message factory {} and is now requested with the " + "message factory {}, which may create log events with unexpected formatting.", name, loggerMessageFactory, messageFactory);
} else if (messageFactory == null && !loggerMessageFactory.getClass().equals(DEFAULT_MESSAGE_FACTORY_CLASS)) {
StatusLogger.getLogger().warn("The Logger {} was created with the message factory {} and is now requested with a null " + "message factory (defaults to {}), which may create log events with unexpected " + "formatting.", name, loggerMessageFactory, DEFAULT_MESSAGE_FACTORY_CLASS.getName());
}
}
Aggregations