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

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

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

throw logger.throwing(myException);

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

throw logger.throwing(myException);

代码示例

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

@Test
public void throwing() {
  logger.throwing(new IllegalArgumentException("Test Exception"));
  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

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

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

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

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

/**
 * A wrapper around a Consumer that throws a checked exception.
 *
 * @param unsafeConsumer Something that acts like a consumer but may throw an exception
 * @param logger Logger that used to log if an exception thrown
 * @return A consumer that is wrapped in a try-catch converting the checked exception into a runtime exception
 */
public static <T> Consumer<T> toConsumer(UnsafeConsumer<T> unsafeConsumer, Logger logger) {
  return t -> {
    try {
      unsafeConsumer.accept(t);
    } catch (Exception e) {
      throw logger.throwing(new RuntimeException(e));
    }
  };
}

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

@Override
public boolean send(Event event) {
  byte[] msg = getEncoder().encode(event);
  DatagramPacket packet = new DatagramPacket(msg, msg.length, IPAddress, port);
  try {
    socket.send(packet);
    return true;
  } catch (IOException e) {
    logger.error("unable to send message: {}", e);
    logger.throwing(Level.DEBUG, e);
    return false;
  }
}

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

@Override
public boolean send(Event event) {
  try {
    byte[] msg = getEncoder().encode(event);
    destination.write(msg);
    destination.println();
    destination.flush();
    return true;
  } catch (IOException e) {
    logger.error("failed to output {}: {}", event, e.getMessage());
    logger.throwing(Level.DEBUG, e);
    return false;
  }
}

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

@Override
  public void initChannel(CC ch) throws Exception {
    try {
      server.addHandlers(ch.pipeline());
      source.addHandlers(ch.pipeline());
      ClientFactory.this.addErrorHandler(ch.pipeline(), logger);
    } catch (Exception e) {
      logger.error("Netty handler failed: {}", e.getMessage());
      logger.throwing(Level.DEBUG, e);
    }
  }
};

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

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

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

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

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

@Override
public boolean configure(Properties properties) {
  customLogger = LogManager.getLogger("loghub.eventlogger." + pipeName);
  try {
    expression = new Expression(message, properties.groovyClassLoader, properties.formatters);
  } catch (ExpressionException e) {
    Throwable cause = e.getCause();
    if (cause instanceof CompilationFailedException) {
      logger.error("invalid groovy expression: {}", e.getMessage());
      return false;
    } else {
      logger.error("Critical groovy error: {}", e.getCause().getMessage());
      logger.throwing(Level.DEBUG, e.getCause());
      return false;
    }
  }
  return super.configure(properties);
}

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

@Override
public boolean configure(Properties properties) {
  try {
    script = new Expression(expression, properties.groovyClassLoader, properties.formatters);
  } catch (ExpressionException e) {
    Throwable cause = e.getCause();
    if (cause instanceof CompilationFailedException) {
      logger.error("invalid groovy expression: {}", e.getMessage());
      return false;
    } else {
      logger.error("Critical groovy error: {}", e.getCause().getMessage());
      logger.throwing(Level.DEBUG, e.getCause());
      return false;
    }
  }
  return super.configure(properties);
}

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

@Override
public void run(Action action) throws ActionFailureException, ActionParameterException {
  if (LOG.isTraceEnabled()) {
    LOG.entry(action);
  }
  
  final UUID actionDefinitionUuid = action.getAppliesToActionDefinition();
  final UUID providerUuid = actionDefinitionToProvider.get(actionDefinitionUuid);
  
  final Provider provider = providers.get(providerUuid);
  
  try {
    provider.run(action);
  } catch (ActionFailureException | ActionParameterException e) {
    LOG.throwing(e);
    throw e;
  } catch (Exception e) {
    // Any unknown or unexpected exceptions are wrapped as a failure and thrown.
    final ActionFailureException afe = new ActionFailureException(e);
    LOG.throwing(afe);
    throw afe;
  }
  
  if (LOG.isTraceEnabled()) {
    LOG.exit();
  }
}

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

@Override
public boolean configure(Properties properties) {
  try {
    script = new Expression(expression, properties.groovyClassLoader, properties.formatters);
  } catch (ExpressionException e) {
    Throwable cause = e.getCause();
    if (cause instanceof CompilationFailedException) {
      logger.error("invalid groovy expression: {}", e.getMessage());
      return false;
    } else {
      logger.error("Critical groovy error: {}", e.getCause().getMessage());
      logger.throwing(Level.DEBUG, e.getCause());
      return false;
    }
  }
  return super.configure(properties);
}
public String getExpression() {

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

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

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

final ActionParameterException t = new ActionParameterException(TitleParameterDefinition.INSTANCE.getName() + " is missing.");
if (logger.isTraceEnabled()) {
  logger.throwing(t);
final ActionParameterException t = new ActionParameterException(MessageParameterDefinition.INSTANCE.getName() + " is missing.");
if (logger.isTraceEnabled()) {
  logger.throwing(t);
final ActionParameterException t = new ActionParameterException(NotificationIconParameterDefinition.INSTANCE.getName() + " is missing.");
if (logger.isTraceEnabled()) {
  logger.throwing(t);
final ActionParameterException t = new ActionParameterException(DurationParameterDefinition.INSTANCE.getName() + " is missing.");
if (logger.isTraceEnabled()) {
  logger.throwing(t);
final ActionFailureException t = new ActionFailureException("Failed to build show notification message.", e);
if (logger.isTraceEnabled()) {
  logger.throwing(t);

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

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

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

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

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

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

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

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

相关文章