List of usage examples for java.util.logging Logger isLoggable
public boolean isLoggable(Level level)
From source file:com.ibm.ws.lars.rest.RepositoryRESTResourceLoggingTest.java
@Test public void testGetAssetFieldSummary(@Mocked final Logger logger, @Mocked final UriInfo info, @Mocked SecurityContext sc)/*from w w w . jav a 2 s . co m*/ throws URISyntaxException, JsonProcessingException, InvalidParameterException { final MultivaluedMapImpl<String, String> parameters = new MultivaluedMapImpl<>(); parameters.add("fields", "xyz"); new Expectations() { { info.getQueryParameters(false); result = parameters; logger.isLoggable(Level.FINE); result = true; info.getRequestUri(); result = new URI("http://localhost:9085/ma/v1/assets/summary?fields=xyz"); logger.fine("getAssetFieldSummary called with query parameters: fields=xyz"); } }; getRestResource().getAssetFieldSummary(info, sc); }
From source file:edu.emory.cci.aiw.i2b2etl.dest.I2b2QueryResultsHandler.java
private void truncateTable(Connection conn, String tableName) throws SQLException { Logger logger = I2b2ETLUtil.logger(); String queryId = query.getName(); String sql = "TRUNCATE TABLE " + tableName; if (logger.isLoggable(Level.FINE)) { logger.log(Level.FINE, "Executing the following SQL for query {0}: {1}", new Object[] { queryId, sql }); }/* w w w. j av a 2 s . co m*/ try (final Statement st = conn.createStatement()) { st.execute(sql); logger.log(Level.FINE, "Done executing SQL for query {0}", queryId); } catch (SQLException ex) { logger.log(Level.SEVERE, "An error occurred truncating the tables for query " + queryId, ex); throw ex; } }
From source file:nl.strohalm.cyclos.utils.logging.LoggingHandler.java
/** * Log a tax error//from w w w. j a va2 s. c om */ public void logAccountFeeError(final AccountFeeLog feeLog, final Throwable error) { final Logger logger = getAccountFeeLogger(); final Level level = AccountFeeLevel.ERRORS.getLevel(); if (logger.isLoggable(level)) { try { logger.log(level, "Error on " + feeLog.getAccountFee().getName(), error); } catch (final Exception e) { System.out .println("Error generating log on " + settingsService.getLogSettings().getAccountFeeFile()); } } }
From source file:nl.strohalm.cyclos.utils.logging.LoggingHandler.java
/** * Log an account fee transfer/* w w w . ja v a2s.c om*/ */ public void logAccountFeeInvoice(final Invoice invoice) { final Logger logger = getAccountFeeLogger(); final Level level = AccountFeeLevel.DETAILED.getLevel(); if (logger.isLoggable(level)) { final UnitsConverter unitsConverter = settingsService.getLocalSettings() .getUnitsConverter(invoice.getTransferType().getFrom().getCurrency().getPattern()); final String message = "Sent invoice of %s from %s"; final Object[] params = { unitsConverter.toString(invoice.getAmount()), invoice.getToMember().getUsername() }; try { logger.log(level, String.format(message, params)); } catch (final Exception e) { System.out .println("Error generating log on " + settingsService.getLogSettings().getAccountFeeFile()); } } }
From source file:nl.strohalm.cyclos.utils.logging.LoggingHandler.java
/** * Log an account fee transfer/*from ww w . j a v a2 s .co m*/ */ public void logAccountFeePayment(final Transfer transfer) { final Logger logger = getAccountFeeLogger(); final Level level = AccountFeeLevel.DETAILED.getLevel(); if (logger.isLoggable(level)) { final AccountFeeLog feeLog = transfer.getAccountFeeLog(); final AccountFee fee = feeLog.getAccountFee(); final UnitsConverter unitsConverter = settingsService.getLocalSettings() .getUnitsConverter(transfer.getFrom().getType().getCurrency().getPattern()); String message; Object[] params; if (fee.getPaymentDirection() == PaymentDirection.TO_SYSTEM) { message = "Charged %s from %s"; params = new Object[] { unitsConverter.toString(transfer.getAmount()), transfer.getFrom().getOwnerName() }; } else { message = "Paid %s to %s"; params = new Object[] { unitsConverter.toString(transfer.getAmount()), transfer.getTo().getOwnerName() }; } try { logger.log(level, String.format(message, params)); } catch (final Exception e) { System.out .println("Error generating log on " + settingsService.getLogSettings().getAccountFeeFile()); } } }
From source file:nl.strohalm.cyclos.utils.logging.LoggingHandler.java
/** * Log a tax status change//from w w w. jav a 2 s . co m */ public void logAccountFeeStatus(final AccountFeeLog feeLog) { final Logger logger = getAccountFeeLogger(); final Level level = AccountFeeLevel.STATUS.getLevel(); if (logger.isLoggable(level)) { String status = null; switch (feeLog.getStatus()) { case RUNNING: status = "Started"; break; case CANCELED: status = "Manually canceled"; break; case NEVER_RAN: status = "Never ran"; break; case PARTIALLY_FAILED: status = "Partially failed"; break; case FINISHED: status = "Finished"; break; } try { logger.log(level, feeLog.getAccountFee().getName() + ": " + status); } catch (final Exception e) { System.out .println("Error generating log on " + settingsService.getLogSettings().getAccountFeeFile()); } } }
From source file:nl.strohalm.cyclos.utils.logging.LoggingHandler.java
/** * Log a permission denied on action execution *///from w ww . j a v a 2s.co m public void logPermissionDenied(final User user, final Method method, final Object[] args) { final Logger logger = getTraceLogger(); final Level level = TraceLevel.ERRORS.getLevel(); if (logger.isLoggable(level)) { try { logger.log(level, "Permission denied for " + buildActionString(user, null, method, args, null, false)); } catch (final Exception e) { System.out.println("Error generating log on " + settingsService.getLogSettings().getTraceFile()); } } }
From source file:nl.strohalm.cyclos.utils.logging.LoggingHandler.java
/** * Logs that a request has been rejected because the account status queue is full *///from w w w. ja va 2s. c om public void logRequestRejectedOnSystemOverloaded(final String uri, final String remoteAddress) { final Logger logger = getTraceLogger(); final Level level = TraceLevel.ERRORS.getLevel(); if (logger.isLoggable(level)) { try { logger.log(level, "A request to " + uri + " from " + remoteAddress + " was rejected because the system is overloaded"); } catch (final Exception e) { System.out.println("Error generating log on " + settingsService.getLogSettings().getTraceFile()); } } }
From source file:nl.strohalm.cyclos.utils.logging.LoggingHandler.java
/** * Log a scheduled task error//from ww w . ja va 2s.c om */ public void logScheduledTaskError(final String taskName, final Exception error) { final Logger logger = getScheduledTaskLogger(); final Level level = ScheduledTaskLevel.ERRORS.getLevel(); if (logger.isLoggable(level)) { try { logger.log(level, "Exception on scheduled task: " + taskName, error); } catch (final Exception e) { System.out.println( "Error generating log on " + settingsService.getLogSettings().getScheduledTaskFile()); } } }
From source file:nl.strohalm.cyclos.utils.logging.LoggingHandler.java
/** * Logs a scheduled task execution//from w ww.j a va 2 s.c o m * @param taskName The task name * @param time The milliseconds the task took to run */ public void logScheduledTaskTrace(final String taskName, final long time) { final Logger logger = getScheduledTaskLogger(); final Level level = ScheduledTaskLevel.DETAILED.getLevel(); if (logger.isLoggable(level)) { final MathContext mathContext = settingsService.getLocalSettings().getMathContext(); final String formattedTime = settingsService.getLocalSettings().getNumberConverter() .toString(new BigDecimal(time).divide(new BigDecimal(1000), mathContext)); try { logger.log(level, String.format("Scheduled task '%s' ran on %s seconds", taskName, formattedTime)); } catch (final Exception e) { System.out.println( "Error generating log on " + settingsService.getLogSettings().getScheduledTaskFile()); } } }