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

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

本文整理了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

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

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

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

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

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

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

  1. /**
  2. * Returns a formatter Logger with the specified name.
  3. * <p>
  4. * This logger let you use a {@link java.util.Formatter} string in the message to format parameters.
  5. * </p>
  6. * <p>
  7. * Short-hand for {@code getLogger(name, StringFormatterMessageFactory.INSTANCE)}
  8. * </p>
  9. *
  10. * @param name The logger name. If null it will default to the name of the calling class.
  11. * @return The Logger, created with a {@link StringFormatterMessageFactory}
  12. * @throws UnsupportedOperationException if {@code name} is {@code null} and the calling class cannot be determined.
  13. * @see Logger#fatal(Marker, String, Object...)
  14. * @see Logger#fatal(String, Object...)
  15. * @see Logger#error(Marker, String, Object...)
  16. * @see Logger#error(String, Object...)
  17. * @see Logger#warn(Marker, String, Object...)
  18. * @see Logger#warn(String, Object...)
  19. * @see Logger#info(Marker, String, Object...)
  20. * @see Logger#info(String, Object...)
  21. * @see Logger#debug(Marker, String, Object...)
  22. * @see Logger#debug(String, Object...)
  23. * @see Logger#trace(Marker, String, Object...)
  24. * @see Logger#trace(String, Object...)
  25. * @see StringFormatterMessageFactory
  26. */
  27. public static Logger getFormatterLogger(final String name) {
  28. return name == null ? getFormatterLogger(StackLocatorUtil.getCallerClass(2)) : getLogger(name,
  29. StringFormatterMessageFactory.INSTANCE);
  30. }

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

  1. @Test
  2. public void getFormatterLogger() {
  3. // The TestLogger logger was already created in an instance variable for this class.
  4. // The message factory is only used when the logger is created.
  5. final TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger();
  6. final TestLogger altLogger = (TestLogger) LogManager.getFormatterLogger(getClass());
  7. assertEquals(testLogger.getName(), altLogger.getName());
  8. assertNotNull(testLogger);
  9. assertMessageFactoryInstanceOf(testLogger.getMessageFactory(), StringFormatterMessageFactory.class);
  10. assertEqualMessageFactory(StringFormatterMessageFactory.INSTANCE, testLogger);
  11. testLogger.debug("%,d", Integer.MAX_VALUE);
  12. assertEquals(1, testLogger.getEntries().size());
  13. assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0));
  14. }

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

  1. @Test
  2. public void getFormatterLogger_Class() {
  3. // The TestLogger logger was already created in an instance variable for this class.
  4. // The message factory is only used when the logger is created.
  5. final TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger(TestStringFormatterMessageFactory.class);
  6. assertNotNull(testLogger);
  7. assertMessageFactoryInstanceOf(testLogger.getMessageFactory(), StringFormatterMessageFactory.class);
  8. assertEqualMessageFactory(StringFormatterMessageFactory.INSTANCE, testLogger);
  9. testLogger.debug("%,d", Integer.MAX_VALUE);
  10. assertEquals(1, testLogger.getEntries().size());
  11. assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0));
  12. }

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

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

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

  1. @Test
  2. public void getFormatterLogger_Object() {
  3. // The TestLogger logger was already created in an instance variable for this class.
  4. // The message factory is only used when the logger is created.
  5. final TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger(new TestStringFormatterMessageFactory());
  6. assertNotNull(testLogger);
  7. assertMessageFactoryInstanceOf(testLogger.getMessageFactory(), StringFormatterMessageFactory.class);
  8. assertEqualMessageFactory(StringFormatterMessageFactory.INSTANCE, testLogger);
  9. testLogger.debug("%,d", Integer.MAX_VALUE);
  10. assertEquals(1, testLogger.getEntries().size());
  11. assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0));
  12. }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  1. static public Logger getLoger() {
  2. if (null != logger) {
  3. return logger;
  4. }
  5. String name = "xresloader";
  6. InputStream inCfg = getInstance().getClass().getClassLoader().getResourceAsStream("application.properties");
  7. Properties props = new Properties();
  8. try {
  9. props.load(inCfg);
  10. name = props.getProperty("name");
  11. } catch (IOException e) {
  12. System.err.println(String.format("[ERROR] Get application name failed.\n%s", e.toString()));
  13. }
  14. try {
  15. logger = LogManager.getFormatterLogger(name);
  16. } catch (UnsupportedCharsetException e) {
  17. System.err.println(String.format("[WARN] Unknown console charset %s, we will try use UTF-8 for console output", e.getCharsetName()));
  18. }
  19. if (null == logger) {
  20. //logger = LogManager.get
  21. }
  22. return logger;
  23. }
  24. }

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

  1. /**
  2. * Returns a formatter Logger with the specified name.
  3. * <p>
  4. * This logger let you use a {@link java.util.Formatter} string in the message to format parameters.
  5. * </p>
  6. * <p>
  7. * Short-hand for {@code getLogger(name, StringFormatterMessageFactory.INSTANCE)}
  8. * </p>
  9. *
  10. * @param name The logger name. If null it will default to the name of the calling class.
  11. * @return The Logger, created with a {@link StringFormatterMessageFactory}
  12. * @throws UnsupportedOperationException if {@code name} is {@code null} and the calling class cannot be determined.
  13. * @see Logger#fatal(Marker, String, Object...)
  14. * @see Logger#fatal(String, Object...)
  15. * @see Logger#error(Marker, String, Object...)
  16. * @see Logger#error(String, Object...)
  17. * @see Logger#warn(Marker, String, Object...)
  18. * @see Logger#warn(String, Object...)
  19. * @see Logger#info(Marker, String, Object...)
  20. * @see Logger#info(String, Object...)
  21. * @see Logger#debug(Marker, String, Object...)
  22. * @see Logger#debug(String, Object...)
  23. * @see Logger#trace(Marker, String, Object...)
  24. * @see Logger#trace(String, Object...)
  25. * @see StringFormatterMessageFactory
  26. */
  27. public static Logger getFormatterLogger(final String name) {
  28. return name == null ? getFormatterLogger(StackLocatorUtil.getCallerClass(2)) : getLogger(name,
  29. StringFormatterMessageFactory.INSTANCE);
  30. }

相关文章