常用的Log日誌列印與輸出

2021-09-30 11:29:06 字數 2925 閱讀 3179

/**

* log日誌

* * @author jenly

* @date 2014-6-20

*/public class logutils

public static boolean isshowlog()

public static int getpriority()

public static void setpriority(int priority)

/*** 根據堆疊生成tag

* @return tag|classname.methodname(l:linenumber)

*/private static string generatetag(stacktraceelement caller) );

} /**

* 獲取堆疊

* @param n

* n=0 vmstack

* n=1 thread

* n=3 currentstack

* n=4 callerstack

* ...

* @return

*/public static stacktraceelement getstacktraceelement(int n)

/*** 獲取呼叫方的堆疊tag

* @return

*/private static string getcallerstacklogtag()

/***

* @param t

* @return

*/private static string getstacktracestring(throwable t)

// -----------------------------------log.v

/*** log.v

* @param msg

*/public static void v(string msg)

public static void v(throwable t)

public static void v(string msg,throwable t)

// -----------------------------------log.d

/*** log.d

* @param msg

*/public static void d(string msg)

public static void d(throwable t)

public static void d(string msg,throwable t)

// -----------------------------------log.i

/*** log.i

* @param msg

*/public static void i(string msg)

public static void i(throwable t)

public static void i(string msg,throwable t)

// -----------------------------------log.w

/*** log.w

* @param msg

*/public static void w(string msg)

public static void w(throwable t)

public static void w(string msg,throwable t)

// -----------------------------------log.e

/*** log.e

* @param msg

*/public static void e(string msg)

public static void e(throwable t)

public static void e(string msg,throwable t)

// -----------------------------------log.wtf

/*** log.wtf

* @param msg

*/public static void wtf(string msg)

public static void wtf(throwable t)

public static void wtf(string msg,throwable t)

// -----------------------------------system.out.print

/*** system.out.print

* * @param msg

*/public static void print(string msg)

public static void print(object obj)

// -----------------------------------system.out.printf

/*** system.out.printf

* * @param msg

*/public static void printf(string msg)

// -----------------------------------system.out.println

/*** system.out.println

* * @param msg

*/public static void println(string msg)

public static void println(object obj)

}

只是進行了乙個簡單的封裝,方便記錄與管理。

所有最新原始碼已總結上傳至

github

歡迎star或fork。

Android輸出日誌Log類

android.util.log常用的方法有以下5個 log.v log.d log.i log.w 以及 log.e 根據首字母分別對應verbose,debug,info,warn,error。1 log.v 的除錯顏色為黑色的,任何訊息都會輸出,這裡的v代表verbose囉嗦的意思,平時使用就...

Qt列印Log日誌到檔案

寫軟體時有時候需要記錄日誌到檔案,方便檢視軟體執行資訊和排查問題,qt有自己的日誌列印功能,實現qt日誌功能需要用到下面的函式,其中qt4和qt5的函式有區別 上面的函式是用來列印除錯資訊,警報資訊,危險資訊和致命資訊的。當qt有內部錯誤產生時,qt除錯庫會列印幾百種警報資訊 通常是異常的函式引數 ...

Log4j日誌輸出

配置檔案示例 參考 link.log4j 的日誌輸出控制檔案,主要由三個部分構成 是專門用於控制日誌輸出的。其主要進行三方面控制 日誌屬性檔案由日誌附加器與根日誌組成 log4j 採用類似 c 語言中的 printf 函式的列印格式格式化日誌資訊 定義日誌輸出級別info和輸出位置控制台,檔案 lo...