Java slf4j Logger infoTimeTaken(final Logger log, final long startTime, final long numItems, final String message, final Object... args)

Here you can find the source of infoTimeTaken(final Logger log, final long startTime, final long numItems, final String message, final Object... args)

Description

info Time Taken

License

Apache License

Declaration

public static void infoTimeTaken(final Logger log, final long startTime, final long numItems,
            final String message, final Object... args) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import org.slf4j.Logger;

public class Main {
    private static final int MILLIES_PER_SECOND = 1000;

    public static void infoTimeTaken(final Logger log, final long startTime, final long numItems,
            final String message, final Object... args) { // NOPMD
        final double elapsedTimeInSeconds = (((double) System.currentTimeMillis()) - startTime)
                / MILLIES_PER_SECOND;/*from w ww .  j av a 2 s . c  o m*/
        final double itemsPerSecond = numItems / elapsedTimeInSeconds;
        final String timeInformation = String.format(" - took %.2f seconds to do %d items at %.2f per second.",
                elapsedTimeInSeconds, numItems, itemsPerSecond);
        info(log, message + timeInformation, args);
    }

    public static void info(final Logger log, final String message, final Object... args) {
        log.info(getFormattedMessage(message, args));
    }

    private static String getFormattedMessage(final String message, final Object... args) {
        String formattedMessage = message;
        if (args != null && args.length > 0) {
            formattedMessage = String.format(message, args);
        }
        return formattedMessage;
    }
}

Related

  1. info(Logger logger, String message, Object... objects)
  2. info(Logger logger, String msg)
  3. info(Logger logger, String msg, Object... params)
  4. info(String format, Object... arguments)
  5. infoLogging(Logger log, String logMessage, Object[] obj)
  6. interruptCurrentThreadWithLog(Logger logger)
  7. isLoggable(final Logger logger, final Level level)
  8. isSlf4jPresent()
  9. log(Logger logger, int logLevel, String value)