mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-07 10:30:14 -05:00
supports sub logs in log export
This commit is contained in:
parent
95e9e2ac30
commit
e69ee812d2
@ -121,20 +121,13 @@ public class LogDisplayFragment extends ListFragment implements OnItemClickListe
|
|||||||
boolean error = false;
|
boolean error = false;
|
||||||
|
|
||||||
PrintWriter pw = null;
|
PrintWriter pw = null;
|
||||||
|
|
||||||
Iterator<LogEntryParcel> logIterator = operationLog.iterator();
|
|
||||||
try {
|
try {
|
||||||
pw = new PrintWriter(f);
|
pw = new PrintWriter(f);
|
||||||
|
pw.print(getPrintableOperationLog(operationLog,""));
|
||||||
while(logIterator.hasNext()) {
|
|
||||||
|
|
||||||
pw.println(getPrintableLogEntry(logIterator.next()));
|
|
||||||
if(pw.checkError()) {//IOException
|
if(pw.checkError()) {//IOException
|
||||||
Log.e(Constants.TAG, "Log Export I/O Exception "+f.getAbsolutePath());
|
Log.e(Constants.TAG, "Log Export I/O Exception "+f.getAbsolutePath());
|
||||||
currLog.add(OperationResult.LogType.MSG_EXPORT_LOG_EXPORT_ERROR_WRITING,1);
|
currLog.add(OperationResult.LogType.MSG_EXPORT_LOG_EXPORT_ERROR_WRITING,1);
|
||||||
error = true;
|
error = true;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch(FileNotFoundException e) {
|
} catch(FileNotFoundException e) {
|
||||||
Log.e(Constants.TAG, "File not found for exporting log "+f.getAbsolutePath());
|
Log.e(Constants.TAG, "File not found for exporting log "+f.getAbsolutePath());
|
||||||
@ -143,7 +136,10 @@ public class LogDisplayFragment extends ListFragment implements OnItemClickListe
|
|||||||
}
|
}
|
||||||
if(pw!=null) {
|
if(pw!=null) {
|
||||||
pw.close();
|
pw.close();
|
||||||
error = error && pw.checkError();//check for errors on closing PrintWriter object too
|
if(!error && pw.checkError()) {//check if it is only pw.close() which generated error
|
||||||
|
currLog.add(OperationResult.LogType.MSG_EXPORT_LOG_EXPORT_ERROR_WRITING,1);
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!error) currLog.add(OperationResult.LogType.MSG_EXPORT_LOG_EXPORT_SUCCESS,1);
|
if(!error) currLog.add(OperationResult.LogType.MSG_EXPORT_LOG_EXPORT_SUCCESS,1);
|
||||||
@ -173,78 +169,69 @@ public class LogDisplayFragment extends ListFragment implements OnItemClickListe
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns an indented String of a LogEntryParcel
|
* returns an indented String of an entire OperationLog
|
||||||
* @param entry log entry whose String representation is to be obtained
|
* @param operationLog log to be converted to indented, printable format
|
||||||
* @return the passed log entry in a readable format
|
* @param basePadding padding to add at the start of all log entries, made for use with SubLogs
|
||||||
|
* @return printable, indented version of passed operationLog
|
||||||
*/
|
*/
|
||||||
private String getPrintableLogEntry(OperationResult.LogEntryParcel entry) {
|
private String getPrintableOperationLog(OperationResult.OperationLog operationLog, String basePadding) {
|
||||||
String subLogText=null;
|
String log = "";
|
||||||
if (entry instanceof SubLogEntryParcel) {
|
Iterator<LogEntryParcel> logIterator = operationLog.iterator();
|
||||||
|
while(logIterator.hasNext()) {
|
||||||
OperationResult result = ((SubLogEntryParcel) entry).getSubResult();
|
log += getPrintableLogEntry(logIterator.next(), basePadding)+"\n";
|
||||||
LogEntryParcel subEntry = result.getLog().getLast();
|
|
||||||
if (subEntry != null) {
|
|
||||||
String subPadding="";
|
|
||||||
for(int i=0;i<entry.mIndent;i++) subPadding+=" ";//2 spaces = 1 Indent
|
|
||||||
|
|
||||||
subLogText=subPadding+"[SUB]";
|
|
||||||
|
|
||||||
switch (subEntry.mType.mLevel) {
|
|
||||||
case DEBUG: subLogText+="[DEBUG]"; break;
|
|
||||||
case INFO: subLogText+="[INFO]"; break;
|
|
||||||
case WARN: subLogText+="[WARN]"; break;
|
|
||||||
case ERROR: subLogText+="[ERROR]"; break;
|
|
||||||
case START: subLogText+="[START]"; break;
|
|
||||||
case OK: subLogText+="[OK]"; break;
|
|
||||||
case CANCELLED: subLogText+="[CANCELLED]"; break;
|
|
||||||
}
|
}
|
||||||
// special case: first parameter may be a quantity
|
log = log.substring(0,log.length()-1);//gets rid of extra new line
|
||||||
if (subEntry.mParameters != null && subEntry.mParameters.length > 0
|
return log;
|
||||||
&& subEntry.mParameters[0] instanceof Integer) {
|
|
||||||
subLogText+=getResources().getQuantityString(subEntry.mType.getMsgId(),
|
|
||||||
(Integer) subEntry.mParameters[0],
|
|
||||||
subEntry.mParameters);
|
|
||||||
} else {
|
|
||||||
subLogText+=getResources().getString(subEntry.mType.getMsgId(),
|
|
||||||
subEntry.mParameters);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* returns an indented String of a LogEntryParcel including any sub-logs it may contain
|
||||||
|
* @param entryParcel log entryParcel whose String representation is to be obtained
|
||||||
|
* @return indented version of passed log entryParcel in a readable format
|
||||||
|
*/
|
||||||
|
private String getPrintableLogEntry(OperationResult.LogEntryParcel entryParcel,
|
||||||
|
String basePadding) {
|
||||||
|
|
||||||
String logText = "";
|
String logText = "";
|
||||||
|
final String indent = " ";//4 spaces = 1 Indent level
|
||||||
|
|
||||||
String padding = "";
|
String padding = basePadding;
|
||||||
for(int i =0;i<entry.mIndent;i++) {
|
for(int i =0;i<entryParcel.mIndent;i++) {
|
||||||
padding +=" "; //4 spaces = 1 Indent level
|
padding +=indent;
|
||||||
}
|
}
|
||||||
|
logText = padding;
|
||||||
|
|
||||||
switch (entry.mType.mLevel) {
|
switch (entryParcel.mType.mLevel) {
|
||||||
case DEBUG: logText="[DEBUG]"; break;
|
case DEBUG: logText+="[DEBUG]"; break;
|
||||||
case INFO: logText="[INFO]"; break;
|
case INFO: logText+="[INFO]"; break;
|
||||||
case WARN: logText="[WARN]"; break;
|
case WARN: logText+="[WARN]"; break;
|
||||||
case ERROR: logText="[ERROR]"; break;
|
case ERROR: logText+="[ERROR]"; break;
|
||||||
case START: logText="[START]"; break;
|
case START: logText+="[START]"; break;
|
||||||
case OK: logText="[OK]"; break;
|
case OK: logText+="[OK]"; break;
|
||||||
case CANCELLED: logText="[CANCELLED]"; break;
|
case CANCELLED: logText+="[CANCELLED]"; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// special case: first parameter may be a quantity
|
// special case: first parameter may be a quantity
|
||||||
if (entry.mParameters != null && entry.mParameters.length > 0
|
if (entryParcel.mParameters != null && entryParcel.mParameters.length > 0
|
||||||
&& entry.mParameters[0] instanceof Integer) {
|
&& entryParcel.mParameters[0] instanceof Integer) {
|
||||||
logText += getResources().getQuantityString(entry.mType.getMsgId(),
|
logText += getResources().getQuantityString(entryParcel.mType.getMsgId(),
|
||||||
(Integer) entry.mParameters[0],
|
(Integer) entryParcel.mParameters[0],
|
||||||
entry.mParameters);
|
entryParcel.mParameters);
|
||||||
} else {
|
} else {
|
||||||
logText += getResources().getString(entry.mType.getMsgId(),
|
logText += getResources().getString(entryParcel.mType.getMsgId(),
|
||||||
entry.mParameters);
|
entryParcel.mParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
logText = padding + logText;
|
if (entryParcel instanceof SubLogEntryParcel) {
|
||||||
|
|
||||||
if(subLogText!=null) //subLog exists
|
OperationResult subResult = ((SubLogEntryParcel) entryParcel).getSubResult();
|
||||||
logText = logText+"\n"+padding+subLogText;
|
LogEntryParcel subEntry = subResult.getLog().getLast();
|
||||||
|
if (subEntry != null) {
|
||||||
|
//the first line of log of subResult is same as entryParcel, so replace logText
|
||||||
|
logText = getPrintableOperationLog(subResult.getLog(),padding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return logText;
|
return logText;
|
||||||
}
|
}
|
||||||
@ -300,7 +287,7 @@ public class LogDisplayFragment extends ListFragment implements OnItemClickListe
|
|||||||
mSecondImg = secondImg;
|
mSecondImg = secondImg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//adithyaphilip: Check if convertView.setPadding is redundant
|
// Check if convertView.setPadding is redundant
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
LogEntryParcel entry = getItem(position);
|
LogEntryParcel entry = getItem(position);
|
||||||
|
Loading…
Reference in New Issue
Block a user