Example usage for java.util.logging Logger isLoggable

List of usage examples for java.util.logging Logger isLoggable

Introduction

In this page you can find the example usage for java.util.logging Logger isLoggable.

Prototype

public boolean isLoggable(Level level) 

Source Link

Document

Check if a message of the given level would actually be logged by this logger.

Usage

From source file:nl.strohalm.cyclos.utils.logging.LoggingHandler.java

/**
 * Logs an scheduling group execution/*  www . ja  v a 2 s. c o m*/
 * @param time The milliseconds the scheduling took to run
 */
public void logSchedulingTrace(final long time) {
    final Logger logger = getScheduledTaskLogger();
    final Level level = ScheduledTaskLevel.INFO.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 tasks ran on %s seconds", formattedTime));
        } catch (final Exception e) {
            System.out.println(
                    "Error generating log on " + settingsService.getLogSettings().getScheduledTaskFile());
        }
    }
}

From source file:nl.strohalm.cyclos.utils.logging.LoggingHandler.java

/**
 * Log a successful transfer/*from   w ww .  j  a va 2s . co  m*/
 */
public void logTransfer(Transfer transfer) {
    final Logger logger = getTransactionLogger();
    final Level detailed = TransactionLevel.DETAILED.getLevel();
    final Level normal = TransactionLevel.NORMAL.getLevel();
    final boolean detailedLoggable = logger.isLoggable(detailed);
    final boolean normalLoggable = logger.isLoggable(normal);
    final boolean willLog = detailedLoggable || normalLoggable;
    // Generate log if, at least, normal level is enabled
    if (willLog) {
        transfer = fetchService.fetch(transfer, RelationshipHelper.nested(Transfer.Relationships.FROM,
                Account.Relationships.TYPE, AccountType.Relationships.CURRENCY), Transfer.Relationships.TO);
        Level level;
        final LocalSettings localSettings = settingsService.getLocalSettings();
        final UnitsConverter unitsConverter = localSettings
                .getUnitsConverter(transfer.getFrom().getType().getCurrency().getPattern());
        String message;
        Object[] args;
        // Get the specific level arguments
        if (detailedLoggable) {
            final TransferType type = transfer.getType();
            level = detailed;
            message = "id: %s, date: %s, type: %s (%s), amount: %s, from: %s, to: %s, by: %s, tx#: %s, description: %s";
            final Element by = transfer.getBy();
            args = new Object[] { transfer.getId(),
                    localSettings.getDateTimeConverter().toString(transfer.getDate()), type.getId(),
                    type.getName(), unitsConverter.toString(transfer.getAmount()),
                    transfer.getFrom().getOwnerName(), transfer.getTo().getOwnerName(),
                    by == null ? "<null>" : by.getUsername(),
                    StringUtils.defaultIfEmpty(transfer.getTransactionNumber(), "<null>"),
                    StringUtils.replace(transfer.getDescription(), "\n", "\\n") };
        } else {
            level = normal;
            message = "id: %s, amount: %s, from: %s, to: %s";
            args = new Object[] { transfer.getId(), unitsConverter.toString(transfer.getAmount()),
                    transfer.getFrom().getOwnerName(), transfer.getTo().getOwnerName() };
        }
        try {
            logger.log(level, String.format(message, args));
        } catch (final Exception e) {
            System.out.println(
                    "Error generating log on " + settingsService.getLogSettings().getTransactionFile());
        }
    }
}

From source file:nl.strohalm.cyclos.utils.logging.LoggingHandler.java

/**
 * Logs an action trace/*  www.  j ava  2 s . c o  m*/
 */
public void trace(final String remoteAddress, final User user, final Permission permission, final Method method,
        final Object[] args, final Object retVal) {
    final Logger logger = getTraceLogger();
    final Level detailed = TraceLevel.DETAILED.getLevel();
    final Level normal = TraceLevel.SIMPLE.getLevel();
    final boolean detailedLoggable = logger.isLoggable(detailed);
    final boolean normalLoggable = logger.isLoggable(normal);
    final Level logLevel = detailedLoggable ? detailed : normalLoggable ? normal : null;
    if (logLevel != null) {
        final String prefix = StringUtils.isEmpty(remoteAddress) ? "" : remoteAddress + " - ";
        final String message = buildActionString(user, permission, method, args, retVal, true);
        try {
            logger.log(logLevel, prefix + message);
        } 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 an action error/*  w w  w  .  j  a v a  2s  .c o  m*/
 */
public void traceError(final User user, final Permission permission, final Method method, final Object[] args,
        final Throwable t) {
    final Logger logger = getTraceLogger();
    final Level level = TraceLevel.ERRORS.getLevel();
    if (logger.isLoggable(level)) {
        try {
            logger.log(level, "Error on " + buildActionString(user, permission, method, args, null, false), t);
        } catch (final Exception e) {
            System.out.println(
                    "Error generating error log on " + settingsService.getLogSettings().getTraceFile());
        }
    }
}

From source file:nl.strohalm.cyclos.utils.logging.LoggingHandler.java

/**
 * Logs an user login/*from  www  .  ja va 2  s.  c  om*/
 */
public void traceLogin(final String remoteAddress, final User user, final String sessionId) {
    final Logger logger = getTraceLogger();
    final Level level = TraceLevel.SIMPLE.getLevel();
    if (logger.isLoggable(level)) {
        try {
            logger.log(level, remoteAddress + " - Login for " + user + " under session id " + sessionId);
        } 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 an user logout/* www .j  a  v a 2s . c o  m*/
 */
public void traceLogout(final String remoteAddress, final User user, final String sessionId) {
    final Logger logger = getTraceLogger();
    final Level level = TraceLevel.SIMPLE.getLevel();
    if (logger.isLoggable(level)) {
        try {
            logger.log(level, remoteAddress + " - Logout for " + user + " under session id " + sessionId);
        } catch (final Exception e) {
            System.out.println("Error generating log on " + settingsService.getLogSettings().getTraceFile());
        }
    }
}

From source file:nl.strohalm.cyclos.utils.logging.LoggingHandler.java

public void traceWebServiceError(final String error) {
    final Logger logger = getTraceLogger();
    final Level level = TraceLevel.ERRORS.getLevel();
    if (logger.isLoggable(level)) {
        error(logger, level, settingsService.getLogSettings().getTraceFile(), "Unknown IP", error, null);
    }/*from   w w w  . ja v a  2  s.  co  m*/
}

From source file:nl.strohalm.cyclos.utils.logging.LoggingHandler.java

public void traceWebServiceError(final String remoteAddress, final Pos pos, final String methodName,
        final Map<String, Object> parameters, final Throwable th) {
    final Logger logger = getTraceLogger();
    final Level level = TraceLevel.ERRORS.getLevel();
    if (logger.isLoggable(level)) {
        error(logger, level, settingsService.getLogSettings().getTraceFile(), remoteAddress,
                buildWebServiceActionString(pos, methodName, parameters), th);
    }/*from  w w  w.j  av  a2 s  .c o m*/
}

From source file:nl.strohalm.cyclos.utils.logging.LoggingHandler.java

public void traceWebServiceError(final String remoteAddress, final ServiceClient serviceClient,
        final String methodName, final Map<String, Object> parameters, final Throwable th) {
    final Logger logger = getTraceLogger();
    final Level level = TraceLevel.ERRORS.getLevel();
    if (logger.isLoggable(level)) {
        error(logger, level, settingsService.getLogSettings().getTraceFile(), remoteAddress,
                buildWebServiceActionString(serviceClient, methodName, parameters), th);
    }/*  w  ww  .  j a v a2 s .co  m*/
}

From source file:nl.strohalm.cyclos.utils.logging.LoggingHandler.java

public void traceWebServiceError(final Throwable th) {
    final Logger logger = getTraceLogger();
    final Level level = TraceLevel.ERRORS.getLevel();
    if (logger.isLoggable(level)) {
        error(logger, level, settingsService.getLogSettings().getTraceFile(), "Unknown IP", "Unknown method",
                th);/*from w w w.  ja  v a2 s.c  o  m*/
    }
}