mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-04 07:40:42 +00:00
Bug 739415 - Add ability to log exceptions to robocop log file. r=jmaher
This commit is contained in:
parent
c103bf247f
commit
dcc4664d10
@ -41,6 +41,7 @@ package @ANDROID_PACKAGE_NAME@;
|
||||
|
||||
public interface Assert {
|
||||
void dumpLog(String message);
|
||||
void dumpLog(String message, Throwable t);
|
||||
void setLogFile(String filename);
|
||||
void setTestName(String testName);
|
||||
|
||||
|
@ -66,6 +66,11 @@ public class FennecMochitestAssert implements Assert {
|
||||
FennecNativeDriver.log(FennecNativeDriver.LogLevel.LOG_LEVEL_INFO, message);
|
||||
}
|
||||
|
||||
/** Write information to a logfile and logcat */
|
||||
public void dumpLog(String message, Throwable t) {
|
||||
FennecNativeDriver.log(FennecNativeDriver.LogLevel.LOG_LEVEL_INFO, message, t);
|
||||
}
|
||||
|
||||
/** Set the filename used for dumpLog. */
|
||||
public void setLogFile(String filename) {
|
||||
FennecNativeDriver.setLogFile(filename);
|
||||
|
@ -41,7 +41,6 @@ package @ANDROID_PACKAGE_NAME@;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
@ -49,6 +48,7 @@ import java.io.FileWriter;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -459,41 +459,48 @@ public class FennecNativeDriver implements Driver {
|
||||
}
|
||||
|
||||
public static void log(LogLevel level, String message) {
|
||||
log(level, message, null);
|
||||
}
|
||||
|
||||
public static void log(LogLevel level, Throwable t) {
|
||||
log(level, null, t);
|
||||
}
|
||||
|
||||
public static void log(LogLevel level, String message, Throwable t) {
|
||||
if (mLogFile == null) {
|
||||
assert(false);
|
||||
}
|
||||
|
||||
if (level.isEnabled(mLogLevel)) {
|
||||
File file = new File(mLogFile);
|
||||
BufferedWriter bw = null;
|
||||
|
||||
PrintWriter pw = null;
|
||||
try {
|
||||
bw = new BufferedWriter(new FileWriter(mLogFile, true));
|
||||
bw.write(message);
|
||||
bw.newLine();
|
||||
} catch(IOException e) {
|
||||
pw = new PrintWriter(new FileWriter(mLogFile, true));
|
||||
if (message != null) {
|
||||
pw.println(message);
|
||||
}
|
||||
if (t != null) {
|
||||
t.printStackTrace(pw);
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
Log.e("Robocop", "exception with file writer on: " + mLogFile);
|
||||
} finally {
|
||||
try {
|
||||
if (bw != null) {
|
||||
bw.flush();
|
||||
bw.close();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
pw.close();
|
||||
}
|
||||
// PrintWriter doesn't throw IOE but sets an error flag instead,
|
||||
// so check for that
|
||||
if (pw.checkError()) {
|
||||
Log.e("Robocop", "exception with file writer on: " + mLogFile);
|
||||
}
|
||||
}
|
||||
|
||||
if (level == LogLevel.LOG_LEVEL_INFO) {
|
||||
Log.i("Robocop", message);
|
||||
Log.i("Robocop", message, t);
|
||||
} else if (level == LogLevel.LOG_LEVEL_DEBUG) {
|
||||
Log.d("Robocop", message);
|
||||
Log.d("Robocop", message, t);
|
||||
} else if (level == LogLevel.LOG_LEVEL_WARN) {
|
||||
Log.w("Robocop", message);
|
||||
Log.w("Robocop", message, t);
|
||||
} else if (level == LogLevel.LOG_LEVEL_ERROR) {
|
||||
Log.e("Robocop", message);
|
||||
Log.e("Robocop", message, t);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -49,6 +49,11 @@ public class FennecTalosAssert implements Assert {
|
||||
FennecNativeDriver.log(FennecNativeDriver.LogLevel.LOG_LEVEL_INFO, message);
|
||||
}
|
||||
|
||||
/** Write information to a logfile and logcat */
|
||||
public void dumpLog(String message, Throwable t) {
|
||||
FennecNativeDriver.log(FennecNativeDriver.LogLevel.LOG_LEVEL_INFO, message, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the filename used for dumpLog.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user