工具封裝,是一個能快速對業務需求做出響應的沉澱,亦是個人能力的提升過程。
以下ALog
工具僅提供對android.util.Log
的重新封裝
依賴方式
Gradle
引用方式
- 必要時可在
Project
的build.gradle
增加工具庫的目標地址
buildscript {
repositories {
jcenter()
maven {
url 'https://bintray.com/itsdf07/maven/'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
......
- 在需要使用該工具庫的Module中的
build.gradle
中添加依賴
compile 'com.itsdf07:lib-alog:2.0.2'
使用方式
初始化過程
ALog.init()
.setLogLevel(ALogLevel.FULL) //是否打印log,默認開啓
.setTag("自定義Tag") //自定義tag,默認TAG = "itsdf07"
.setDefineALogFilePath("xxx/xxx/xxx.log") //自定義log存儲路徑,默認SDCard根目錄下的ALOG文件夾
.setLog2Local(true) //設置是否本地存儲log記錄,默認關閉
.setShowThreadInfo(true)//是否顯示線程信息,默認不顯示
.setMethodCount(2); //顯示函數棧中的方法數,默認顯示2個
使用方式
ALog.d("這是第 %s 次 Log 輸出", 6);
ALog.dTag("aso", "這是第 %s 次 Log 輸出", 7);
關閉顯示線程信息Log輸出如下
03-25 10:51:15.327 18073-18073/com.itsdf07.app.alog D/itsdf07: ╔════════════════════════════════════════════════════════════════════════════════════════
03-25 10:51:15.331 18073-18073/com.itsdf07.app.alog D/itsdf07: ║ onCreate (MainActivity.java:22) [ALog-Content] 這是第 6 次 Log 輸出
03-25 10:51:15.331 18073-18073/com.itsdf07.app.alog D/itsdf07: ╚════════════════════════════════════════════════════════════════════════════════════════
03-25 10:51:15.331 18073-18073/com.itsdf07.app.alog D/aso: ╔════════════════════════════════════════════════════════════════════════════════════════
03-25 10:51:15.332 18073-18073/com.itsdf07.app.alog D/aso: ║ onCreate (MainActivity.java:23) [ALog-Content] 這是第 7 次 Log 輸出
03-25 10:51:15.332 18073-18073/com.itsdf07.app.alog D/aso: ╚════════════════════════════════════════════════════════════════════════════════════════
開啓顯示線程信息Log輸出如下
03-25 10:50:08.064 17002-17002/com.itsdf07.app.alog D/itsdf07: ╔════════════════════════════════════════════════════════════════════════════════════════
03-25 10:50:08.065 17002-17002/com.itsdf07.app.alog D/itsdf07: ║Thread:main
03-25 10:50:08.065 17002-17002/com.itsdf07.app.alog D/itsdf07: ╟────────────────────────────────────────────────────────────────────────────────────────
03-25 10:50:08.065 17002-17002/com.itsdf07.app.alog D/itsdf07: ║ Activity.performCreate (Activity.java:7372)
03-25 10:50:08.065 17002-17002/com.itsdf07.app.alog D/itsdf07: ║ MainActivity.onCreate (MainActivity.java:22)
03-25 10:50:08.065 17002-17002/com.itsdf07.app.alog D/itsdf07: ╟────────────────────────────────────────────────────────────────────────────────────────
03-25 10:50:08.069 17002-17002/com.itsdf07.app.alog D/itsdf07: ║ [ALog-Content] 這是第 6 次 Log 輸出
03-25 10:50:08.069 17002-17002/com.itsdf07.app.alog D/itsdf07: ╚════════════════════════════════════════════════════════════════════════════════════════
03-25 10:50:08.070 17002-17002/com.itsdf07.app.alog D/aso: ╔════════════════════════════════════════════════════════════════════════════════════════
03-25 10:50:08.070 17002-17002/com.itsdf07.app.alog D/aso: ║Thread:main
03-25 10:50:08.070 17002-17002/com.itsdf07.app.alog D/aso: ╟────────────────────────────────────────────────────────────────────────────────────────
03-25 10:50:08.071 17002-17002/com.itsdf07.app.alog D/aso: ║ Activity.performCreate (Activity.java:7372)
03-25 10:50:08.071 17002-17002/com.itsdf07.app.alog D/aso: ║ MainActivity.onCreate (MainActivity.java:23)
03-25 10:50:08.071 17002-17002/com.itsdf07.app.alog D/aso: ╟────────────────────────────────────────────────────────────────────────────────────────
03-25 10:50:08.071 17002-17002/com.itsdf07.app.alog D/aso: ║ [ALog-Content] 這是第 7 次 Log 輸出
03-25 10:50:08.071 17002-17002/com.itsdf07.app.alog D/aso: ╚════════════════════════════════════════════════════════════════════════════════════════
開放功能如下
/**
* 當前是否打印Log
*
* @return
*/
isLog();
/**
* ALog.v("isFIleExist = %s, innerBasePath = %s", isFileExist, innerBasePath);
*
* @param message 要打印的內容
* @param args 打印信息中的動態數據
*/
v(String message, Object... args);
/**
* ALog.v("itsdf07", "isFIleExist = %s, innerBasePath = %s", isFileExist, innerBasePath);
*
* @param tag tag
* @param message 要打印的內容
* @param args 打印信息中的動態數據
*/
vTag(String tag, String message, Object... args);
d(String message, Object... args);
dTag(String tag, String message, Object... args);
i(String message, Object... args);
iTag(String tag, String message, Object... args);
w(String message, Object... args);
wTag(String tag, String message, Object... args);
e(String message, Object... args);
eTag(String tag, String message, Object... args);
eTag(String tag, Throwable throwable, String message, Object... args);
wtf(String message, Object... args);
wtfTag(String tag, String message, Object... args);
wtfTag(String tag, Throwable throwable, String message, Object... args);
/**
* JSON格式數據打印
*
* @param json
*/
json(String json);
/**
* XML格式數據打印
*
* @param xml the xml content
*/
xml(String xml);