Skip to content

Commit

Permalink
💡 添加源码注释
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyd-c committed Aug 2, 2019
1 parent 267b74b commit d9967b2
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/main/java/me/zhyd/oauth/log/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @date 2019/8/1 17:14
* @see Log#debug(String)
* @see Log#debug(String, Throwable)
* @see Log#warn(String)
* @see Log#warn(String, Throwable)
* @see Log#error(String)
* @see Log#error(String, Throwable)
* @since 1.8
*/
public class Log {
Expand Down Expand Up @@ -41,6 +47,14 @@ public static void error(String msg, Throwable t) {
print(Level.ERROR, msg, t, System.err);
}

/**
* 打印日志内容,格式:2019-08-02 20:44:07 main me.zhyd.oauth.log.Log(debug:39) [DEBUG] - xxxx
*
* @param level 日志级别
* @param msg 日志内容
* @param t 异常信息
* @param ps 实际执行打印的PrintStream
*/
private static void print(Level level, String msg, Throwable t, PrintStream ps) {
if (Config.enable) {
if (level.getLevelNum() >= Config.level.getLevelNum()) {
Expand All @@ -51,6 +65,11 @@ private static void print(Level level, String msg, Throwable t, PrintStream ps)
}
}

/**
* 获取调用方的信息
*
* @return 返回调用方的信息,格式:class(method:lineNumber)
*/
private static String getCaller() {
int offset = 2;
StackTraceElement[] stackTraceArr = (new Throwable()).getStackTrace();
Expand All @@ -67,10 +86,21 @@ private static String getCaller() {
")";
}

/**
* 获取格式化后的日期
*
* @return string
*/
private static String getDate() {
return LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
}

/**
* 打印异常信息
*
* @param t 异常
* @param targetStream 实际执行打印的PrintStream
*/
private static void writeThrowable(Throwable t, PrintStream targetStream) {
if (t != null) {
t.printStackTrace(targetStream);
Expand Down

0 comments on commit d9967b2

Please sign in to comment.