import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
public class TimeUtil {
public static long start;
public static long end;
final static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss.SSS");
public static long start(){
start = System.currentTimeMillis();
return start;
}
public static void end(){
end = System.currentTimeMillis();
}
public static void takeTime(){
System.out.println("# 실행시간: " + (end - start) + " ms");
}
public static String getCurrentTimeFormatted(){
return LocalTime.now().format(formatter);
}
public static long getCurrentTime(){
return System.currentTimeMillis();
}
public static void sleep(long interval){
try {
Thread.sleep(interval);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public enum LogType {
ON_SUBSCRIBE("onSubscribe()"),
ON_NEXT("onNext()"),
ON_ERROR("onERROR()"),
ON_COMPLETE("onComplete()"),
ON_SUCCESS("onSuccess()"),
DO_ON_SUBSCRIBE("doOnSubscribe()"),
DO_ON_NEXT("doOnNext()"),
DO_ON_COMPLETE("doOnComplete()"),
DO_ON_EACH("doOnEach()"),
DO_ON_DISPOSE("doOnDispose()"),
DO_ON_ERROR("donOnError()"),
PRINT("print()");
private String logType;
LogType(String logType) {
this.logType = logType;
}
public String getLogType() {
return logType;
}
}
public class Logger {
public static void log(String msg){
String time = TimeUtil.getCurrentTimeFormatted();
System.out.println(msg + " | " + Thread.currentThread().getName() + " | " + time);
}
public static void log(String msg, Object obj){
String time = TimeUtil.getCurrentTimeFormatted();
System.out.println(msg + " | " + Thread.currentThread().getName() + " | " + time + " | " +obj);
}
public static void log(LogType logType){
String time = TimeUtil.getCurrentTimeFormatted();
System.out.println(logType.getLogType() + " | " + Thread.currentThread().getName() + " | " + time);
}
public static void log(LogType logType, Object obj){
String time = TimeUtil.getCurrentTimeFormatted();
System.out.println(logType.getLogType() + " | " + Thread.currentThread().getName() + " | " + time + " | " +obj);
}
}
public class DateUtil {
public static String getNowDate(){
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
.format(Calendar.getInstance().getTime());
}
}