2 // This file is part of the aMule Project.
4 // Copyright (C) 2005-2008 aMule Team ( admin@amule.org / http://www.amule.org )
6 // Any parts of this program derived from the xMule, lMule or eMule project,
7 // or contributed by third-party developers are copyrighted by their
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 //! General warnings/errors.
36 //! Warnings/Errors for the main hashing thread.
38 //! Warnings/Errors for client-objects.
40 //! Warnings/Errors for the local client protocol.
42 //! Warnings/Errors for the remote client protocol.
44 //! Warnings/Errors when parsing packets.
46 //! Warnings/Errors for the CFile class.
48 //! Warnings/Errors related to reading/writing files.
50 //! Warnings/Errors when using the zLib library.
52 //! Warnings/Errors for the AICH-syncronization thread.
54 //! Warnings/Errors for transfering AICH hash-sets.
56 //! Warnings/Errors when recovering with AICH.
58 //! Warnings/Errors for the CListenSocket class.
60 //! Warnings/Errors for Client-Credits.
62 //! Warnings/Errors for the client UDP socket.
64 //! Warnings/Errors for the download-queue.
66 //! Warnings/Errors for the IP-Filter.
68 //! Warnings/Errors for known-files.
70 //! Warnings/Errors for part-files.
72 //! Warnings/Errors for SHA-hashset creation.
74 //! Warnings/Errors for servers, server connections.
76 //! Warnings/Errors for proxy.
78 //! Warnings/Errors related to searching.
80 //! Warnings/Errors related to the server UDP socket.
82 //! Warning/Errors related to Kademlia UDP comunication on client
84 //! Warning/Errors related to Kademlia Search
86 //! Warning/Errors related to Kademlia Routing
88 //! Warning/Errors related to Kademlia Indexing
90 //! Warning/Errors related to Kademlia Main Thread
92 //! Warning/Errors related to Kademlia Preferences
94 //! Warnings/Errors related to partfile importer
96 //! Warnings/Errors related to the basic UDP socket-class.
98 //! Warnings/Errors related to the thread-scheduler.
100 //! Warnings/Errors related to the Universal Plug and Play subsystem.
102 //! Warnings/Errors related to the UDP Firewall Tester
104 //! Warnings/Errors related to Kad packet tracking.
105 logKadPacketTracking
,
106 //! Warnings/Errors related to Kad entry tracking.
108 // IMPORTANT NOTE: when you add values to this enum, update the g_debugcats
109 // array in Logger.cpp!
115 * Container-class for the debugging categories.
123 * @param type The actual debug-category type.
124 * @param name The user-readable name.
126 CDebugCategory( DebugType type
, const wxString
& name
);
130 * Returns true if the category is enabled.
132 bool IsEnabled() const;
135 * Enables/Disables the category.
137 void SetEnabled( bool );
141 * Returns the user-readable name.
143 const wxString
& GetName() const;
146 * Returns the actual type.
148 DebugType
GetType() const;
151 //! The user-readable name.
155 //! Whenever or not the category is enabled.
161 * Namespace containing functions for logging operations.
166 * Returns true if debug-messages should be generated for a specific category.
168 bool IsEnabled( DebugType
);
171 * Enables or disables debug-messages for a specific category.
173 void SetEnabled( DebugType type
, bool enabled
);
177 * Logs the specified line of text.
181 * @param critical If true, then the message will be made visible directly to the user.
182 * @param str The actual line of text.
184 * This function is thread-safe. If it is called by the main thread, the
185 * event will be sent directly to the application, otherwise it will be
186 * queued in the event-loop.
189 const wxString
&file
,
192 const wxString
&str
);
195 * Logs the specified line of text, prefixed with the name of the DebugType.
199 * @param critical If true, then the message will be made visible directly to the user.
200 * @param type The debug-category, the name of which will be prepended to the line.
201 * @param str The actual line of text.
203 * This function is thread-safe. If it is called by the main thread, the
204 * event will be sent directly to the application, otherwise it will be
205 * queued in the event-loop.
208 const wxString
&file
,
212 const wxString
&str
);
216 * Ensures that any pending entries are sent to the app.
218 * TODO: Ensure that entries are appended to the
219 * logfile even when queued to avoid risk of
222 void FlushPendingEntries();
225 * Returns a category specified by index.
227 const CDebugCategory
& GetDebugCategory( int index
);
230 * Returns the number of debug-categories.
232 unsigned int GetDebugCategoryCount();
237 * This class forwards log-lines from wxWidgets to CLogger.
239 class CLoggerTarget
: public wxLog
245 * @see wxLog::DoLogString
247 void DoLogString(const wxChar
*msg
, time_t);
251 DECLARE_LOCAL_EVENT_TYPE(MULE_EVT_LOGLINE
, -1)
254 /** This event is sent when a log-line is queued. */
255 class CLoggingEvent
: public wxEvent
258 CLoggingEvent(bool critical
, const wxString
& msg
)
259 : wxEvent(-1, MULE_EVT_LOGLINE
)
260 , m_critical(critical
)
261 // Deep copy, to avoid thread-unsafe reference counting. */
262 , m_msg(msg
.c_str(), msg
.Length())
266 const wxString
& Message() const {
270 bool IsCritical() const {
274 wxEvent
* Clone() const {
275 return new CLoggingEvent(m_critical
, m_msg
);
284 typedef void (wxEvtHandler::*MuleLogEventFunction
)(CLoggingEvent
&);
286 //! Event-handler for completed hashings of new shared files and partfiles.
287 #define EVT_MULE_LOGGING(func) \
288 DECLARE_EVENT_TABLE_ENTRY(MULE_EVT_LOGLINE, -1, -1, \
289 (wxObjectEventFunction) (wxEventFunction) \
290 wxStaticCastEvent(MuleLogEventFunction, &func), (wxObject*) NULL),
294 * These macros should be used when logging. The
295 * AddLogLineM macro will simply call one of the
296 * two CLogger::AddLogLine functions depending on
297 * paramteres, but AddDebugLogLineM will only log
298 * a message if the message is either critical or
299 * the specified debug-type is enabled in the
302 #if defined(MULEUNIT)
303 #define AddDebugLogLineM(critical, type, string) do {} while (false)
304 #define AddLogLineM(...) do {} while (false)
307 #define AddDebugLogLineM(critical, type, string) \
309 if (critical || CLogger::IsEnabled(type)) { \
310 CLogger::AddLogLine(__TFILE__, __LINE__, critical, type, string); \
314 #define AddDebugLogLineM(critical, type, string) \
317 CLogger::AddLogLine(__TFILE__, __LINE__, critical, type, string); \
322 #define AddLogLineM(...) CLogger::AddLogLine(__TFILE__, __LINE__, __VA_ARGS__)
326 // File_checked_for_headers