From 81da25d53389e14fa81c5091cb7595af592ff45d Mon Sep 17 00:00:00 2001 From: jun0315 <1072505283@qq.com> Date: Fri, 11 Jun 2021 13:53:07 +0800 Subject: [PATCH] feat:log print current time --- APIJSONORM/src/main/java/apijson/Log.java | 43 +++++++++++++++++++---- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/APIJSONORM/src/main/java/apijson/Log.java b/APIJSONORM/src/main/java/apijson/Log.java index eecc7e1c2..e3f64f86d 100755 --- a/APIJSONORM/src/main/java/apijson/Log.java +++ b/APIJSONORM/src/main/java/apijson/Log.java @@ -5,20 +5,49 @@ package apijson; +import java.text.SimpleDateFormat; + /**测试用Log * @modifier Lemon */ public class Log { public static boolean DEBUG = true; - + + //默认的时间格式 + public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS"); + + /** + * modify date format + * @param dateFormatString + */ + public static void setDateFormat(String dateFormatString) { + dateFormat = new SimpleDateFormat(dateFormatString); + } + + /** + * log info by level tag and msg + * @param TAG + * @param msg + * @param level + */ + public static void logInfo(String TAG, String msg, String level){ + if(level.equals("DEBUG") || level .equals("ERROR") ||level.equals("WARN")){ + System.err.println(dateFormat.format(System.currentTimeMillis()) + ": " + TAG + "." + level + ": " + msg); + } + else if(level.equals("VERBOSE") || level .equals("INFO") ){ + System.out.println(dateFormat.format(System.currentTimeMillis()) + ": " + TAG + "." + level + ": " + msg); + } + } + + /** * @param TAG * @param msg */ public static void d(String TAG, String msg) { if (DEBUG) { - System.err.println(TAG + ".DEBUG: " + msg); + logInfo(TAG,msg,"DEBUG"); } } @@ -28,7 +57,7 @@ public static void d(String TAG, String msg) { * @param msg debug messages */ public static void fd(String TAG, String msg) { - System.err.println(TAG + ".DEBUG: " + msg); + logInfo(TAG,msg,"DEBUG"); } /** @@ -47,7 +76,7 @@ public static void sl(String pre,char symbol ,String post) { */ public static void v(String TAG, String msg) { if (DEBUG) { - System.out.println(TAG + ".VERBOSE: " + msg); + logInfo(TAG,msg,"VERBOSE"); } } @@ -57,7 +86,7 @@ public static void v(String TAG, String msg) { */ public static void i(String TAG, String msg) { if (DEBUG) { - System.out.println(TAG + ".INFO: " + msg); + logInfo(TAG,msg,"INFO"); } } @@ -67,7 +96,7 @@ public static void i(String TAG, String msg) { */ public static void e(String TAG, String msg) { if (DEBUG) { - System.err.println(TAG + ".ERROR: " + msg); + logInfo(TAG,msg,"ERROR"); } } @@ -77,7 +106,7 @@ public static void e(String TAG, String msg) { */ public static void w(String TAG, String msg) { if (DEBUG) { - System.err.println(TAG + ".WARN: " + msg); + logInfo(TAG,msg,"WARN"); } }