Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: src/plugin/PluginDebug.cpp

Issue 5747779603267584: Issue #1234 - Rework strings in debug facility (Closed)
Left Patch Set: Fixed spaces Created Feb. 25, 2015, 3:24 p.m.
Right Patch Set: typo fix Created March 5, 2015, 12:43 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/plugin/PluginDebug.h ('k') | src/plugin/PluginDebugMacros.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 CComAutoCriticalSection CPluginDebugLock::s_criticalSectionDebugLock; 44 CComAutoCriticalSection CPluginDebugLock::s_criticalSectionDebugLock;
45 45
46 void CPluginDebug::DebugSystemException(const std::system_error& ex, int errorId , int errorSubid, const std::string& description) 46 void CPluginDebug::DebugSystemException(const std::system_error& ex, int errorId , int errorSubid, const std::string& description)
47 { 47 {
48 std::string message = description + ", " + ex.code().message() + ", " + ex.wha t(); 48 std::string message = description + ", " + ex.code().message() + ", " + ex.wha t();
49 DEBUG_ERROR_LOG(ex.code().value(), errorId, errorSubid, message); 49 DEBUG_ERROR_LOG(ex.code().value(), errorId, errorSubid, message);
50 } 50 }
51 51
52 #ifdef ENABLE_DEBUG_INFO 52 #ifdef ENABLE_DEBUG_INFO
53 53
54 void DebugLegacy(const CString& text, DWORD dwProcessId, DWORD dwThreadId) 54 void DebugLegacy(const CString& text, DWORD dwProcessId, DWORD dwThreadId)
Oleksandr 2015/02/27 07:50:15 Isn't this changeset about converting CStrings to
Eric 2015/02/27 14:26:56 It is, but I've split the work into two parts. Fir
55 { 55 {
56 #ifdef USE_CONSOLE 56 #ifdef USE_CONSOLE
57 CONSOLE("%s", CT2A(text.GetString(), CP_UTF8)); 57 CONSOLE("%s", CT2A(text.GetString(), CP_UTF8));
58 #endif 58 #endif
59 59
60 if (CPluginSettings::HasInstance()) 60 if (CPluginSettings::HasInstance())
61 { 61 {
62 #ifdef ENABLE_DEBUG_SPLIT_FILE 62 #ifdef ENABLE_DEBUG_SPLIT_FILE
63 CPluginSettings* settings = CPluginSettings::GetInstance(); 63 CPluginSettings* settings = CPluginSettings::GetInstance();
64 64
(...skipping 13 matching lines...) Expand all
78 } 78 }
79 if (dwThreadId == 0) 79 if (dwThreadId == 0)
80 { 80 {
81 dwThreadId = ::GetCurrentThreadId(); 81 dwThreadId = ::GetCurrentThreadId();
82 } 82 }
83 83
84 CStringA processInfo; 84 CStringA processInfo;
85 processInfo.Format("%4.4u.%4.4u - ", dwProcessId, dwThreadId); 85 processInfo.Format("%4.4u.%4.4u - ", dwProcessId, dwThreadId);
86 #endif 86 #endif
87 SYSTEMTIME st; 87 SYSTEMTIME st;
88 ::GetSystemTime(&st); 88 ::GetSystemTime(&st);
Oleksandr 2015/02/27 07:50:15 Probably easier to replace this with std::localtim
Eric 2015/02/27 14:26:56 Yes, we can do that when we rewrite this implement
89 89
90 CStringA sysTime; 90 CStringA sysTime;
91 sysTime.Format("%2.2d:%2.2d:%2.2d.%3.3d - ", st.wHour, st.wMinute, st.wSecon d, st.wMilliseconds); 91 sysTime.Format("%2.2d:%2.2d:%2.2d.%3.3d - ", st.wHour, st.wMinute, st.wSecon d, st.wMilliseconds);
92 92
93 CPluginDebugLock lock; 93 CPluginDebugLock lock;
94 if (lock.IsLocked()) 94 if (lock.IsLocked())
95 { 95 {
96 std::ofstream debugFile; 96 std::ofstream debugFile;
97 97
98 #ifdef ENABLE_DEBUG_SPLIT_FILE 98 #ifdef ENABLE_DEBUG_SPLIT_FILE
99 debugFile.open(GetDataPath(L"debug_" + processor + L".txt"), std::ios::app ); 99 debugFile.open(GetDataPath(L"debug_" + processor + L".txt"), std::ios::app );
100 #else 100 #else
101 debugFile.open(GetDataPath(L"debug.txt"), std::ios::app); 101 debugFile.open(GetDataPath(L"debug.txt"), std::ios::app);
102 #endif 102 #endif
103 int pos = 0; 103 int pos = 0;
104 CStringA line = text.Tokenize(L"\n\r", pos); 104 CStringA line = text.Tokenize(L"\n\r", pos);
Oleksandr 2015/02/27 07:50:15 Looks like just a place for wcstok_s again
Eric 2015/02/27 14:26:56 Actually, we don't need to tokenize at all here. T
105 105
106 while (pos >= 0) 106 while (pos >= 0)
107 { 107 {
108 debugFile.write(sysTime.GetBuffer(), sysTime.GetLength()); 108 debugFile.write(sysTime.GetBuffer(), sysTime.GetLength());
109 #ifndef ENABLE_DEBUG_SPLIT_FILE 109 #ifndef ENABLE_DEBUG_SPLIT_FILE
110 debugFile.write(processInfo.GetBuffer(), processInfo.GetLength()); 110 debugFile.write(processInfo.GetBuffer(), processInfo.GetLength());
111 #endif 111 #endif
112 debugFile.write(line.GetBuffer(), line.GetLength()); 112 debugFile.write(line.GetBuffer(), line.GetLength());
113 debugFile.write("\n", 1); 113 debugFile.write("\n", 1);
114 114
(...skipping 22 matching lines...) Expand all
137 void CPluginDebug::DebugException(const std::exception& ex) 137 void CPluginDebug::DebugException(const std::exception& ex)
138 { 138 {
139 auto error = std::string("!!! Exception:") + ex.what(); 139 auto error = std::string("!!! Exception:") + ex.what();
140 #ifdef ENABLE_DEBUG_ERROR 140 #ifdef ENABLE_DEBUG_ERROR
141 Debug(error); 141 Debug(error);
142 #endif 142 #endif
143 143
144 DEBUG_SELFTEST("************************************************************** ******************\n" + error + "\n********************************************* ***********************************") 144 DEBUG_SELFTEST("************************************************************** ******************\n" + error + "\n********************************************* ***********************************")
145 } 145 }
146 146
147 void DebugErrorCodeLegacy(DWORD errorCode, const CString& error, DWORD dwProcess Id, DWORD dwThreadId) 147 void DebugErrorCodeLegacy(DWORD errorCode, const CString& error, DWORD dwProcess Id, DWORD dwThreadId)
Oleksandr 2015/02/27 07:50:15 Same here. Why do we need legacy functions after t
Eric 2015/02/27 14:26:56 See above. Same reason.
148 { 148 {
149 CString errorCodeText; 149 CString errorCodeText;
150 errorCodeText.Format(L"%u (0x%8.8x)", errorCode, errorCode); 150 errorCodeText.Format(L"%u (0x%8.8x)", errorCode, errorCode);
151 151
152 CString finalError = error + L". error=" + errorCodeText; 152 CString finalError = error + L". error=" + errorCodeText;
153 153
154 #ifdef ENABLE_DEBUG_ERROR 154 #ifdef ENABLE_DEBUG_ERROR
155 DebugLegacy(finalError, dwProcessId, dwThreadId); 155 DebugLegacy(finalError, dwProcessId, dwThreadId);
156 #endif 156 #endif
157 157
158 DEBUG_SELFTEST(L"************************************************************* *******************\n" + finalError + "\ n************************************** ******************************************") 158 DEBUG_SELFTEST(L"************************************************************* *******************\n" + finalError + "\n*************************************** *****************************************")
159 } 159 }
160 160
161 void CPluginDebug::DebugErrorCode(DWORD errorCode, const std::string& error, DWO RD processId, DWORD threadId) 161 void CPluginDebug::DebugErrorCode(DWORD errorCode, const std::string& error, DWO RD processId, DWORD threadId)
162 { 162 {
163 DebugErrorCodeLegacy(errorCode, CString(error.c_str()), processId, threadId); 163 DebugErrorCodeLegacy(errorCode, CString(error.c_str()), processId, threadId);
164 } 164 }
165 165
166 #endif 166 #endif
167 167
168 // ============================================================================ 168 // ============================================================================
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 srcTrunc = srcTrunc.Left(67) + L"..." + srcTrunc.Right(30); 249 srcTrunc = srcTrunc.Left(67) + L"..." + srcTrunc.Right(30);
250 } 250 }
251 251
252 CString blocking; 252 CString blocking;
253 blocking.Format(L"Ignored %-12s %s %s", ToCString(type), domain.empty()? L" -" : ToCString(domain), srcTrunc); 253 blocking.Format(L"Ignored %-12s %s %s", ToCString(type), domain.empty()? L" -" : ToCString(domain), srcTrunc);
254 254
255 DebugResultLegacy(blocking); 255 DebugResultLegacy(blocking);
256 } 256 }
257 257
258 #endif // ENABLE_DEBUG_RESULT_IGNORED 258 #endif // ENABLE_DEBUG_RESULT_IGNORED
LEFTRIGHT

Powered by Google App Engine
This is Rietveld