1 6 package org.logicalcobwebs.proxool.admin; 7 8 import org.apache.commons.logging.Log; 9 import org.logicalcobwebs.proxool.ProxoolConstants; 10 11 import java.text.DateFormat ; 12 import java.text.DecimalFormat ; 13 import java.text.SimpleDateFormat ; 14 15 22 public class StatisticsLogger implements StatisticsListenerIF { 23 24 private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat ("0.00"); 25 26 private static final DateFormat TIME_FORMAT = new SimpleDateFormat ("HH:mm:ss"); 27 28 private Log log; 29 30 private String logLevel; 31 32 public StatisticsLogger(Log log, String logLevel) { 33 this.log = log; 34 this.logLevel = logLevel; 35 } 36 37 public void statistics(String alias, StatisticsIF statistics) { 38 39 if (statistics != null && logLevel != null) { 40 41 StringBuffer out = new StringBuffer (); 42 43 out.append(TIME_FORMAT.format(statistics.getStartDate())); 44 out.append(" - "); 45 out.append(TIME_FORMAT.format(statistics.getStopDate())); 46 out.append(", s:"); 47 out.append(statistics.getServedCount()); 48 out.append(":"); 49 out.append(DECIMAL_FORMAT.format(statistics.getServedPerSecond())); 50 51 out.append("/s, r:"); 52 out.append(statistics.getRefusedCount()); 53 out.append(":"); 54 out.append(DECIMAL_FORMAT.format(statistics.getRefusedPerSecond())); 55 56 out.append("/s, a:"); 57 out.append(DECIMAL_FORMAT.format(statistics.getAverageActiveTime())); 58 out.append("ms/"); 59 out.append(DECIMAL_FORMAT.format(statistics.getAverageActiveCount())); 60 61 if (logLevel.equals(ProxoolConstants.STATISTICS_LOG_LEVEL_TRACE)) { 62 log.trace(out.toString()); 63 } else if (logLevel.equals(ProxoolConstants.STATISTICS_LOG_LEVEL_DEBUG)) { 64 log.debug(out.toString()); 65 } else if (logLevel.equals(ProxoolConstants.STATISTICS_LOG_LEVEL_INFO)) { 66 log.info(out.toString()); 67 } 68 69 } 70 71 } 72 } 73 74 75 | Popular Tags |