2 // This file is part of the aMule Project.
4 // Copyright (c) 2005-2011 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
35 //! Standard warning, not debug
37 //! General warnings/errors.
39 //! Warnings/Errors for the main hashing thread.
41 //! Warnings/Errors for client-objects.
43 //! Warnings/Errors for the local client protocol.
45 //! Warnings/Errors for the remote client protocol.
47 //! Warnings/Errors when parsing packets.
49 //! Warnings/Errors for the CFile class.
51 //! Warnings/Errors related to reading/writing files.
53 //! Warnings/Errors when using the zLib library.
55 //! Warnings/Errors for the AICH-syncronization thread.
57 //! Warnings/Errors for transfering AICH hash-sets.
59 //! Warnings/Errors when recovering with AICH.
61 //! Warnings/Errors for the CListenSocket class.
63 //! Warnings/Errors for Client-Credits.
65 //! Warnings/Errors for the client UDP socket.
67 //! Warnings/Errors for the download-queue.
69 //! Warnings/Errors for the IP-Filter.
71 //! Warnings/Errors for known-files.
73 //! Warnings/Errors for part-files.
75 //! Warnings/Errors for SHA-hashset creation.
77 //! Warnings/Errors for servers, server connections.
79 //! Warnings/Errors for proxy.
81 //! Warnings/Errors related to searching.
83 //! Warnings/Errors related to the server UDP socket.
85 //! Warning/Errors related to Kademlia UDP comunication on client
87 //! Warning/Errors related to Kademlia Search
89 //! Warning/Errors related to Kademlia Routing
91 //! Warning/Errors related to Kademlia Indexing
93 //! Warning/Errors related to Kademlia Main Thread
95 //! Warning/Errors related to Kademlia Preferences
97 //! Warnings/Errors related to partfile importer
99 //! Warnings/Errors related to the basic UDP socket-class.
101 //! Warnings/Errors related to the thread-scheduler.
103 //! Warnings/Errors related to the Universal Plug and Play subsystem.
105 //! Warnings/Errors related to the UDP Firewall Tester
107 //! Warnings/Errors related to Kad packet tracking.
108 logKadPacketTracking
,
109 //! Warnings/Errors related to Kad entry tracking.
111 //! Full log of external connection packets
113 //! Warnings/Errors related to HTTP traffic
115 // IMPORTANT NOTE: when you add values to this enum, update the g_debugcats
116 // array in Logger.cpp!
122 * Container-class for the debugging categories.
130 * @param type The actual debug-category type.
131 * @param name The user-readable name.
133 CDebugCategory( DebugType type
, const wxString
& name
)
134 : m_name(name
), m_type(type
), m_enabled(false)
139 * Returns true if the category is enabled.
141 bool IsEnabled() const { return m_enabled
; }
144 * Enables/Disables the category.
146 void SetEnabled( bool enabled
) { m_enabled
= enabled
; }
150 * Returns the user-readable name.
152 const wxString
& GetName() const { return m_name
; }
155 * Returns the actual type.
157 DebugType
GetType() const { return m_type
; }
160 //! The user-readable name.
164 //! Whenever or not the category is enabled.
170 * Functions for logging operations.
172 class CLogger
: public wxEvtHandler
176 * Returns true if debug-messages should be generated for a specific category.
179 bool IsEnabled( DebugType
) const;
181 bool IsEnabled( DebugType
) const { return false; }
185 * Enables or disables debug-messages for a specific category.
187 void SetEnabled( DebugType type
, bool enabled
);
190 * Returns true if logging to stdout is enabled
192 bool IsEnabledStdoutLog() const { return m_StdoutLog
; }
195 * Enables or disables logging to stdout.
197 void SetEnabledStdoutLog(bool enabled
) { m_StdoutLog
= enabled
; }
201 * Logs the specified line of text, prefixed with the name of the DebugType.
202 * (except for logStandard)
206 * @param critical If true, then the message will be made visible directly to the user.
207 * @param type The debug-category, the name of which will be prepended to the line.
208 * @param str The actual line of text.
210 * This function is thread-safe. If it is called by the main thread, the
211 * event will be sent directly to the application, otherwise it will be
212 * queued in the event-loop.
215 const wxString
&file
,
220 bool toStdout
= false,
225 const wxString
&file
,
229 const std::ostringstream
&msg
);
232 const wxString
&file
,
235 const std::ostringstream
&msg
);
239 * Emergency log for crashes.
241 void EmergencyLog(const wxString
&message
, bool closeLog
= true);
244 * Returns a category specified by index.
246 const CDebugCategory
& GetDebugCategory( int index
);
249 * Returns the number of debug-categories.
251 unsigned int GetDebugCategoryCount();
254 * Open Logfile, true on success
256 bool OpenLogfile(const wxString
& name
);
264 * Get name of Logfile
266 const wxString
& GetLogfileName() const {
267 return m_LogfileName
;
273 void OnLoggingEvent(class CLoggingEvent
& evt
);
285 class wxFFileOutputStream
* applog
; // the logfile
286 wxString m_LogfileName
;
287 wxString m_ApplogBuf
;
289 int m_count
; // output line counter
292 * Write all waiting log info to the logfile
297 * Really output a single line
299 void DoLine(const wxString
& line
, bool toStdout
, bool toGUI
);
301 DECLARE_EVENT_TABLE()
304 extern CLogger theLogger
;
307 * This class forwards log-lines from wxWidgets to CLogger.
309 class CLoggerTarget
: public wxLog
315 * @see wxLog::DoLogString
317 #if wxCHECK_VERSION(2, 9, 0)
318 void DoLogText(const wxString
&msg
);
320 void DoLogString(const wxChar
*msg
, time_t);
325 DECLARE_LOCAL_EVENT_TYPE(MULE_EVT_LOGLINE
, -1)
328 /** This event is sent when a log-line is queued. */
329 class CLoggingEvent
: public wxEvent
332 CLoggingEvent(bool critical
, bool toStdout
, bool toGUI
, const wxString
& msg
)
333 : wxEvent(-1, MULE_EVT_LOGLINE
)
334 , m_critical(critical
)
337 // Deep copy, to avoid thread-unsafe reference counting. */
338 , m_msg(msg
.c_str(), msg
.Length())
342 const wxString
& Message() const {
346 bool IsCritical() const {
350 bool ToStdout() const {
358 wxEvent
* Clone() const {
359 return new CLoggingEvent(m_critical
, m_stdout
, m_GUI
, m_msg
);
370 typedef void (wxEvtHandler::*MuleLogEventFunction
)(CLoggingEvent
&);
372 //! Event-handler for completed hashings of new shared files and partfiles.
373 #define EVT_MULE_LOGGING(func) \
374 DECLARE_EVENT_TABLE_ENTRY(MULE_EVT_LOGLINE, -1, -1, \
375 (wxObjectEventFunction) (wxEventFunction) \
376 wxStaticCastEvent(MuleLogEventFunction, &func), (wxObject*) NULL),
379 // access the logfile for EC
383 class wxFFileInputStream
* m_logfile
;
384 class wxCharBuffer
* m_buffer
;
391 // construct/destruct
396 // Reset (used when logfile is cleared)
400 // get a String (if there is one)
402 bool GetString(wxString
& s
);
404 // is a String available ?
411 * These macros should be used when logging. The
412 * AddLogLineM macro will simply call one of the
413 * two CLogger::AddLogLine functions depending on
414 * parameters, but AddDebugLogLine* will only log
415 * a message if the message is either critical or
416 * the specified debug-type is enabled in the
418 * AddLogLineMS will also always print to stdout.
421 #define AddDebugLogLineN(...) do {} while (false)
422 #define AddLogLineN(...) do {} while (false)
423 #define AddLogLineNS(...) do {} while (false)
424 #define AddDebugLogLineC(...) do {} while (false)
425 #define AddLogLineC(...) do {} while (false)
426 #define AddLogLineCS(...) do {} while (false)
428 // Macro for UPnP. This is not a debug macro, but wants its category printed nevertheless (sigh).
429 #define AddLogLineU(critical, type, string) theLogger.AddLogLine(__TFILE__, __LINE__, critical, type, string)
430 // Macros for 'N'on critical logging
432 #define AddDebugLogLineN(type, string) theLogger.AddLogLine(__TFILE__, __LINE__, false, type, string)
434 #define AddDebugLogLineN(type, string) do {} while (false)
436 #define AddLogLineN(string) theLogger.AddLogLine(__TFILE__, __LINE__, false, logStandard, string)
437 #define AddLogLineNS(string) theLogger.AddLogLine(__TFILE__, __LINE__, false, logStandard, string, true)
438 // Macros for 'C'ritical logging
439 #define AddDebugLogLineC(type, string) theLogger.AddLogLine(__TFILE__, __LINE__, true, type, string)
440 #define AddLogLineC(string) theLogger.AddLogLine(__TFILE__, __LINE__, true, logStandard, string)
441 #define AddLogLineCS(string) theLogger.AddLogLine(__TFILE__, __LINE__, true, logStandard, string, true)
442 // Macros for logging to logfile only
443 #define AddDebugLogLineF(type, string) theLogger.AddLogLine(__TFILE__, __LINE__, false, type, string, false, false)
444 #define AddLogLineF(string) theLogger.AddLogLine(__TFILE__, __LINE__, false, logStandard, string, false, false)
448 // File_checked_for_headers