本文整理汇总了Java中org.apache.logging.log4j.message.MessageFactory类的典型用法代码示例。如果您正苦于以下问题:Java MessageFactory类的具体用法?Java MessageFactory怎么用?Java MessageFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MessageFactory类属于org.apache.logging.log4j.message包,在下文中一共展示了MessageFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkMessageFactory
import org.apache.logging.log4j.message.MessageFactory; //导入依赖的package包/类
/**
* 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 Logger 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());
}
}
示例2: getLogger
import org.apache.logging.log4j.message.MessageFactory; //导入依赖的package包/类
@Override
public Log4jTaglibLogger getLogger(final String name, final MessageFactory factory) {
Log4jTaglibLogger logger = this.loggers.get(name);
if (logger != null) {
AbstractLogger.checkMessageFactory(logger, factory);
return logger;
}
synchronized (this.loggers) {
logger = this.loggers.get(name);
if (logger == null) {
final Logger original = factory == null ?
LogManager.getLogger(name) : LogManager.getLogger(name, factory);
if (!(original instanceof AbstractLogger)) {
throw new LoggingException(
"Log4j Tag Library requires base logging system to extend Log4j AbstractLogger."
);
}
// wrap a logger from an underlying implementation
logger = new Log4jTaglibLogger((AbstractLogger) original, name, original.getMessageFactory());
this.loggers.put(name, logger);
}
}
return logger;
}
示例3: resolveLogger
import org.apache.logging.log4j.message.MessageFactory; //导入依赖的package包/类
static Log4jTaglibLogger resolveLogger(final Log4jTaglibLoggerContext context, final Object logger,
final MessageFactory factory) throws JspException {
if (logger instanceof Logger) {
if (logger instanceof Log4jTaglibLogger) {
return (Log4jTaglibLogger) logger;
}
if (logger instanceof AbstractLogger) {
if (LOGGER.isInfoEnabled() && !WARNED_FOR.contains(logger)) {
LOGGER.info("Constructing new Log4jTaglibLogger from AbstractLogger {} name and message factory.",
logger.getClass().getName());
WARNED_FOR.add(logger);
}
final AbstractLogger original = (AbstractLogger) logger;
return getLogger(context, original.getName(), original.getMessageFactory());
}
throw new JspException(
"Log4j Tag Library requires base logging system to extend Log4j AbstractLogger.");
}
if (logger instanceof String) {
return getLogger(context, (String) logger, factory);
}
throw new JspException("Logger must be of type String or org.apache.logging.log4j.Logger.");
}
示例4: testDoEndTagStringFactoryVarPageScope
import org.apache.logging.log4j.message.MessageFactory; //导入依赖的package包/类
@Test
public void testDoEndTagStringFactoryVarPageScope() throws Exception {
this.tag.setLogger("testDoEndTagStringFactoryVarPageScope");
final MessageFactory factory = new StringFormatterMessageFactory();
this.tag.setFactory(factory);
this.tag.setVar("goodbyeCruelWorld");
assertNull("The default logger should be null.", TagUtils.getDefaultLogger(this.context));
assertEquals("The return value is not correct.", Tag.EVAL_PAGE, this.tag.doEndTag());
assertNull("The default logger should still be null.", TagUtils.getDefaultLogger(this.context));
final Object attribute = this.context.getAttribute("goodbyeCruelWorld", PageContext.PAGE_SCOPE);
assertNotNull("The attribute should not be null.", attribute);
assertTrue("The attribute should be a Log4jTaglibLogger.", attribute instanceof Log4jTaglibLogger);
final Log4jTaglibLogger logger = (Log4jTaglibLogger)attribute;
assertEquals("The logger name is not correct.", "testDoEndTagStringFactoryVarPageScope", logger.getName());
assertSame("The message factory is not correct.", factory, logger.getMessageFactory());
}
示例5: testDoEndTagStringFactoryVarApplicationScope
import org.apache.logging.log4j.message.MessageFactory; //导入依赖的package包/类
@Test
public void testDoEndTagStringFactoryVarApplicationScope() throws Exception {
this.tag.setLogger("testDoEndTagStringFactoryVarApplicationScope");
final MessageFactory factory = new StringFormatterMessageFactory();
this.tag.setFactory(factory);
this.tag.setVar("goodbyeCruelWorld");
this.tag.setScope("application");
assertNull("The default logger should be null.", TagUtils.getDefaultLogger(this.context));
assertEquals("The return value is not correct.", Tag.EVAL_PAGE, this.tag.doEndTag());
assertNull("The default logger should still be null.", TagUtils.getDefaultLogger(this.context));
final Object attribute = this.context.getAttribute("goodbyeCruelWorld", PageContext.APPLICATION_SCOPE);
assertNotNull("The attribute should not be null.", attribute);
assertTrue("The attribute should be a Log4jTaglibLogger.", attribute instanceof Log4jTaglibLogger);
final Log4jTaglibLogger logger = (Log4jTaglibLogger)attribute;
assertEquals("The logger name is not correct.", "testDoEndTagStringFactoryVarApplicationScope",
logger.getName());
assertSame("The message factory is not correct.", factory, logger.getMessageFactory());
}
示例6: testDoEndTagStringFactoryDefault
import org.apache.logging.log4j.message.MessageFactory; //导入依赖的package包/类
@Test
public void testDoEndTagStringFactoryDefault() throws Exception {
this.tag.setLogger("testDoEndTagStringFactoryDefault");
final MessageFactory factory = new StringFormatterMessageFactory();
this.tag.setFactory(factory);
assertNull("The default logger should be null.", TagUtils.getDefaultLogger(this.context));
assertEquals("The return value is not correct.", Tag.EVAL_PAGE, this.tag.doEndTag());
final Log4jTaglibLogger logger = TagUtils.getDefaultLogger(this.context);
assertNotNull("The default logger should not be null anymore.", logger);
assertEquals("The logger name is not correct.", "testDoEndTagStringFactoryDefault", logger.getName());
assertSame("The message factory is not correct.", factory, logger.getMessageFactory());
}
示例7: checkMessageFactory
import org.apache.logging.log4j.message.MessageFactory; //导入依赖的package包/类
/**
* 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());
}
}
示例8: getLogger
import org.apache.logging.log4j.message.MessageFactory; //导入依赖的package包/类
@Override
public Log4jTaglibLogger getLogger(final String name, final MessageFactory messageFactory) {
// Note: This is the only method where we add entries to the 'loggerRegistry' ivar.
Log4jTaglibLogger logger = this.loggerRegistry.getLogger(name, messageFactory);
if (logger != null) {
AbstractLogger.checkMessageFactory(logger, messageFactory);
return logger;
}
synchronized (this.loggerRegistry) {
logger = this.loggerRegistry.getLogger(name, messageFactory);
if (logger == null) {
final LoggerContext context = LogManager.getContext(false);
final ExtendedLogger original = messageFactory == null ?
context.getLogger(name) : context.getLogger(name, messageFactory);
// wrap a logger from an underlying implementation
logger = new Log4jTaglibLogger(original, name, original.getMessageFactory());
this.loggerRegistry.putIfAbsent(name, messageFactory, logger);
}
}
return logger;
}
示例9: testDoEndTagStringFactoryVarPageScope
import org.apache.logging.log4j.message.MessageFactory; //导入依赖的package包/类
@Test
public void testDoEndTagStringFactoryVarPageScope() throws Exception {
this.tag.setLogger("testDoEndTagStringFactoryVarPageScope");
final MessageFactory factory = new StringFormatterMessageFactory();
this.tag.setFactory(factory);
this.tag.setVar("goodbyeCruelWorld");
assertNull("The default logger should be null.", TagUtils.getDefaultLogger(this.context));
assertEquals("The return value is not correct.", Tag.EVAL_PAGE, this.tag.doEndTag());
assertNull("The default logger should still be null.", TagUtils.getDefaultLogger(this.context));
final Object attribute = this.context.getAttribute("goodbyeCruelWorld", PageContext.PAGE_SCOPE);
assertNotNull("The attribute should not be null.", attribute);
assertTrue("The attribute should be a Log4jTaglibLogger.", attribute instanceof Log4jTaglibLogger);
final Log4jTaglibLogger logger = (Log4jTaglibLogger)attribute;
assertEquals("The logger name is not correct.", "testDoEndTagStringFactoryVarPageScope", logger.getName());
checkMessageFactory("The message factory is not correct.", factory, logger);
}
示例10: testDoEndTagStringFactoryVarApplicationScope
import org.apache.logging.log4j.message.MessageFactory; //导入依赖的package包/类
@Test
public void testDoEndTagStringFactoryVarApplicationScope() throws Exception {
this.tag.setLogger("testDoEndTagStringFactoryVarApplicationScope");
final MessageFactory factory = new StringFormatterMessageFactory();
this.tag.setFactory(factory);
this.tag.setVar("goodbyeCruelWorld");
this.tag.setScope("application");
assertNull("The default logger should be null.", TagUtils.getDefaultLogger(this.context));
assertEquals("The return value is not correct.", Tag.EVAL_PAGE, this.tag.doEndTag());
assertNull("The default logger should still be null.", TagUtils.getDefaultLogger(this.context));
final Object attribute = this.context.getAttribute("goodbyeCruelWorld", PageContext.APPLICATION_SCOPE);
assertNotNull("The attribute should not be null.", attribute);
assertTrue("The attribute should be a Log4jTaglibLogger.", attribute instanceof Log4jTaglibLogger);
final Log4jTaglibLogger logger = (Log4jTaglibLogger)attribute;
assertEquals("The logger name is not correct.", "testDoEndTagStringFactoryVarApplicationScope",
logger.getName());
checkMessageFactory("The message factory is not correct.", factory, logger);
}
示例11: testDoEndTagStringFactoryDefault
import org.apache.logging.log4j.message.MessageFactory; //导入依赖的package包/类
@Test
public void testDoEndTagStringFactoryDefault() throws Exception {
this.tag.setLogger("testDoEndTagStringFactoryDefault");
final MessageFactory factory = new StringFormatterMessageFactory();
this.tag.setFactory(factory);
assertNull("The default logger should be null.", TagUtils.getDefaultLogger(this.context));
assertEquals("The return value is not correct.", Tag.EVAL_PAGE, this.tag.doEndTag());
final Log4jTaglibLogger logger = TagUtils.getDefaultLogger(this.context);
assertNotNull("The default logger should not be null anymore.", logger);
assertEquals("The logger name is not correct.", "testDoEndTagStringFactoryDefault", logger.getName());
checkMessageFactory("The message factory is not correct.", factory, logger);
}
示例12: testLoggerWithTwoArguments
import org.apache.logging.log4j.message.MessageFactory; //导入依赖的package包/类
@Test
public void testLoggerWithTwoArguments()
{
final MessageFactory MF = new MessageFormatMessageFactory();
String name = testName.getMethodName();
Module module = loginject(Logger.class, LogManager::getLogger, parameter(name), parameter(MF)).as(Module.class);
Injector injector = Guice.createInjector(module);
TestClass service = injector.getInstance(TestClass.class);
assertEquals(name, service.injectedLogger.getName());
assertEquals(MF, service.injectedLogger.getMessageFactory());
}
示例13: testGetLoggerWithTwoArgumentsWithInferredLoggerType
import org.apache.logging.log4j.message.MessageFactory; //导入依赖的package包/类
@Test
public void testGetLoggerWithTwoArgumentsWithInferredLoggerType()
{
final MessageFactory MF = new MessageFormatMessageFactory();
String name = testName.getMethodName();
Module module = loginject(LogManager::getLogger, parameter(name), parameter(MF)).as(Module.class);
Injector injector = Guice.createInjector(module);
TestClass service = injector.getInstance(TestClass.class);
assertEquals(name, service.injectedLogger.getName());
assertEquals(MF, service.injectedLogger.getMessageFactory());
}
示例14: SimpleLogger
import org.apache.logging.log4j.message.MessageFactory; //导入依赖的package包/类
public SimpleLogger(final String name, final Level defaultLevel, final boolean showLogName,
final boolean showShortLogName, final boolean showDateTime, final boolean showContextMap,
final String dateTimeFormat, final MessageFactory messageFactory, final PropertiesUtil props,
final PrintStream stream) {
super(name, messageFactory);
final String lvl = props.getStringProperty(SimpleLoggerContext.SYSTEM_PREFIX + name + ".level");
this.level = Level.toLevel(lvl, defaultLevel);
if (showShortLogName) {
final int index = name.lastIndexOf(".");
if (index > 0 && index < name.length()) {
this.logName = name.substring(index + 1);
} else {
this.logName = name;
}
} else if (showLogName) {
this.logName = name;
} else {
this.logName = null;
}
this.showDateTime = showDateTime;
this.showContextMap = showContextMap;
this.stream = stream;
if (showDateTime) {
try {
this.dateFormatter = new SimpleDateFormat(dateTimeFormat);
} catch (final IllegalArgumentException e) {
// If the format pattern is invalid - use the default format
this.dateFormatter = new SimpleDateFormat(SimpleLoggerContext.DEFAULT_DATE_TIME_FORMAT);
}
}
}
示例15: getLogger
import org.apache.logging.log4j.message.MessageFactory; //导入依赖的package包/类
@Override
public Logger getLogger(final String name, final MessageFactory messageFactory) {
if (loggers.containsKey(name)) {
final Logger logger = loggers.get(name);
AbstractLogger.checkMessageFactory(logger, messageFactory);
return logger;
}
loggers.putIfAbsent(name, new SimpleLogger(name, defaultLevel, showLogName, showShortName, showDateTime,
showContextMap, dateTimeFormat, messageFactory, props, stream));
return loggers.get(name);
}