1 package org.simantics.utils.logging;
3 import java.text.DecimalFormat;
4 import java.text.NumberFormat;
6 public class TimeLogger {
7 public static final boolean TIME_LOGGING_ENABLED = false;
9 private static final NumberFormat TIME_FORMAT = new DecimalFormat("0.000");
11 private static long BEGIN_TIME = System.nanoTime();
13 private static void printCurrentTime() {
14 double time = (System.nanoTime() - BEGIN_TIME) * 1e-9;
15 System.out.print("[");
16 System.out.print(TIME_FORMAT.format(time));
17 System.out.print(" s] ");
20 public static void resetTimeAndLog(String message) {
21 if(TIME_LOGGING_ENABLED) {
22 BEGIN_TIME = System.nanoTime();
24 System.out.print(message);
25 System.out.print(" ");
26 for(int i=0;i<140-message.length();++i)
27 System.out.print("=");
32 public static void resetTimeAndLog(Class<?> clazz, String method) {
33 if(TIME_LOGGING_ENABLED)
34 resetTimeAndLog(clazz.getSimpleName() + "." + method);
37 public static void resetTime() {
38 if(TIME_LOGGING_ENABLED)
39 BEGIN_TIME = System.nanoTime();
42 public static void log(String message) {
43 if(TIME_LOGGING_ENABLED) {
45 System.out.println(message);
49 public static void log(Class<?> clazz, String method) {
50 if(TIME_LOGGING_ENABLED)
51 log(clazz.getSimpleName() + "." + method);