• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java MessageFactory类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.logging.log4j.message.MessageFactory的典型用法代码示例。如果您正苦于以下问题:Java MessageFactory类的具体用法?Java MessageFactory怎么用?Java MessageFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MessageFactory类属于org.apache.logging.log4j.message包,在下文中一共展示了MessageFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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());
    }
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:29,代码来源:AbstractLogger.java


示例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;
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:27,代码来源:Log4jTaglibLoggerContext.java


示例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.");
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:24,代码来源:TagUtils.java


示例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());
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:22,代码来源:SetLoggerTagTest.java


示例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());
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:24,代码来源:SetLoggerTagTest.java


示例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());
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:17,代码来源:SetLoggerTagTest.java


示例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());
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:26,代码来源:AbstractLogger.java


示例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;
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:24,代码来源:Log4jTaglibLoggerContext.java


示例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);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:22,代码来源:SetLoggerTagTest.java


示例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);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:24,代码来源:SetLoggerTagTest.java


示例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);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:17,代码来源:SetLoggerTagTest.java


示例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());
}
 
开发者ID:raner,项目名称:loginject,代码行数:12,代码来源:GuiceLoggerTest.java


示例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());
}
 
开发者ID:raner,项目名称:loginject,代码行数:12,代码来源:GuiceLoggerTest.java


示例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);
        }
    }
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:33,代码来源:SimpleLogger.java


示例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);
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:13,代码来源:SimpleLoggerContext.java


示例16: getLogger

import org.apache.logging.log4j.message.MessageFactory; //导入依赖的package包/类
private static Log4jTaglibLogger getLogger(final Log4jTaglibLoggerContext context, final String name,
                                           final MessageFactory factory)
        throws JspException {
    try {
        return context.getLogger(name, factory);
    } catch (final LoggingException e) {
        throw new JspException(e.getMessage(), e);
    }
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:10,代码来源:TagUtils.java


示例17: getLogger

import org.apache.logging.log4j.message.MessageFactory; //导入依赖的package包/类
@Override
public Logger getLogger(final String name, final MessageFactory messageFactory) {
    if (!loggers.containsKey(name)) {
        loggers.putIfAbsent(name, new SLF4JLogger(name, messageFactory, LoggerFactory.getLogger(name)));
    }
    return loggers.get(name);
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:8,代码来源:SLF4JLoggerContext.java


示例18: testMessageFactoryMismatch

import org.apache.logging.log4j.message.MessageFactory; //导入依赖的package包/类
private Logger testMessageFactoryMismatch(final String name, final MessageFactory messageFactory1, final MessageFactory messageFactory2) {
    final Logger testLogger = LogManager.getLogger(name, messageFactory1);
    assertNotNull(testLogger);
    assertEquals(messageFactory1, testLogger.getMessageFactory());
    final Logger testLogger2 = LogManager.getLogger(name, messageFactory2);
    assertEquals(messageFactory1, testLogger2.getMessageFactory());
    return testLogger;
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:9,代码来源:LoggerTest.java


示例19: getLogger

import org.apache.logging.log4j.message.MessageFactory; //导入依赖的package包/类
/**
 * Obtain a Logger from the Context.
 * @param name The name of the Logger to return.
 * @param messageFactory The message factory is used only when creating a
 *            logger, subsequent use does not change the logger but will log
 *            a warning if mismatched.
 * @return The Logger.
 */
@Override
public Logger getLogger(final String name, final MessageFactory messageFactory) {
    Logger logger = loggers.get(name);
    if (logger != null) {
        AbstractLogger.checkMessageFactory(logger, messageFactory);
        return logger;
    }

    logger = newInstance(this, name, messageFactory);
    final Logger prev = loggers.putIfAbsent(name, logger);
    return prev == null ? logger : prev;
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:21,代码来源:LoggerContext.java


示例20: testMessageFactoryMismatch

import org.apache.logging.log4j.message.MessageFactory; //导入依赖的package包/类
private Logger testMessageFactoryMismatch(final String name, final MessageFactory messageFactory1, final MessageFactory messageFactory2) {
    final Logger testLogger = (Logger) LogManager.getLogger(name, messageFactory1);
    assertNotNull(testLogger);
    assertEquals(messageFactory1, testLogger.getMessageFactory());
    final Logger testLogger2 = (Logger) LogManager.getLogger(name, messageFactory2);
    assertEquals(messageFactory1, testLogger2.getMessageFactory());
    return testLogger;
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:9,代码来源:LoggerTest.java



注:本文中的org.apache.logging.log4j.message.MessageFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SimpleBindRequest类代码示例发布时间:2022-05-22
下一篇:
Java SourceInterface类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap