 Issue 5187613258416128:
  Issue #1234 - Rewrite internals of debug facility  (Closed)
    
  
    Issue 5187613258416128:
  Issue #1234 - Rewrite internals of debug facility  (Closed) 
  | Left: | ||
| Right: | 
| LEFT | RIGHT | 
|---|---|
| 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 Loading... | |
| 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 | 
| 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 Loading... | |
| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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 | 
| LEFT | RIGHT |