Skip to content

Commit

Permalink
Merge pull request #2337 from wordpress-mobile/issue/2336-logentry-to…
Browse files Browse the repository at this point in the history
…html-npe

fix #2336 NPE in LogEntry
  • Loading branch information
nbradbury committed Feb 17, 2015
2 parents 4e0b3cf + 72a7a51 commit 3aad2fd
Showing 1 changed file with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,31 @@ private String toHtmlColor() {
}

private static class LogEntry {
LogLevel logLevel;
String logText;
T logTag;
LogLevel mLogLevel;
String mLogText;
T mLogTag;

public LogEntry(LogLevel logLevel, String logText, T logTag) {
mLogLevel = logLevel;
mLogText = logText;
if (mLogText == null) {
mLogText = "null";
}
mLogTag = logTag;
}

private String toHtml() {
StringBuilder sb = new StringBuilder()
.append("<font color=\"")
.append(logLevel.toHtmlColor())
.append("\">")
.append("[")
.append(logTag.name())
.append("] ")
.append(logLevel.name())
.append(": ")
.append(TextUtils.htmlEncode(logText).replace("\n", "<br />"))
.append("</font>");
StringBuilder sb = new StringBuilder();
sb.append("<font color=\"");
sb.append(mLogLevel.toHtmlColor());
sb.append("\">");
sb.append("[");
sb.append(mLogTag.name());
sb.append("] ");
sb.append(mLogLevel.name());
sb.append(": ");
sb.append(TextUtils.htmlEncode(mLogText).replace("\n", "<br />"));
sb.append("</font>");
return sb.toString();
}
}
Expand All @@ -155,12 +164,10 @@ private void removeFirstEntry() {

private static void addEntry(T tag, LogLevel level, String text) {
// skip if recording is disabled (default)
if (!mEnableRecording)
if (!mEnableRecording) {
return;
LogEntry entry = new LogEntry();
entry.logLevel = level;
entry.logText = text;
entry.logTag = tag;
}
LogEntry entry = new LogEntry(level, text, tag);
mLogEntries.addEntry(entry);
}

Expand All @@ -170,7 +177,6 @@ private static String getStringStackTrace(Throwable throwable) {
return errors.toString();
}


/*
* returns entire log as html for display (see AppLogViewerActivity)
*/
Expand All @@ -188,7 +194,6 @@ public static ArrayList<String> toHtmlList(Context context) {
return items;
}


/*
* returns entire log as plain text
*/
Expand All @@ -203,7 +208,7 @@ public static String toPlainText(Context context) {
int lineNum = 1;
while (it.hasNext()) {
sb.append(String.format("%02d - ", lineNum))
.append(it.next().logText)
.append(it.next().mLogText)
.append("\n");
lineNum++;
}
Expand Down

0 comments on commit 3aad2fd

Please sign in to comment.