Skip to content

Commit

Permalink
Merge pull request #250 from jun0315/master
Browse files Browse the repository at this point in the history
feat:log print current time
  • Loading branch information
TommyLemon authored Jun 11, 2021
2 parents 7e6097a + 81da25d commit a6a4129
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions APIJSONORM/src/main/java/apijson/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand All @@ -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");
}

/**
Expand All @@ -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");
}
}

Expand All @@ -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");
}
}

Expand All @@ -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");
}
}

Expand All @@ -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");
}
}

Expand Down

0 comments on commit a6a4129

Please sign in to comment.