在開發項目時候,需要解析從服務端獲取的數據,常常這些數據過大,導致eclipse上打印的log顯示不全,所以我寫了個方法分段顯示log,保證每段顯示的log長度在可顯示範圍內。
下面是實現方法:
/**
* 分段打印出較長log文本
* @param log 原log文本
* @param showCount 規定每段顯示的長度(最好不要超過eclipse限制長度)
*/
public static void showLogCompletion(String log,int showCount){
if(log.length() >showCount){
String show = log.substring(0, showCount);
// System.out.println(show);
Log.i("TAG", show+"");
if((log.length() - showCount)>showCount){//剩下的文本還是大於規定長度
String partLog = log.substring(showCount,log.length());
showLogCompletion(partLog, showCount);
}else{
String surplusLog = log.substring(showCount, log.length());
// System.out.println(surplusLog);
Log.i("TAG", surplusLog+"");
}
}else{
// System.out.println(log);
Log.i("TAG", log+"");
}
}