org.apache.logging.log4j.LogManager.getFormatterLogger()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(114)

本文整理了Java中org.apache.logging.log4j.LogManager.getFormatterLogger()方法的一些代码示例,展示了LogManager.getFormatterLogger()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LogManager.getFormatterLogger()方法的具体详情如下:
包路径:org.apache.logging.log4j.LogManager
类名称:LogManager
方法名:getFormatterLogger

LogManager.getFormatterLogger介绍

[英]Returns a formatter Logger using the fully qualified name of the calling Class as the Logger name.

This logger lets you use a java.util.Formatter string in the message to format parameters.
[中]返回使用调用类的完全限定名作为记录器名称的格式化程序记录器。
此记录器允许您使用java。util。消息中用于格式化参数的格式化程序字符串。

代码示例

代码示例来源:origin: wildfly/wildfly

public Log4J2LogImpl(String category) {
  logger=LogManager.getFormatterLogger(category);
}

代码示例来源:origin: wildfly/wildfly

public Log4J2LogImpl(Class<?> category) {
  logger = LogManager.getFormatterLogger(category);
}

代码示例来源:origin: org.apache.logging.log4j/log4j-api

/**
 * Returns a formatter Logger using the fully qualified name of the calling Class as the Logger name.
 * <p>
 * This logger lets you use a {@link java.util.Formatter} string in the message to format parameters.
 * </p>
 *
 * @return The Logger for the calling class.
 * @throws UnsupportedOperationException if the calling class cannot be determined.
 * @since 2.4
 */
public static Logger getFormatterLogger() {
  return getFormatterLogger(StackLocatorUtil.getCallerClass(2));
}

代码示例来源:origin: org.apache.logging.log4j/log4j-api

/**
 * Returns a formatter Logger with the specified name.
 * <p>
 * This logger let you use a {@link java.util.Formatter} string in the message to format parameters.
 * </p>
 * <p>
 * Short-hand for {@code getLogger(name, StringFormatterMessageFactory.INSTANCE)}
 * </p>
 *
 * @param name The logger name. If null it will default to the name of the calling class.
 * @return The Logger, created with a {@link StringFormatterMessageFactory}
 * @throws UnsupportedOperationException if {@code name} is {@code null} and the calling class cannot be determined.
 * @see Logger#fatal(Marker, String, Object...)
 * @see Logger#fatal(String, Object...)
 * @see Logger#error(Marker, String, Object...)
 * @see Logger#error(String, Object...)
 * @see Logger#warn(Marker, String, Object...)
 * @see Logger#warn(String, Object...)
 * @see Logger#info(Marker, String, Object...)
 * @see Logger#info(String, Object...)
 * @see Logger#debug(Marker, String, Object...)
 * @see Logger#debug(String, Object...)
 * @see Logger#trace(Marker, String, Object...)
 * @see Logger#trace(String, Object...)
 * @see StringFormatterMessageFactory
 */
public static Logger getFormatterLogger(final String name) {
  return name == null ? getFormatterLogger(StackLocatorUtil.getCallerClass(2)) : getLogger(name,
      StringFormatterMessageFactory.INSTANCE);
}

代码示例来源:origin: org.apache.logging.log4j/log4j-api

@Test
public void getFormatterLogger() {
  // 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 TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger();
  final TestLogger altLogger = (TestLogger) LogManager.getFormatterLogger(getClass());
  assertEquals(testLogger.getName(), altLogger.getName());
  assertNotNull(testLogger);
  assertMessageFactoryInstanceOf(testLogger.getMessageFactory(), StringFormatterMessageFactory.class);
  assertEqualMessageFactory(StringFormatterMessageFactory.INSTANCE, testLogger);
  testLogger.debug("%,d", Integer.MAX_VALUE);
  assertEquals(1, testLogger.getEntries().size());
  assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0));
}

代码示例来源:origin: org.apache.logging.log4j/log4j-api

@Test
public void getFormatterLogger_Class() {
  // 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 TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger(TestStringFormatterMessageFactory.class);
  assertNotNull(testLogger);
  assertMessageFactoryInstanceOf(testLogger.getMessageFactory(), StringFormatterMessageFactory.class);
  assertEqualMessageFactory(StringFormatterMessageFactory.INSTANCE, testLogger);
  testLogger.debug("%,d", Integer.MAX_VALUE);
  assertEquals(1, testLogger.getEntries().size());
  assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0));
}

代码示例来源:origin: org.apache.logging.log4j/log4j-api

@Test
public void getFormatterLogger_String() {
  final StringFormatterMessageFactory messageFactory = StringFormatterMessageFactory.INSTANCE;
  final TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger("getLogger_String_StringFormatterMessageFactory");
  assertNotNull(testLogger);
  assertMessageFactoryInstanceOf(testLogger.getMessageFactory(), StringFormatterMessageFactory.class);
  assertEqualMessageFactory(messageFactory, testLogger);
  testLogger.debug("%,d", Integer.MAX_VALUE);
  assertEquals(1, testLogger.getEntries().size());
  assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0));
}

代码示例来源:origin: org.apache.logging.log4j/log4j-api

@Test
public void getFormatterLogger_Object() {
  // 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 TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger(new TestStringFormatterMessageFactory());
  assertNotNull(testLogger);
  assertMessageFactoryInstanceOf(testLogger.getMessageFactory(), StringFormatterMessageFactory.class);
  assertEqualMessageFactory(StringFormatterMessageFactory.INSTANCE, testLogger);
  testLogger.debug("%,d", Integer.MAX_VALUE);
  assertEquals(1, testLogger.getEntries().size());
  assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0));
}

代码示例来源:origin: apache/activemq-artemis

public Log4J2LogImpl(String category) {
  logger=LogManager.getFormatterLogger(category);
}

代码示例来源:origin: apache/activemq-artemis

public Log4J2LogImpl(Class<?> category) {
  logger = LogManager.getFormatterLogger(category);
}

代码示例来源:origin: org.apache.activemq/artemis-jms-client-all

public Log4J2LogImpl(String category) {
  logger=LogManager.getFormatterLogger(category);
}

代码示例来源:origin: apache/activemq-artemis

public Log4J2LogImpl(String category) {
  logger=LogManager.getFormatterLogger(category);
}

代码示例来源:origin: apache/activemq-artemis

public Log4J2LogImpl(Class<?> category) {
  logger = LogManager.getFormatterLogger(category);
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

public Log4J2LogImpl(Class<?> category) {
  logger = LogManager.getFormatterLogger(category);
}

代码示例来源:origin: org.apache.activemq/artemis-jms-client-all

public Log4J2LogImpl(Class<?> category) {
  logger = LogManager.getFormatterLogger(category);
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

public Log4J2LogImpl(String category) {
  logger=LogManager.getFormatterLogger(category);
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

/**
 * Returns a formatter Logger using the fully qualified name of the calling Class as the Logger name.
 * <p>
 * This logger lets you use a {@link java.util.Formatter} string in the message to format parameters.
 * </p>
 *
 * @return The Logger for the calling class.
 * @throws UnsupportedOperationException if the calling class cannot be determined.
 * @since 2.4
 */
public static Logger getFormatterLogger() {
  return getFormatterLogger(StackLocatorUtil.getCallerClass(2));
}

代码示例来源:origin: xresloader/xresloader

static public Logger getLoger() {
    if (null != logger) {
      return logger;
    }

    String name = "xresloader";
    InputStream inCfg = getInstance().getClass().getClassLoader().getResourceAsStream("application.properties");
    Properties props = new Properties();

    try {
      props.load(inCfg);
      name = props.getProperty("name");
    } catch (IOException e) {
      System.err.println(String.format("[ERROR] Get application name failed.\n%s", e.toString()));
    }

    try {
      logger = LogManager.getFormatterLogger(name);
    } catch (UnsupportedCharsetException e) {
      System.err.println(String.format("[WARN] Unknown console charset %s, we will try use UTF-8 for console output", e.getCharsetName()));
    }

    if (null == logger) {
      //logger = LogManager.get
    }
    return logger;
  }
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

/**
 * Returns a formatter Logger with the specified name.
 * <p>
 * This logger let you use a {@link java.util.Formatter} string in the message to format parameters.
 * </p>
 * <p>
 * Short-hand for {@code getLogger(name, StringFormatterMessageFactory.INSTANCE)}
 * </p>
 *
 * @param name The logger name. If null it will default to the name of the calling class.
 * @return The Logger, created with a {@link StringFormatterMessageFactory}
 * @throws UnsupportedOperationException if {@code name} is {@code null} and the calling class cannot be determined.
 * @see Logger#fatal(Marker, String, Object...)
 * @see Logger#fatal(String, Object...)
 * @see Logger#error(Marker, String, Object...)
 * @see Logger#error(String, Object...)
 * @see Logger#warn(Marker, String, Object...)
 * @see Logger#warn(String, Object...)
 * @see Logger#info(Marker, String, Object...)
 * @see Logger#info(String, Object...)
 * @see Logger#debug(Marker, String, Object...)
 * @see Logger#debug(String, Object...)
 * @see Logger#trace(Marker, String, Object...)
 * @see Logger#trace(String, Object...)
 * @see StringFormatterMessageFactory
 */
public static Logger getFormatterLogger(final String name) {
  return name == null ? getFormatterLogger(StackLocatorUtil.getCallerClass(2)) : getLogger(name,
      StringFormatterMessageFactory.INSTANCE);
}

相关文章