@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()); }
@Test public void throwing() { logger.throwing(new IllegalArgumentException("Test Exception")); final List<LogEvent> events = app.getEvents(); assertEventCount(events, 1); }
/** * 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)); } }; }
/** * 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)); } }; }
@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; } }
@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; } }
@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); } } };
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()); } }
newCtxt = null; logger.error("Can't configurer SSL context: {}", e.getMessage()); logger.throwing(Level.DEBUG, e);
@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); }
@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); }
@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(); } }
@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() {
} catch (ScriptException e) { logger.error("execution of script {} failed: {}", script, e); logger.throwing(Level.DEBUG, e); return false; } catch (NoSuchMethodException e) {
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);
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);
} catch (ParseException e) { if (LOG.isTraceEnabled()) { LOG.throwing(e);
Stats.newException(cce); logger.error("A not AsyncProcessor {} throws a asynchronous operation", p); logger.throwing(Level.DEBUG, cce); status = ProcessingStatus.FAILED;