Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:log print current time #250

Merged
merged 1 commit into from
Jun 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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