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

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

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

Logger.catching介绍

[英]Logs an exception or error that has been caught. Normally, one may wish to provide additional information with an exception while logging it; in these cases, one would not use this method. In other cases where simply logging the fact that an exception was swallowed somewhere (e.g., at the top of the stack trace in a main()method), this method is ideal for it.
[中]记录已捕获的异常或错误。通常,人们可能希望在记录时提供附加信息,但有例外;在这些情况下,人们不会使用这种方法。在其他情况下,如果只记录某个地方(例如,main()方法中堆栈跟踪的顶部)发生了异常,则此方法非常适合。

代码示例

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

public static void main(final String[] args) {
  System.setProperty("log4j.skipJansi", "false"); // LOG4J2-2087: explicitly enable
  // System.out.println(System.getProperty("java.class.path"));
  final String config = args.length == 0 ? "target/test-classes/log4j2-180.xml" : args[0];
  try (final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(),
      config)) {
    LOG.fatal("Fatal message.");
    LOG.error("Error message.");
    LOG.warn("Warning message.");
    LOG.info("Information message.");
    LOG.debug("Debug message.");
    LOG.trace("Trace message.");
    try {
      throw new NullPointerException();
    } catch (final Exception e) {
      LOG.error("Error message.", e);
      LOG.catching(Level.ERROR, e);
    }
  }
}

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

public static void main(final String[] args) {
  System.setProperty("log4j.skipJansi", "false"); // LOG4J2-2087: explicitly enable
  // System.out.println(System.getProperty("java.class.path"));
  final String config = args.length == 0 ? "target/test-classes/log4j2-272.xml" : args[0];
  try (final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(), config)) {
    LOG.fatal("Fatal message.");
    LOG.error("Error message.");
    LOG.warn("Warning message.");
    LOG.info("Information message.");
    LOG.debug("Debug message.");
    LOG.trace("Trace message.");
    try {
      throw new NullPointerException();
    } catch (final Exception e) {
      LOG.error("Error message.", e);
      LOG.catching(Level.ERROR, e);
    }
    LOG.warn("this is ok \n And all \n this have only\t\tblack colour \n and here is colour again?");
    LOG.info("Information message.");
  }
}

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

@Test
public void catching() {
  try {
    throw new NullPointerException();
  } catch (final Exception e) {
    logger.catching(e);
  }
  final List<LogEvent> events = app.getEvents();
  assertEquals("Incorrect number of events. Expected 1, actual " + events.size(), 1, events.size());
}

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

public static void main(final String[] args) {
  System.setProperty("log4j.skipJansi", "false"); // LOG4J2-2087: explicitly enable
  // System.out.println(System.getProperty("java.class.path"));
  final String config = args.length == 0 ? "target/test-classes/log4j2-319.xml" : args[0];
  try (final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(),
      config)) {
    LOG.fatal("Fatal message.");
    LOG.error("Error message.");
    LOG.warn("Warning message.");
    LOG.info("Information message.");
    LOG.debug("Debug message.");
    LOG.trace("Trace message.");
    try {
      throw new NullPointerException();
    } catch (final Exception e) {
      LOG.error("Error message.", e);
      LOG.catching(Level.ERROR, e);
    }
    LOG.warn("this is ok \n And all \n this have only\t\tblack colour \n and here is colour again?");
    LOG.info("Information message.");
  }
}

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

@Test
public void catching() {
  try {
    throw new NullPointerException();
  } catch (final Exception e) {
    logger.catching(e);
  }
  final List<LogEvent> events = app.getEvents();
  assertEventCount(events, 1);
}

代码示例来源:origin: org.smartboot.sosa/smartboot-sosa-core

@Override
  public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
    LOGGER.catching(cause);
    ctx.close();
  }
}

代码示例来源:origin: mopemope/meghanada-server

public void shutdown() {
 this.executorService.shutdown();
 try {
  this.executorService.awaitTermination(3, TimeUnit.SECONDS);
 } catch (InterruptedException e) {
  log.catching(e);
 }
}

代码示例来源:origin: mopemope/meghanada-server

private synchronized void closeIndexWriter() {
 if (nonNull(this.indexWriter)) {
  try {
   this.indexWriter.close();
  } catch (IOException e) {
   log.catching(e);
  }
 }
 this.indexWriter = null;
}

代码示例来源:origin: mopemope/meghanada-server

public static File getInstalledPath() {
 try {
  return new File(
    Config.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
 } catch (URISyntaxException e) {
  log.catching(e);
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: com.gitlab.cdc-java.util/cdc-util-data

public static String toString(Document doc,
               String indent,
               XmlWriter.Feature... features) {
  try (StringWriter writer = new StringWriter()) {
    save(doc, writer, indent, features);
    return writer.toString();
  } catch (final IOException e) {
    LOGGER.catching(e);
  }
  return null;
}

代码示例来源:origin: mopemope/meghanada-server

private void writeError(final long id, final Throwable t) {
 log.catching(t);
 try {
  final String out = outputFormatter.error(id, t);
  writer.write(out);
  writer.newLine();
 } catch (IOException e) {
  log.catching(e);
  throw new CommandException(e);
 }
}

代码示例来源:origin: mopemope/meghanada-server

private synchronized void closeIndexSearcher() {
 if (nonNull(this.indexSearcher)) {
  try {
   this.indexSearcher.close();
  } catch (IOException e) {
   log.catching(e);
  }
 }
 this.indexSearcher = null;
}

代码示例来源:origin: fbacchella/LogHub

@Override
public void stopSending() {
  try {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    mbs.unregisterMBean(new ObjectName("loghub:type=sender,servicename=" + getName() + ",name=connectionsPool"));
  } catch (MalformedObjectNameException | MBeanRegistrationException | InstanceNotFoundException e) {
    logger.error("Failed to unregister mbeam: " + Helpers.resolveThrowableException(e), e);
    logger.catching(Level.DEBUG, e);
  }
  super.stopSending();
}

代码示例来源:origin: mopemope/meghanada-server

private void requestAsyncStore(StoreRequest req) {
 if (isNull(req.getStorable()) && isNull(req.getStorables())) {
  throw new IllegalArgumentException("require obj or objects");
 }
 try {
  this.blockingQueue.put(req);
  this.runWorker();
 } catch (InterruptedException e) {
  log.catching(e);
 }
}

代码示例来源:origin: fbacchella/LogHub

@Override
public void close() {
  try {
    snmp.close();
  } catch (IOException e1) {
    logger.error("Failure on snmp close: {}", e1);
    logger.catching(e1);
  }
  super.close();
}

代码示例来源:origin: fbacchella/LogHub

@Override
public void onChannelInitializeException(ChannelHandlerContext arg0, Throwable error) {
  logger.fatal("Beats initialization exception: {}", Helpers.resolveThrowableException(error));
  logger.catching(Level.DEBUG, error);
}

代码示例来源:origin: fbacchella/LogHub

@Override
public void exception(ChannelHandlerContext ctx, Throwable cause) {
  logger.error("Unable to process query: {}", Helpers.resolveThrowableException(cause));
  logger.catching(Level.DEBUG, cause);
  ctx.pipeline().addAfter("HttpObjectAggregator", "FatalErrorHandler", getFatalErrorHandler());
}

代码示例来源:origin: mopemope/meghanada-server

@Override
 public void close() {
  try {
   this.closeIndexSearcher();
   this.closeIndexWriter();
   this.directory.close();
  } catch (Throwable e) {
   log.catching(e);
  }
 }
}

代码示例来源:origin: com.gitlab.cdc-java.util/cdc-util-data

protected static void print(Node node) {
  try {
    OUT.println("=====================");
    XmlDataWriter.print(node, false, OUT, "  ", false, XmlWriter.Feature.APPEND_FINAL_EOL);
    OUT.println();
  } catch (final IOException e) {
    LOGGER.catching(e);
  }
}

代码示例来源:origin: mopemope/meghanada-server

@Test
public void testConvertPathToClass1() throws Exception {
 File f =
   new File(project.getProjectRootPath(), "./src/main/java/meghanada/session/Session.java")
     .getCanonicalFile();
 try {
  Optional<String> s = FileUtils.convertPathToClass(project.getAllSources(), f);
  log.info("{}", s);
 } catch (IOException e) {
  log.catching(e);
 }
}

相关文章