Skip to content

Commit

Permalink
#983 using stringbuilder instead of string.format to improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
kfchu committed Sep 25, 2018
1 parent 94da4c8 commit a6a6ee7
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions saturn-core/src/main/java/com/vip/saturn/job/utils/LogUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
public class LogUtils {

private static final String FORMAT_FOR_LOG = "[{}] msg={}";
private static final String FORMAT_FOR_STRING = "[%s] msg=%s";

private static String constructFormatOrMsg(String eventName, String formatOrMsg) {
return String.format(FORMAT_FOR_STRING, eventName, formatOrMsg);
}

// debug begin

/**
* @param logger slf4j logger
Expand Down Expand Up @@ -75,8 +68,6 @@ public static void debug(Logger logger, String eventName, String msg, Throwable
}
}

// info begin

/**
* @param logger slf4j logger
* @param eventName 事件名
Expand Down Expand Up @@ -127,8 +118,6 @@ public static void info(Logger logger, String eventName, String msg, Throwable t
logger.info(constructFormatOrMsg(eventName, msg), t);
}

// warn begin

/**
* @param logger slf4j logger
* @param eventName 事件名
Expand Down Expand Up @@ -179,8 +168,6 @@ public static void warn(Logger logger, String eventName, String msg, Throwable t
logger.warn(constructFormatOrMsg(eventName, msg), t);
}

// error begin

/**
* @param logger slf4j logger
* @param eventName 事件名
Expand Down Expand Up @@ -231,4 +218,7 @@ public static void error(Logger logger, String eventName, String msg, Throwable
logger.error(constructFormatOrMsg(eventName, msg), t);
}

private static String constructFormatOrMsg(String eventName, String formatOrMsg) {
return new StringBuilder("[").append(eventName).append("] msg=").append(formatOrMsg).toString();
}
}

0 comments on commit a6a6ee7

Please sign in to comment.