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 to current public tip Created June 28, 2015, 3:25 a.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
(...skipping 12 matching lines...) Expand all
23 #include "../shared/Utils.h" 23 #include "../shared/Utils.h"
24 #include <iomanip> 24 #include <iomanip>
25 #include <memory> 25 #include <memory>
26 26
27 namespace 27 namespace
28 { 28 {
29 class CPluginDebugLock 29 class CPluginDebugLock
30 : public CPluginMutex 30 : public CPluginMutex
31 { 31 {
32 private: 32 private:
33 static CComAutoCriticalSection s_criticalSectionDebugLock; 33 static CComAutoCriticalSection s_criticalSectionDebugLock;
sergei 2015/10/12 12:46:20 What will happen if we remove `s_criticalSectionDe
Eric 2015/10/13 17:33:19 The problem right now (and also in the later versi
sergei 2015/11/30 14:15:03 The plan is clear but the reason we need `s_critic
Eric 2015/11/30 17:39:01 There's only one occurrence of 'CPluginDebugLock',
sergei 2015/11/30 18:14:29 There is already CPluginMutex and it serializes th
Eric 2015/12/01 20:43:57 Now I see what you're getting at. Yes, the critica
sergei 2015/12/02 13:52:59 Acknowledged.
34 34
35 public: 35 public:
36 CPluginDebugLock() 36 CPluginDebugLock()
37 : CPluginMutex(L"DebugFile", PLUGIN_ERROR_MUTEX_DEBUG_FILE) 37 : CPluginMutex(L"DebugFile", PLUGIN_ERROR_MUTEX_DEBUG_FILE)
38 { 38 {
39 s_criticalSectionDebugLock.Lock(); 39 s_criticalSectionDebugLock.Lock();
40 } 40 }
41 41
42 ~CPluginDebugLock() 42 ~CPluginDebugLock()
43 { 43 {
44 s_criticalSectionDebugLock.Unlock(); 44 s_criticalSectionDebugLock.Unlock();
45 } 45 }
46 }; 46 };
47 47
48 CComAutoCriticalSection CPluginDebugLock::s_criticalSectionDebugLock; 48 CComAutoCriticalSection CPluginDebugLock::s_criticalSectionDebugLock;
49 49
50 class LogText 50 class LogText
sergei 2015/10/12 12:46:20 virtual destructor is missed here, the derived cla
Eric 2015/10/13 17:33:19 Yep. I'll add it after I get a rebase posted.
51 { 51 {
52 public: 52 public:
53 virtual std::string Text() const = 0; 53 virtual std::string Text() const = 0;
54 virtual ~LogText() {};
54 }; 55 };
55 56
56 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
57 : public LogText 58 : public LogText
58 { 59 {
59 protected: 60 protected:
60 const std::string fixedText; 61 const std::string fixedText;
61 62
62 public: 63 public:
63 explicit LogTextFixed(const std::string& text) 64 explicit LogTextFixed(const std::string& text)
64 : fixedText(text) 65 : fixedText(text)
65 {} 66 {}
66 67
67 explicit LogTextFixed(const std::exception& ex) 68 explicit LogTextFixed(const std::exception& ex)
68 : fixedText(std::string("!!! Exception: ") + ex.what()) 69 : fixedText(std::string("!!! Exception: ") + ex.what())
69 {} 70 {}
70 71
71 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.
72 { 73 {
73 return fixedText; 74 return fixedText;
74 } 75 }
75 }; 76 };
76 77
77 class LogTextErrorCode 78 class LogTextErrorCode
78 : public LogTextFixed 79 : public LogTextFixed
79 { 80 {
80 protected: 81 protected:
81 const DWORD errorCode; 82 const DWORD errorCode;
(...skipping 20 matching lines...) Expand all
102 : public SYSTEMTIME 103 : public SYSTEMTIME
103 { 104 {
104 SystemTime() 105 SystemTime()
105 { 106 {
106 ::GetSystemTime(static_cast<SYSTEMTIME*>(this)); 107 ::GetSystemTime(static_cast<SYSTEMTIME*>(this));
107 } 108 }
108 }; 109 };
109 110
110 class LogEntry 111 class LogEntry
111 { 112 {
112 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
113 114
114 std::string InitialPrefix() const 115 std::string InitialPrefix() const
115 { 116 {
116 std::stringstream ss; 117 std::stringstream ss;
117 ss << std::setfill('0') << std::setw(2) << st.wHour; 118 ss << std::setfill('0') << std::setw(2) << st.wHour;
118 ss << ":"; 119 ss << ":";
119 ss << std::setfill('0') << std::setw(2) << st.wMinute; 120 ss << std::setfill('0') << std::setw(2) << st.wMinute;
120 ss << ":"; 121 ss << ":";
121 ss << std::setfill('0') << std::setw(2) << st.wSecond; 122 ss << std::setfill('0') << std::setw(2) << st.wSecond;
122 ss << "."; 123 ss << ".";
(...skipping 28 matching lines...) Expand all
151 explicit LogEntry(LogText* text) 152 explicit LogEntry(LogText* text)
152 : processId(::GetCurrentProcessId()), threadId(::GetCurrentThreadId()), te xt(text) 153 : processId(::GetCurrentProcessId()), threadId(::GetCurrentThreadId()), te xt(text)
153 {} 154 {}
154 155
155 LogEntry(LogText* text, DWORD processId, DWORD threadId) 156 LogEntry(LogText* text, DWORD processId, DWORD threadId)
156 : processId(processId), threadId(threadId), text(text) 157 : processId(processId), threadId(threadId), text(text)
157 {} 158 {}
158 159
159 void Write(std::ostream& out) const 160 void Write(std::ostream& out) const
160 { 161 {
161 CPluginDebugLock lock; 162 CPluginDebugLock lock;
Eric 2015/11/30 17:39:01 This is the sentry object. 'Write()' is currently
162 if (lock.IsLocked()) 163 if (lock.IsLocked())
163 { 164 {
164 auto lines = text->Text(); 165 auto lines = text->Text();
165 size_t linePosition = 0; 166 size_t linePosition = 0;
166 while (true) 167 while (true)
167 { 168 {
168 auto eolPosition = lines.find('\n', linePosition); 169 auto eolPosition = lines.find('\n', linePosition);
169 auto prefix = linePosition == 0 ? InitialPrefix() : SubsequentPrefix() ; 170 auto prefix = linePosition == 0 ? InitialPrefix() : SubsequentPrefix() ;
170 out << prefix; 171 out << prefix;
171 if (eolPosition == std::string::npos) 172 if (eolPosition == std::string::npos)
172 { 173 {
173 out << lines.substr(linePosition) << "\n"; 174 out << lines.substr(linePosition) << "\n";
174 break; 175 break;
175 } 176 }
176 else 177 else
177 { 178 {
178 out << lines.substr(linePosition, eolPosition - linePosition) << "\n "; 179 out << lines.substr(linePosition, eolPosition - linePosition) << "\n ";
179 linePosition = eolPosition + 1; 180 linePosition = eolPosition + 1;
180 } 181 }
181 } 182 }
182 out.flush(); 183 out.flush();
183 } 184 }
184 } 185 }
185 186
186 void WriteFile(const std::wstring& logFileName) const 187 void WriteFile(const std::wstring& logFileName) const
187 { 188 {
188 std::ofstream out; 189 std::ofstream out;
189 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
190 Write(out); 191 Write(out);
191 } 192 }
192 }; 193 };
193 194
194 std::wstring GetDataPath(const std::wstring& filename) 195 std::wstring GetDataPath(const std::wstring& filename)
195 { 196 {
196 return GetAppDataPath() + L"\\" + filename; 197 return GetAppDataPath() + L"\\" + filename;
197 } 198 }
198 199
199 void LogWriteDefault(const LogEntry& le) 200 void LogWriteDefault(const LogEntry& le)
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 317
317 318
318 #ifdef ENABLE_DEBUG_RESULT_IGNORED 319 #ifdef ENABLE_DEBUG_RESULT_IGNORED
319 320
320 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)
321 { 322 {
322 DebugResultFormat(L"Ignored", type, domain.empty() ? L"-" : domain, Shorten(sr c)); 323 DebugResultFormat(L"Ignored", type, domain.empty() ? L"-" : domain, Shorten(sr c));
323 } 324 }
324 325
325 #endif // ENABLE_DEBUG_RESULT_IGNORED 326 #endif // ENABLE_DEBUG_RESULT_IGNORED
LEFTRIGHT

Powered by Google App Engine
This is Rietveld