是否可以在sqlite数据库中保存logcat条目? 如果用户收到错误,我想在不将手机连接到adb的情况下阅读日志。
这是我写日志的方式:Log.d(TAG, "An error occured", e)
由于
答案 0 :(得分:0)
创建日志文件是读错误的更好选择
public void mlogFile(String pActivityName, String pOperation, String pData) {
File lLogFilePath, lLogFile;
Date lDate;
CharSequence lCurrfolder;
FileWriter lFileWriter;
BufferedWriter lBuffWriter;
String lActivity, lOperation;
try {
lDate = new Date();
lCurrfolder = DateFormat.format("yyyyMMdd", lDate.getTime());
lLogFilePath = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "CSPDCLData/" + lCurrfolder + "/");
if (!lLogFilePath.exists()) {
lLogFilePath.mkdirs();
}
lLogFile = new File(lLogFilePath, "ADDLogfile.txt");
lFileWriter = new FileWriter(lLogFile, true);
lBuffWriter = new BufferedWriter(lFileWriter);
lActivity = pActivityName.length() != 0 ? ADDPadding(pActivityName, 25, ' ', 'L') + "~ " : "";
lOperation = pOperation.length() != 0 ? " : " + pData : "";
lBuffWriter.append(DateFormat.format("kk:mm:ss", lDate.getTime()) + " " + lActivity + pOperation + lOperation + "\n");
lBuffWriter.flush();
lBuffWriter.close();
lFileWriter.close();
} catch (IOException ex) {
Toast.makeText(this, "ERROR: " + ex.getMessage(), Toast.LENGTH_SHORT).show();
}
}
在发生错误时添加此行
logFile(getClass().getSimpleName(),"methodName()", "An error occured"+ e.getMessage());