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

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

Issue 5187613258416128: Issue #1234 - Rewrite internals of debug facility (Closed)
Left Patch Set: rebase + address comments Created March 31, 2015, 1:56 p.m.
Right Patch Set: rebase only Created Nov. 26, 2015, 1:02 p.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/PluginSettings.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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include "PluginStdAfx.h" 18 #include "PluginStdAfx.h"
19 #include "PluginDebug.h" 19 #include "PluginDebug.h"
20 #include "PluginClientBase.h"
20 #include "PluginMutex.h" 21 #include "PluginMutex.h"
21 #include "PluginClient.h" 22 #include "PluginClientBase.h"
22 #include "../shared/Utils.h" 23 #include "../shared/Utils.h"
23 #include <iomanip> 24 #include <iomanip>
25 #include <memory>
24 26
25 namespace 27 namespace
26 { 28 {
27 class CPluginDebugLock 29 class CPluginDebugLock
28 : public CPluginMutex 30 : public CPluginMutex
29 { 31 {
30 private: 32 private:
31 static CComAutoCriticalSection s_criticalSectionDebugLock; 33 static CComAutoCriticalSection s_criticalSectionDebugLock;
32 34
33 public: 35 public:
34 CPluginDebugLock() 36 CPluginDebugLock()
35 : CPluginMutex(L"DebugFile", PLUGIN_ERROR_MUTEX_DEBUG_FILE) 37 : CPluginMutex(L"DebugFile", PLUGIN_ERROR_MUTEX_DEBUG_FILE)
36 { 38 {
37 s_criticalSectionDebugLock.Lock(); 39 s_criticalSectionDebugLock.Lock();
38 } 40 }
39 41
40 ~CPluginDebugLock() 42 ~CPluginDebugLock()
41 { 43 {
42 s_criticalSectionDebugLock.Unlock(); 44 s_criticalSectionDebugLock.Unlock();
43 } 45 }
44 }; 46 };
45 47
46 CComAutoCriticalSection CPluginDebugLock::s_criticalSectionDebugLock; 48 CComAutoCriticalSection CPluginDebugLock::s_criticalSectionDebugLock;
47 49
48 class LogText 50 class LogText
49 { 51 {
50 public: 52 public:
51 virtual std::string Text() const = 0; 53 virtual std::string Text() const = 0;
54 virtual ~LogText() {};
52 }; 55 };
53 56
54 class LogTextFixed 57 class LogTextFixed
sergei 2015/12/02 13:53:00 What about naming of classes differently? Let's a
Eric 2015/12/02 15:01:24 No. Naming the subclasses of 'class LogText' with
55 : public LogText 58 : public LogText
56 { 59 {
57 protected: 60 protected:
58 const std::string fixedText; 61 const std::string fixedText;
59 62
60 public: 63 public:
61 LogTextFixed(const std::string& text) 64 explicit LogTextFixed(const std::string& text)
62 : fixedText(text) 65 : fixedText(text)
63 {} 66 {}
64 67
65 LogTextFixed(const std::exception& ex) 68 explicit LogTextFixed(const std::exception& ex)
66 : fixedText(std::string("!!! Exception: ") + ex.what()) 69 : fixedText(std::string("!!! Exception: ") + ex.what())
67 {} 70 {}
68 71
69 virtual std::string Text() const override 72 virtual std::string Text() const override
sergei 2015/11/30 14:15:03 I would propose to omit `virtual` when we use `ove
Eric 2015/11/30 17:39:01 It's good to have both in place. Makes the intent
sergei 2015/11/30 18:14:29 Actually, I would like to note that it's not relat
Eric 2015/12/01 20:43:58 OK.
70 { 73 {
71 return fixedText; 74 return fixedText;
72 } 75 }
73 }; 76 };
74 77
75 class LogTextErrorCode 78 class LogTextErrorCode
76 : public LogTextFixed 79 : public LogTextFixed
77 { 80 {
78 protected: 81 protected:
79 const DWORD errorCode; 82 const DWORD errorCode;
(...skipping 20 matching lines...) Expand all
100 : public SYSTEMTIME 103 : public SYSTEMTIME
101 { 104 {
102 SystemTime() 105 SystemTime()
103 { 106 {
104 ::GetSystemTime(static_cast<SYSTEMTIME*>(this)); 107 ::GetSystemTime(static_cast<SYSTEMTIME*>(this));
105 } 108 }
106 }; 109 };
107 110
108 class LogEntry 111 class LogEntry
109 { 112 {
110 const std::unique_ptr<LogText> text; 113 const std::unique_ptr<LogText> text;
sergei 2015/12/02 13:53:00 Just in case, what is the reason of extensively pu
Eric 2015/12/02 15:01:24 'const' members mean "initialized only at construc
111 114
112 std::string InitialPrefix() const 115 std::string InitialPrefix() const
113 { 116 {
114 std::stringstream ss; 117 std::stringstream ss;
115 ss << std::setfill('0') << std::setw(2) << st.wHour; 118 ss << std::setfill('0') << std::setw(2) << st.wHour;
116 ss << ":"; 119 ss << ":";
117 ss << std::setfill('0') << std::setw(2) << st.wMinute; 120 ss << std::setfill('0') << std::setw(2) << st.wMinute;
118 ss << ":"; 121 ss << ":";
119 ss << std::setfill('0') << std::setw(2) << st.wSecond; 122 ss << std::setfill('0') << std::setw(2) << st.wSecond;
120 ss << "."; 123 ss << ".";
(...skipping 18 matching lines...) Expand all
139 /** 142 /**
140 * The process within which the log-generating statement executes. 143 * The process within which the log-generating statement executes.
141 */ 144 */
142 const DWORD processId; 145 const DWORD processId;
143 146
144 /** 147 /**
145 * The thread within which the log-generating statement executes. 148 * The thread within which the log-generating statement executes.
146 */ 149 */
147 const DWORD threadId; 150 const DWORD threadId;
148 151
149 LogEntry(LogText* text) 152 explicit LogEntry(LogText* text)
150 : processId(::GetCurrentProcessId()), threadId(::GetCurrentThreadId()), te xt(text) 153 : processId(::GetCurrentProcessId()), threadId(::GetCurrentThreadId()), te xt(text)
151 {} 154 {}
152 155
153 LogEntry(LogText* text, DWORD processId, DWORD threadId) 156 LogEntry(LogText* text, DWORD processId, DWORD threadId)
154 : processId(processId), threadId(threadId), text(text) 157 : processId(processId), threadId(threadId), text(text)
155 {} 158 {}
156 159
157 void Write(std::ostream& out) const 160 void Write(std::ostream& out) const
158 { 161 {
159 CPluginDebugLock lock; 162 CPluginDebugLock lock;
(...skipping 17 matching lines...) Expand all
177 linePosition = eolPosition + 1; 180 linePosition = eolPosition + 1;
178 } 181 }
179 } 182 }
180 out.flush(); 183 out.flush();
181 } 184 }
182 } 185 }
183 186
184 void WriteFile(const std::wstring& logFileName) const 187 void WriteFile(const std::wstring& logFileName) const
185 { 188 {
186 std::ofstream out; 189 std::ofstream out;
187 out.open(logFileName, std::ios::app); 190 out.open(logFileName, std::ios::app);
sergei 2015/12/02 13:53:00 I wonder whether we need a synchronization here. E
Eric 2015/12/02 15:01:24 Easy answer: This locking behavior is the same as
188 Write(out); 191 Write(out);
189 } 192 }
190 }; 193 };
191 194
192 std::wstring GetDataPath(const std::wstring& filename) 195 std::wstring GetDataPath(const std::wstring& filename)
193 { 196 {
194 return GetAppDataPath() + L"\\" + filename; 197 return GetAppDataPath() + L"\\" + filename;
195 } 198 }
196 199
197 void LogWriteDefault(const LogEntry& le) 200 void LogWriteDefault(const LogEntry& le)
(...skipping 27 matching lines...) Expand all
225 { 228 {
226 std::string message = description + ", " + ex.code().message() + ", " + ex.wha t(); 229 std::string message = description + ", " + ex.code().message() + ", " + ex.wha t();
227 DEBUG_ERROR_LOG(ex.code().value(), errorId, errorSubid, message); 230 DEBUG_ERROR_LOG(ex.code().value(), errorId, errorSubid, message);
228 } 231 }
229 232
230 #if (defined ENABLE_DEBUG_INFO) 233 #if (defined ENABLE_DEBUG_INFO)
231 234
232 void CPluginDebug::DebugException(const std::exception& ex) 235 void CPluginDebug::DebugException(const std::exception& ex)
233 { 236 {
234 auto lt = new LogTextFixed(ex); 237 auto lt = new LogTextFixed(ex);
238 LogEntry le(lt);
235 #ifdef ENABLE_DEBUG_ERROR 239 #ifdef ENABLE_DEBUG_ERROR
236 LogWriteDefault(LogEntry(lt)); 240 LogWriteDefault(le);
237 #endif 241 #endif
238 DEBUG_SELFTEST( 242 DEBUG_SELFTEST(
239 "*************************************************************************** *****\n" 243 "*************************************************************************** *****\n"
240 + lt.text() + "\n" 244 + lt->text() + "\n"
241 "*************************************************************************** *****") 245 "*************************************************************************** *****")
242 } 246 }
243 247
244 void CPluginDebug::DebugErrorCode(DWORD errorCode, const std::string& error, DWO RD processId, DWORD threadId) 248 void CPluginDebug::DebugErrorCode(DWORD errorCode, const std::string& error, DWO RD processId, DWORD threadId)
245 { 249 {
246 auto lt = new LogTextErrorCode(errorCode, error); 250 auto lt = new LogTextErrorCode(errorCode, error);
sergei 2015/04/02 07:41:12 Here and above, who will destroy it if ENABLE_DEBU
Eric 2015/05/19 15:13:56 Fixed.
251 LogEntry le(lt, processId, threadId);
247 #ifdef ENABLE_DEBUG_ERROR 252 #ifdef ENABLE_DEBUG_ERROR
248 LogWriteDefault(LogEntry(lt, processId, threadId)); 253 LogWriteDefault(le);
249 #endif 254 #endif
250 DEBUG_SELFTEST( 255 DEBUG_SELFTEST(
251 "*************************************************************************** *****\n" 256 "*************************************************************************** *****\n"
252 + lt.text() + "\n" 257 + lt->text() + "\n"
sergei 2015/04/02 07:41:12 should it be `lt->`?
Eric 2015/05/19 15:13:56 Fixed. It should also be that we just eliminate D
253 "*************************************************************************** *****") 258 "*************************************************************************** *****")
254 } 259 }
255 260
256 #endif 261 #endif
257 262
258 // ============================================================================ 263 // ============================================================================
259 // Debug result 264 // Debug result
260 // ============================================================================ 265 // ============================================================================
261 266
262 #ifdef ENABLE_DEBUG_RESULT 267 #ifdef ENABLE_DEBUG_RESULT
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 317
313 318
314 #ifdef ENABLE_DEBUG_RESULT_IGNORED 319 #ifdef ENABLE_DEBUG_RESULT_IGNORED
315 320
316 void CPluginDebug::DebugResultIgnoring(const std::wstring& type, const std::wstr ing& src, const std::wstring& domain) 321 void CPluginDebug::DebugResultIgnoring(const std::wstring& type, const std::wstr ing& src, const std::wstring& domain)
317 { 322 {
318 DebugResultFormat(L"Ignored", type, domain.empty() ? L"-" : domain, Shorten(sr c)); 323 DebugResultFormat(L"Ignored", type, domain.empty() ? L"-" : domain, Shorten(sr c));
319 } 324 }
320 325
321 #endif // ENABLE_DEBUG_RESULT_IGNORED 326 #endif // ENABLE_DEBUG_RESULT_IGNORED
LEFTRIGHT

Powered by Google App Engine
This is Rietveld