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

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

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

Logger.throwing介绍

[英]Logs an exception or error to be thrown. This may be coded as:

  1. throw logger.throwing(myException);

[中]记录要引发的异常或错误。这可能被编码为:

  1. throw logger.throwing(myException);

代码示例

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

  1. @Test
  2. public void throwing() {
  3. logger.throwing(new IllegalArgumentException("Test Exception"));
  4. final List<LogEvent> events = app.getEvents();
  5. assertEquals("Incorrect number of events. Expected 1, actual " + events.size(), 1, events.size());
  6. }

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

  1. @Test
  2. public void throwing() {
  3. logger.throwing(new IllegalArgumentException("Test Exception"));
  4. final List<LogEvent> events = app.getEvents();
  5. assertEventCount(events, 1);
  6. }

代码示例来源:origin: com.visionarts/power-jambda-core

  1. /**
  2. * A wrapper around a Consumer that throws a checked exception.
  3. *
  4. * @param unsafeBiConsumer Something that acts like a consumer but may throw an exception
  5. * @param logger Logger that used to log if an exception thrown
  6. * @return A consumer that is wrapped in a try-catch converting the checked exception into a runtime exception
  7. */
  8. public static <T, U> BiConsumer<T, U> toBiConsumer(UnsafeBiConsumer<T, U> unsafeBiConsumer, Logger logger) {
  9. return (t, u) -> {
  10. try {
  11. unsafeBiConsumer.accept(t, u);
  12. } catch (Exception e) {
  13. throw logger.throwing(new RuntimeException(e));
  14. }
  15. };
  16. }

代码示例来源:origin: com.visionarts/power-jambda-core

  1. /**
  2. * A wrapper around a Consumer that throws a checked exception.
  3. *
  4. * @param unsafeConsumer Something that acts like a consumer but may throw an exception
  5. * @param logger Logger that used to log if an exception thrown
  6. * @return A consumer that is wrapped in a try-catch converting the checked exception into a runtime exception
  7. */
  8. public static <T> Consumer<T> toConsumer(UnsafeConsumer<T> unsafeConsumer, Logger logger) {
  9. return t -> {
  10. try {
  11. unsafeConsumer.accept(t);
  12. } catch (Exception e) {
  13. throw logger.throwing(new RuntimeException(e));
  14. }
  15. };
  16. }

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

  1. @Override
  2. public boolean send(Event event) {
  3. byte[] msg = getEncoder().encode(event);
  4. DatagramPacket packet = new DatagramPacket(msg, msg.length, IPAddress, port);
  5. try {
  6. socket.send(packet);
  7. return true;
  8. } catch (IOException e) {
  9. logger.error("unable to send message: {}", e);
  10. logger.throwing(Level.DEBUG, e);
  11. return false;
  12. }
  13. }

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

  1. @Override
  2. public boolean send(Event event) {
  3. try {
  4. byte[] msg = getEncoder().encode(event);
  5. destination.write(msg);
  6. destination.println();
  7. destination.flush();
  8. return true;
  9. } catch (IOException e) {
  10. logger.error("failed to output {}: {}", event, e.getMessage());
  11. logger.throwing(Level.DEBUG, e);
  12. return false;
  13. }
  14. }

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

  1. @Override
  2. public void initChannel(CC ch) throws Exception {
  3. try {
  4. server.addHandlers(ch.pipeline());
  5. source.addHandlers(ch.pipeline());
  6. ClientFactory.this.addErrorHandler(ch.pipeline(), logger);
  7. } catch (Exception e) {
  8. logger.error("Netty handler failed: {}", e.getMessage());
  9. logger.throwing(Level.DEBUG, e);
  10. }
  11. }
  12. };

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

  1. public static void logError(ExpressionException e, String source, Logger logger) {
  2. Throwable cause = e.getCause();
  3. if (cause instanceof CompilationFailedException) {
  4. logger.error("Groovy compilation failed for expression {}: {}", source, e.getMessage());
  5. } else {
  6. logger.error("Critical groovy error for expression {}: {}", source, e.getMessage());
  7. logger.throwing(Level.DEBUG, e.getCause());
  8. }
  9. }

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

  1. newCtxt = null;
  2. logger.error("Can't configurer SSL context: {}", e.getMessage());
  3. logger.throwing(Level.DEBUG, e);

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

  1. @Override
  2. public boolean configure(Properties properties) {
  3. customLogger = LogManager.getLogger("loghub.eventlogger." + pipeName);
  4. try {
  5. expression = new Expression(message, properties.groovyClassLoader, properties.formatters);
  6. } catch (ExpressionException e) {
  7. Throwable cause = e.getCause();
  8. if (cause instanceof CompilationFailedException) {
  9. logger.error("invalid groovy expression: {}", e.getMessage());
  10. return false;
  11. } else {
  12. logger.error("Critical groovy error: {}", e.getCause().getMessage());
  13. logger.throwing(Level.DEBUG, e.getCause());
  14. return false;
  15. }
  16. }
  17. return super.configure(properties);
  18. }

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

  1. @Override
  2. public boolean configure(Properties properties) {
  3. try {
  4. script = new Expression(expression, properties.groovyClassLoader, properties.formatters);
  5. } catch (ExpressionException e) {
  6. Throwable cause = e.getCause();
  7. if (cause instanceof CompilationFailedException) {
  8. logger.error("invalid groovy expression: {}", e.getMessage());
  9. return false;
  10. } else {
  11. logger.error("Critical groovy error: {}", e.getCause().getMessage());
  12. logger.throwing(Level.DEBUG, e.getCause());
  13. return false;
  14. }
  15. }
  16. return super.configure(properties);
  17. }

代码示例来源:origin: com.github.kmbulebu.nicknack/nicknack-core

  1. @Override
  2. public void run(Action action) throws ActionFailureException, ActionParameterException {
  3. if (LOG.isTraceEnabled()) {
  4. LOG.entry(action);
  5. }
  6. final UUID actionDefinitionUuid = action.getAppliesToActionDefinition();
  7. final UUID providerUuid = actionDefinitionToProvider.get(actionDefinitionUuid);
  8. final Provider provider = providers.get(providerUuid);
  9. try {
  10. provider.run(action);
  11. } catch (ActionFailureException | ActionParameterException e) {
  12. LOG.throwing(e);
  13. throw e;
  14. } catch (Exception e) {
  15. // Any unknown or unexpected exceptions are wrapped as a failure and thrown.
  16. final ActionFailureException afe = new ActionFailureException(e);
  17. LOG.throwing(afe);
  18. throw afe;
  19. }
  20. if (LOG.isTraceEnabled()) {
  21. LOG.exit();
  22. }
  23. }

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

  1. @Override
  2. public boolean configure(Properties properties) {
  3. try {
  4. script = new Expression(expression, properties.groovyClassLoader, properties.formatters);
  5. } catch (ExpressionException e) {
  6. Throwable cause = e.getCause();
  7. if (cause instanceof CompilationFailedException) {
  8. logger.error("invalid groovy expression: {}", e.getMessage());
  9. return false;
  10. } else {
  11. logger.error("Critical groovy error: {}", e.getCause().getMessage());
  12. logger.throwing(Level.DEBUG, e.getCause());
  13. return false;
  14. }
  15. }
  16. return super.configure(properties);
  17. }
  18. public String getExpression() {

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

  1. } catch (ScriptException e) {
  2. logger.error("execution of script {} failed: {}", script, e);
  3. logger.throwing(Level.DEBUG, e);
  4. return false;
  5. } catch (NoSuchMethodException e) {

代码示例来源:origin: com.github.kmbulebu.nicknack/xbmc-provider

  1. final ActionParameterException t = new ActionParameterException(TitleParameterDefinition.INSTANCE.getName() + " is missing.");
  2. if (logger.isTraceEnabled()) {
  3. logger.throwing(t);
  4. final ActionParameterException t = new ActionParameterException(MessageParameterDefinition.INSTANCE.getName() + " is missing.");
  5. if (logger.isTraceEnabled()) {
  6. logger.throwing(t);
  7. final ActionParameterException t = new ActionParameterException(NotificationIconParameterDefinition.INSTANCE.getName() + " is missing.");
  8. if (logger.isTraceEnabled()) {
  9. logger.throwing(t);
  10. final ActionParameterException t = new ActionParameterException(DurationParameterDefinition.INSTANCE.getName() + " is missing.");
  11. if (logger.isTraceEnabled()) {
  12. logger.throwing(t);
  13. final ActionFailureException t = new ActionFailureException("Failed to build show notification message.", e);
  14. if (logger.isTraceEnabled()) {
  15. logger.throwing(t);

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

  1. } catch (IOException e) {
  2. logger.error("can't read geoip database " + geoipdb.toString());
  3. logger.throwing(Level.DEBUG, e);
  4. return false;
  5. logger.throwing(Level.DEBUG, e);
  6. return false;

代码示例来源:origin: com.github.kmbulebu.nicknack/xbmc-provider

  1. final ActionParameterException t = new ActionParameterException(HostParameterDefinition.INSTANCE.getName() + " is missing.");
  2. if (logger.isTraceEnabled()) {
  3. logger.throwing(t);
  4. final ActionParameterException t = new ActionParameterException("Host " + host + " could not be found.");
  5. if (logger.isTraceEnabled()) {
  6. logger.throwing(t);

代码示例来源:origin: com.github.kmbulebu.nicknack/nicknack-core

  1. } catch (ParseException e) {
  2. if (LOG.isTraceEnabled()) {
  3. LOG.throwing(e);

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

  1. Stats.newException(cce);
  2. logger.error("A not AsyncProcessor {} throws a asynchronous operation", p);
  3. logger.throwing(Level.DEBUG, cce);
  4. status = ProcessingStatus.FAILED;

相关文章