DateUtil.java : Java 常用工具类(4) : 时间处理_Lxinccode的博客-CSDN博客
/**
* @Author: liyue
* @Date: 2021/12/27/14:37
* @Description:
*/
public class PrintUtil {
// 黑色
public static void info(String str, Object... param) {
println(DateUtil.getNowhm() + "|INFO|" + join(str, param));
}
// 红色
public static void error(String str, Object... param) {
println("\033[31m" + DateUtil.getNowhm() + "|ERROR|" + join(str, param) + " \033[0m");
}
// 黄色
public static void warning(String str, Object... param) {
println("\033[33m" + DateUtil.getNowhm() + "|WARNING|" + join(str, param) + " \033[0m");
}
// 绿色
public static void success(String str, Object... param) {
println("\033[32m" + DateUtil.getNowhm() + "|SUCCESS|" + join(str, param) + " \033[0m");
}
private static void println(String str) {
System.out.println(str);
}
/**
* 依次替换{}
* 例 : join("a={},b={}",1,2) => a=1,b=2
*
* @param str
* @param param
* @return
*/
public static String join(String str, Object... param) {
try {
for (Object p : param) {
str = str.replaceFirst("\\{\\}", p.toString());
}
} catch (Exception e) {
for (Object p : param) {
str = str + p;
}
}
return str;
}
}