зеркало из https://github.com/mozilla/pjs.git
bug 399341 - add crashreporter log file. r=bsmedberg
This commit is contained in:
Родитель
33d5ce6dc1
Коммит
12f59b82c0
|
@ -46,6 +46,8 @@
|
|||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
#include <time.h>
|
||||
|
||||
using std::string;
|
||||
using std::istream;
|
||||
|
@ -55,6 +57,7 @@ using std::ostringstream;
|
|||
using std::ostream;
|
||||
using std::ofstream;
|
||||
using std::vector;
|
||||
using std::auto_ptr;
|
||||
|
||||
namespace CrashReporter {
|
||||
|
||||
|
@ -63,8 +66,9 @@ string gSettingsPath;
|
|||
int gArgc;
|
||||
char** gArgv;
|
||||
|
||||
static string gDumpFile;
|
||||
static string gExtraFile;
|
||||
static auto_ptr<ofstream> gLogStream(NULL);
|
||||
static string gDumpFile;
|
||||
static string gExtraFile;
|
||||
|
||||
static string kExtraDataExtension = ".extra";
|
||||
|
||||
|
@ -199,6 +203,24 @@ bool WriteStringsToFile(const string& path,
|
|||
return success;
|
||||
}
|
||||
|
||||
void LogMessage(const std::string& message)
|
||||
{
|
||||
if (gLogStream.get()) {
|
||||
char date[64];
|
||||
time_t tm;
|
||||
time(&tm);
|
||||
if (strftime(date, sizeof(date) - 1, "%c", localtime(&tm)) == 0)
|
||||
date[0] = '\0';
|
||||
(*gLogStream) << "[" << date << "] " << message << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
static void OpenLogFile()
|
||||
{
|
||||
string logPath = gSettingsPath + UI_DIR_SEPARATOR + "submit.log";
|
||||
gLogStream.reset(UIOpenWrite(logPath.c_str(), true));
|
||||
}
|
||||
|
||||
static bool ReadConfig()
|
||||
{
|
||||
string iniPath;
|
||||
|
@ -433,6 +455,8 @@ int main(int argc, char** argv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
OpenLogFile();
|
||||
|
||||
if (!UIFileExists(gDumpFile)) {
|
||||
UIError(gStrings[ST_ERROR_DUMPFILEEXISTS]);
|
||||
return 0;
|
||||
|
|
|
@ -88,7 +88,7 @@ namespace CrashReporter {
|
|||
const std::string& header,
|
||||
StringTable& strings,
|
||||
bool escape);
|
||||
|
||||
void LogMessage(const std::string& message);
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
|
@ -118,7 +118,7 @@ bool UIFileExists(const std::string& path);
|
|||
bool UIMoveFile(const std::string& oldfile, const std::string& newfile);
|
||||
bool UIDeleteFile(const std::string& oldfile);
|
||||
std::ifstream* UIOpenRead(const std::string& filename);
|
||||
std::ofstream* UIOpenWrite(const std::string& filename);
|
||||
std::ofstream* UIOpenWrite(const std::string& filename, bool append=false);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning( pop )
|
||||
|
|
|
@ -149,6 +149,14 @@ static gboolean SendReportIdle(gpointer userData)
|
|||
"upload_file_minidump",
|
||||
"", "",
|
||||
&response);
|
||||
if (success) {
|
||||
LogMessage("Crash report submitted successfully");
|
||||
}
|
||||
else {
|
||||
//XXX: HTTPUpload::SendRequest eats the curl error code, filed
|
||||
// http://code.google.com/p/google-breakpad/issues/detail?id=221
|
||||
LogMessage("Crash report submission failed");
|
||||
}
|
||||
SendCompleted(success, response);
|
||||
|
||||
if (!success) {
|
||||
|
@ -534,7 +542,9 @@ std::ifstream* UIOpenRead(const string& filename)
|
|||
return new std::ifstream(filename.c_str(), std::ios::in);
|
||||
}
|
||||
|
||||
std::ofstream* UIOpenWrite(const string& filename)
|
||||
std::ofstream* UIOpenWrite(const string& filename, bool append) // append=false
|
||||
{
|
||||
return new std::ofstream(filename.c_str(), std::ios::out);
|
||||
return new std::ofstream(filename.c_str(),
|
||||
append ? std::ios::out | std::ios::app
|
||||
: std::ios::out);
|
||||
}
|
||||
|
|
|
@ -43,9 +43,11 @@
|
|||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <sstream>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::ostringstream;
|
||||
|
||||
using namespace CrashReporter;
|
||||
|
||||
|
@ -379,8 +381,17 @@ static bool RestartApplication()
|
|||
if (!data || !response || [response statusCode] != 200) {
|
||||
success = false;
|
||||
reply = "";
|
||||
|
||||
// if data is nil, we probably logged an error in uploadThread
|
||||
if (data != nil && response != nil) {
|
||||
ostringstream message;
|
||||
message << "Crash report submission failed: server returned status "
|
||||
<< [response statusCode];
|
||||
LogMessage(message.str());
|
||||
}
|
||||
} else {
|
||||
success = true;
|
||||
LogMessage("Crash report submitted successfully");
|
||||
|
||||
NSString* encodingName = [response textEncodingName];
|
||||
NSStringEncoding encoding;
|
||||
|
@ -408,8 +419,12 @@ static bool RestartApplication()
|
|||
NSAutoreleasePool* autoreleasepool = [[NSAutoreleasePool alloc] init];
|
||||
NSError* error = nil;
|
||||
NSData* data = [post send: &error];
|
||||
if (error)
|
||||
if (error) {
|
||||
data = nil;
|
||||
NSString* errorDesc = [error localizedDescription];
|
||||
string message = [errorDesc UTF8String];
|
||||
LogMessage("Crash report submission failed: " + message);
|
||||
}
|
||||
|
||||
[self performSelectorOnMainThread: @selector(uploadComplete:)
|
||||
withObject: data
|
||||
|
@ -542,7 +557,9 @@ std::ifstream* UIOpenRead(const string& filename)
|
|||
return new std::ifstream(filename.c_str(), std::ios::in);
|
||||
}
|
||||
|
||||
std::ofstream* UIOpenWrite(const string& filename)
|
||||
std::ofstream* UIOpenWrite(const string& filename, bool append) // append=false
|
||||
{
|
||||
return new std::ofstream(filename.c_str(), std::ios::out);
|
||||
return new std::ofstream(filename.c_str(),
|
||||
append ? std::ios::out | std::ios::app
|
||||
: std::ios::out);
|
||||
}
|
||||
|
|
|
@ -225,6 +225,38 @@ static void SetStringKey(const wchar_t* key,
|
|||
}
|
||||
}
|
||||
|
||||
static string FormatLastError()
|
||||
{
|
||||
DWORD err = GetLastError();
|
||||
LPWSTR s;
|
||||
string message = "Crash report submision failed: ";
|
||||
// odds are it's a WinInet error
|
||||
HANDLE hInetModule = GetModuleHandle(L"WinInet.dll");
|
||||
if(FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_FROM_HMODULE,
|
||||
hInetModule,
|
||||
err,
|
||||
0,
|
||||
(LPWSTR)&s,
|
||||
0,
|
||||
NULL) != 0) {
|
||||
message += WideToUTF8(s, NULL);
|
||||
LocalFree(s);
|
||||
// strip off any trailing newlines
|
||||
string::size_type n = message.find_last_not_of("\r\n");
|
||||
if (n < message.size() - 1) {
|
||||
message.erase(n+1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
char buf[64];
|
||||
sprintf(buf, "Unknown error, error code: 0x%08x", err);
|
||||
message += buf;
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
// Gets the position of a window relative to another window's client area
|
||||
static void GetRelativeRect(HWND hwnd, HWND hwndParent, RECT* r)
|
||||
{
|
||||
|
@ -292,6 +324,7 @@ static DWORD WINAPI SendThreadProc(LPVOID param)
|
|||
|
||||
if (td->sendURL.empty()) {
|
||||
finishedOk = false;
|
||||
LogMessage("No server URL, not sending report");
|
||||
} else {
|
||||
google_breakpad::CrashReportSender sender(L"");
|
||||
finishedOk = (sender.SendCrashReport(td->sendURL,
|
||||
|
@ -299,6 +332,15 @@ static DWORD WINAPI SendThreadProc(LPVOID param)
|
|||
td->dumpFile,
|
||||
&td->serverResponse)
|
||||
== google_breakpad::RESULT_SUCCEEDED);
|
||||
if (finishedOk) {
|
||||
LogMessage("Crash report submitted successfully");
|
||||
}
|
||||
else {
|
||||
// get an error string and print it to the log
|
||||
//XXX: would be nice to get the HTTP status code here, filed:
|
||||
// http://code.google.com/p/google-breakpad/issues/detail?id=220
|
||||
LogMessage(FormatLastError());
|
||||
}
|
||||
}
|
||||
|
||||
PostMessage(td->hDlg, WM_UPLOADCOMPLETE, finishedOk ? 1 : 0, 0);
|
||||
|
@ -839,7 +881,7 @@ ifstream* UIOpenRead(const string& filename)
|
|||
return file;
|
||||
}
|
||||
|
||||
ofstream* UIOpenWrite(const string& filename)
|
||||
ofstream* UIOpenWrite(const string& filename, bool append) // append=false
|
||||
{
|
||||
// adapted from breakpad's src/common/windows/http_upload.cc
|
||||
|
||||
|
@ -849,9 +891,11 @@ ofstream* UIOpenWrite(const string& filename)
|
|||
// not exist in earlier versions, so let the ifstream open the file itself.
|
||||
#if _MSC_VER >= 1400 // MSVC 2005/8
|
||||
ofstream* file = new ofstream();
|
||||
file->open(UTF8ToWide(filename).c_str(), ios::out);
|
||||
file->open(UTF8ToWide(filename).c_str(), append ? ios::out | ios::app
|
||||
: ios::out);
|
||||
#else // _MSC_VER >= 1400
|
||||
ofstream* file = new ofstream(_wfopen(UTF8ToWide(filename).c_str(), L"w"));
|
||||
ofstream* file = new ofstream(_wfopen(UTF8ToWide(filename).c_str(),
|
||||
append ? L"a" : L"w"));
|
||||
#endif // _MSC_VER >= 1400
|
||||
|
||||
return file;
|
||||
|
|
Загрузка…
Ссылка в новой задаче