]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: log.h | |
e54c96f1 | 3 | // Purpose: interface of wxLogWindow |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
4a6665c6 FM |
9 | |
10 | /** | |
11 | Different standard log levels (you may also define your own) used with | |
bc73d5ae | 12 | by standard wxLog functions wxLogError(), wxLogWarning(), etc... |
4a6665c6 FM |
13 | */ |
14 | enum wxLogLevelValues | |
15 | { | |
16 | wxLOG_FatalError, //!< program can't continue, abort immediately | |
17 | wxLOG_Error, //!< a serious error, user must be informed about it | |
18 | wxLOG_Warning, //!< user is normally informed about it but may be ignored | |
19 | wxLOG_Message, //!< normal message (i.e. normal output of a non GUI app) | |
20 | wxLOG_Status, //!< informational: might go to the status line of GUI app | |
21 | wxLOG_Info, //!< informational message (a.k.a. 'Verbose') | |
22 | wxLOG_Debug, //!< never shown to the user, disabled in release mode | |
23 | wxLOG_Trace, //!< trace messages are also only enabled in debug mode | |
24 | wxLOG_Progress, //!< used for progress indicator (not yet) | |
25 | wxLOG_User = 100, //!< user defined levels start here | |
26 | wxLOG_Max = 10000 | |
27 | }; | |
28 | ||
4a6665c6 FM |
29 | /** |
30 | The type used to specify a log level. | |
31 | ||
32 | Default values of ::wxLogLevel used by wxWidgets are contained in the | |
33 | ::wxLogLevelValues enumeration. | |
34 | */ | |
35 | typedef unsigned long wxLogLevel; | |
36 | ||
bc73d5ae VZ |
37 | /** |
38 | Information about a log record (unit of the log output). | |
39 | */ | |
af588446 | 40 | class wxLogRecordInfo |
bc73d5ae | 41 | { |
af588446 VZ |
42 | public: |
43 | /// The name of the file where this log message was generated. | |
44 | const char *filename; | |
45 | ||
46 | /// The line number at which this log message was generated. | |
47 | int line; | |
48 | ||
49 | /** | |
50 | The name of the function where the log record was generated. | |
51 | ||
52 | This field may be @NULL if the compiler doesn't support @c __FUNCTION__ | |
53 | (but most modern compilers do). | |
54 | */ | |
55 | const char *func; | |
56 | ||
bc73d5ae VZ |
57 | /// Time when the log message was generated. |
58 | time_t timestamp; | |
59 | ||
60 | /** | |
61 | Id of the thread in which the message was generated. | |
62 | ||
63 | This field is only available if wxWidgets was built with threads | |
64 | support (<code>wxUSE_THREADS == 1</code>). | |
65 | ||
66 | @see wxThread::GetCurrentId() | |
67 | */ | |
68 | wxThreadIdType threadId; | |
69 | }; | |
4a6665c6 | 70 | |
23324ae1 FM |
71 | /** |
72 | @class wxLogWindow | |
7c913512 | 73 | |
23324ae1 FM |
74 | This class represents a background log window: to be precise, it collects all |
75 | log messages in the log frame which it manages but also passes them on to the | |
3e6f95dc | 76 | log target which was active at the moment of its creation. This allows you, for |
23324ae1 FM |
77 | example, to show all the log messages in a frame but still continue to process |
78 | them normally by showing the standard log dialog. | |
7c913512 | 79 | |
23324ae1 FM |
80 | @library{wxbase} |
81 | @category{logging} | |
7c913512 | 82 | |
e54c96f1 | 83 | @see wxLogTextCtrl |
23324ae1 FM |
84 | */ |
85 | class wxLogWindow : public wxLogInterposer | |
86 | { | |
87 | public: | |
88 | /** | |
89 | Creates the log frame window and starts collecting the messages in it. | |
3c4f71cc | 90 | |
f21dd16b | 91 | @param pParent |
4cc4bfaf | 92 | The parent window for the log frame, may be @NULL |
f21dd16b | 93 | @param szTitle |
4cc4bfaf | 94 | The title for the log frame |
7c913512 | 95 | @param show |
4cc4bfaf FM |
96 | @true to show the frame initially (default), otherwise |
97 | Show() must be called later. | |
7c913512 | 98 | @param passToOld |
4cc4bfaf FM |
99 | @true to process the log messages normally in addition to |
100 | logging them in the log frame (default), @false to only log them in the | |
101 | log frame. | |
23324ae1 | 102 | */ |
fadc2df6 | 103 | wxLogWindow(wxWindow* pParent, const wxString& szTitle, bool show = true, |
4cc4bfaf | 104 | bool passToOld = true); |
23324ae1 FM |
105 | |
106 | /** | |
107 | Returns the associated log frame window. This may be used to position or resize | |
108 | it but use Show() to show or hide it. | |
109 | */ | |
328f5751 | 110 | wxFrame* GetFrame() const; |
23324ae1 FM |
111 | |
112 | /** | |
113 | Called if the user closes the window interactively, will not be | |
114 | called if it is destroyed for another reason (such as when program | |
115 | exits). | |
6a93e794 | 116 | |
23324ae1 FM |
117 | Return @true from here to allow the frame to close, @false to |
118 | prevent this from happening. | |
3c4f71cc | 119 | |
4cc4bfaf | 120 | @see OnFrameDelete() |
23324ae1 | 121 | */ |
43c48e1e | 122 | virtual bool OnFrameClose(wxFrame* frame); |
23324ae1 FM |
123 | |
124 | /** | |
125 | Called immediately after the log frame creation allowing for | |
126 | any extra initializations. | |
127 | */ | |
43c48e1e | 128 | virtual void OnFrameCreate(wxFrame* frame); |
23324ae1 FM |
129 | |
130 | /** | |
131 | Called right before the log frame is going to be deleted: will | |
132 | always be called unlike OnFrameClose(). | |
133 | */ | |
43c48e1e | 134 | virtual void OnFrameDelete(wxFrame* frame); |
23324ae1 FM |
135 | |
136 | /** | |
137 | Shows or hides the frame. | |
138 | */ | |
4cc4bfaf | 139 | void Show(bool show = true); |
23324ae1 FM |
140 | }; |
141 | ||
142 | ||
e54c96f1 | 143 | |
23324ae1 FM |
144 | /** |
145 | @class wxLogInterposerTemp | |
7c913512 | 146 | |
6a93e794 FM |
147 | A special version of wxLogChain which uses itself as the new log target. |
148 | It forwards log messages to the previously installed one in addition to | |
149 | processing them itself. Unlike wxLogInterposer, it doesn't delete the old | |
150 | target which means it can be used to temporarily redirect log output. | |
7c913512 | 151 | |
23324ae1 | 152 | As per wxLogInterposer, this class must be derived from to implement |
6a93e794 | 153 | wxLog::DoLog and/or wxLog::DoLogString methods. |
7c913512 | 154 | |
23324ae1 FM |
155 | @library{wxbase} |
156 | @category{logging} | |
157 | */ | |
158 | class wxLogInterposerTemp : public wxLogChain | |
159 | { | |
160 | public: | |
161 | /** | |
162 | The default constructor installs this object as the current active log target. | |
163 | */ | |
6a93e794 | 164 | wxLogInterposerTemp(); |
23324ae1 FM |
165 | }; |
166 | ||
167 | ||
e54c96f1 | 168 | |
23324ae1 FM |
169 | /** |
170 | @class wxLogChain | |
7c913512 | 171 | |
3e6f95dc | 172 | This simple class allows you to chain log sinks, that is to install a new sink but |
23324ae1 FM |
173 | keep passing log messages to the old one instead of replacing it completely as |
174 | wxLog::SetActiveTarget does. | |
7c913512 | 175 | |
23324ae1 FM |
176 | It is especially useful when you want to divert the logs somewhere (for |
177 | example to a file or a log window) but also keep showing the error messages | |
178 | using the standard dialogs as wxLogGui does by default. | |
7c913512 | 179 | |
23324ae1 | 180 | Example of usage: |
7c913512 | 181 | |
23324ae1 FM |
182 | @code |
183 | wxLogChain *logChain = new wxLogChain(new wxLogStderr); | |
7c913512 | 184 | |
23324ae1 FM |
185 | // all the log messages are sent to stderr and also processed as usually |
186 | ... | |
7c913512 | 187 | |
23324ae1 FM |
188 | // don't delete logChain directly as this would leave a dangling |
189 | // pointer as active log target, use SetActiveTarget() instead | |
6bfc18d0 | 190 | delete wxLog::SetActiveTarget(...something else or NULL...); |
23324ae1 | 191 | @endcode |
7c913512 | 192 | |
23324ae1 FM |
193 | @library{wxbase} |
194 | @category{logging} | |
195 | */ | |
196 | class wxLogChain : public wxLog | |
197 | { | |
198 | public: | |
199 | /** | |
200 | Sets the specified @c logger (which may be @NULL) as the default log | |
201 | target but the log messages are also passed to the previous log target if any. | |
202 | */ | |
4cc4bfaf | 203 | wxLogChain(wxLog* logger); |
23324ae1 FM |
204 | |
205 | /** | |
206 | Destroys the previous log target. | |
207 | */ | |
adaaa686 | 208 | virtual ~wxLogChain(); |
23324ae1 FM |
209 | |
210 | /** | |
211 | Detaches the old log target so it won't be destroyed when the wxLogChain object | |
212 | is destroyed. | |
213 | */ | |
214 | void DetachOldLog(); | |
215 | ||
216 | /** | |
217 | Returns the pointer to the previously active log target (which may be @NULL). | |
218 | */ | |
328f5751 | 219 | wxLog* GetOldLog() const; |
23324ae1 FM |
220 | |
221 | /** | |
222 | Returns @true if the messages are passed to the previously active log | |
6a93e794 | 223 | target (default) or @false if PassMessages() had been called. |
23324ae1 | 224 | */ |
328f5751 | 225 | bool IsPassingMessages() const; |
23324ae1 FM |
226 | |
227 | /** | |
228 | By default, the log messages are passed to the previously active log target. | |
229 | Calling this function with @false parameter disables this behaviour | |
230 | (presumably temporarily, as you shouldn't use wxLogChain at all otherwise) and | |
4cc4bfaf | 231 | it can be reenabled by calling it again with @a passMessages set to @true. |
23324ae1 FM |
232 | */ |
233 | void PassMessages(bool passMessages); | |
234 | ||
235 | /** | |
6a93e794 FM |
236 | Sets another log target to use (may be @NULL). |
237 | ||
238 | The log target specified in the wxLogChain(wxLog*) constructor or in a | |
239 | previous call to this function is deleted. | |
23324ae1 FM |
240 | This doesn't change the old log target value (the one the messages are |
241 | forwarded to) which still remains the same as was active when wxLogChain | |
242 | object was created. | |
243 | */ | |
4cc4bfaf | 244 | void SetLog(wxLog* logger); |
23324ae1 FM |
245 | }; |
246 | ||
247 | ||
e54c96f1 | 248 | |
23324ae1 FM |
249 | /** |
250 | @class wxLogGui | |
7c913512 | 251 | |
5d815500 VZ |
252 | This is the default log target for the GUI wxWidgets applications. |
253 | ||
254 | Please see @ref overview_log_customize for explanation of how to change the | |
255 | default log target. | |
256 | ||
257 | An object of this class is used by default to show the log messages created | |
258 | by using wxLogMessage(), wxLogError() and other logging functions. It | |
259 | doesn't display the messages logged by them immediately however but | |
260 | accumulates all messages logged during an event handler execution and then | |
261 | shows them all at once when its Flush() method is called during the idle | |
262 | time processing. This has the important advantage of showing only a single | |
263 | dialog to the user even if several messages were logged because of a single | |
264 | error as it often happens (e.g. a low level function could log a message | |
265 | because it failed to open a file resulting in its caller logging another | |
266 | message due to the failure of higher level operation requiring the use of | |
267 | this file). If you need to force the display of all previously logged | |
268 | messages immediately you can use wxLog::FlushActive() to force the dialog | |
269 | display. | |
270 | ||
271 | Also notice that if an error message is logged when several informative | |
272 | messages had been already logged before, the informative messages are | |
273 | discarded on the assumption that they are not useful -- and may be | |
274 | confusing and hence harmful -- any more after the error. The warning | |
275 | and error messages are never discarded however and any informational | |
276 | messages logged after the first error one are also kept (as they may | |
277 | contain information about the error recovery). You may override DoLog() | |
278 | method to change this behaviour. | |
279 | ||
280 | At any rate, it is possible that that several messages were accumulated | |
281 | before this class Flush() method is called. If this is the case, Flush() | |
282 | uses a custom dialog which shows the last message directly and allows the | |
283 | user to view the previously logged ones by expanding the "Details" | |
284 | wxCollapsiblePane inside it. This custom dialog also provides the buttons | |
285 | for copying the log messages to the clipboard and saving them to a file. | |
286 | ||
287 | However if only a single message is present when Flush() is called, just a | |
288 | wxMessageBox() is used to show it. This has the advantage of being closer | |
289 | to the native behaviour but it doesn't give the user any possibility to | |
290 | copy or save the message (except for the recent Windows versions where @c | |
291 | Ctrl-C may be pressed in the message box to copy its contents to the | |
292 | clipboard) so you may want to override DoShowSingleMessage() to customize | |
293 | wxLogGui -- the dialogs sample shows how to do this. | |
7c913512 | 294 | |
5d815500 | 295 | @library{wxcore} |
23324ae1 FM |
296 | @category{logging} |
297 | */ | |
298 | class wxLogGui : public wxLog | |
299 | { | |
300 | public: | |
301 | /** | |
302 | Default constructor. | |
303 | */ | |
304 | wxLogGui(); | |
5d815500 VZ |
305 | |
306 | /** | |
307 | Presents the accumulated log messages, if any, to the user. | |
308 | ||
309 | This method is called during the idle time and should show any messages | |
310 | accumulated in wxLogGui#m_aMessages field to the user. | |
311 | */ | |
312 | virtual void Flush(); | |
313 | ||
314 | protected: | |
315 | /** | |
316 | Returns the appropriate title for the dialog. | |
317 | ||
318 | The title is constructed from wxApp::GetAppDisplayName() and the | |
319 | severity string (e.g. "error" or "warning") appropriate for the current | |
320 | wxLogGui#m_bErrors and wxLogGui#m_bWarnings values. | |
321 | */ | |
322 | wxString GetTitle() const; | |
323 | ||
324 | /** | |
325 | Returns wxICON_ERROR, wxICON_WARNING or wxICON_INFORMATION depending on | |
326 | the current maximal severity. | |
327 | ||
328 | This value is suitable to be used in the style parameter of | |
329 | wxMessageBox() function. | |
330 | */ | |
331 | int GetSeverityIcon() const; | |
332 | ||
333 | /** | |
334 | Forgets all the currently stored messages. | |
335 | ||
336 | If you override Flush() (and don't call the base class version), you | |
337 | must call this method to avoid messages being logged over and over | |
338 | again. | |
339 | */ | |
340 | void Clear(); | |
341 | ||
342 | ||
343 | /** | |
344 | Method called by Flush() to show a single log message. | |
345 | ||
346 | This function can be overridden to show the message in a different way. | |
347 | By default a simple wxMessageBox() call is used. | |
348 | ||
349 | @param message | |
350 | The message to show (it can contain multiple lines). | |
351 | @param title | |
352 | The suggested title for the dialog showing the message, see | |
353 | GetTitle(). | |
354 | @param style | |
355 | One of @c wxICON_XXX constants, see GetSeverityIcon(). | |
356 | */ | |
357 | virtual void DoShowSingleLogMessage(const wxString& message, | |
358 | const wxString& title, | |
359 | int style); | |
360 | ||
361 | /** | |
362 | Method called by Flush() to show multiple log messages. | |
363 | ||
364 | This function can be overridden to show the messages in a different way. | |
365 | By default a special log dialog showing the most recent message and | |
366 | allowing the user to expand it to view the previously logged ones is | |
367 | used. | |
368 | ||
369 | @param messages | |
370 | Array of messages to show; it contains more than one element. | |
371 | @param severities | |
372 | Array of message severities containing @c wxLOG_XXX values. | |
373 | @param times | |
374 | Array of time_t values indicating when each message was logged. | |
375 | @param title | |
376 | The suggested title for the dialog showing the message, see | |
377 | GetTitle(). | |
378 | @param style | |
379 | One of @c wxICON_XXX constants, see GetSeverityIcon(). | |
380 | */ | |
381 | virtual void DoShowMultipleLogMessages(const wxArrayString& messages, | |
382 | const wxArrayInt& severities, | |
383 | const wxArrayLong& times, | |
384 | const wxString& title, | |
385 | int style); | |
386 | ||
387 | ||
388 | /** | |
389 | All currently accumulated messages. | |
390 | ||
391 | This array may be empty if no messages were logged. | |
392 | ||
393 | @see m_aSeverity, m_aTimes | |
394 | */ | |
395 | wxArrayString m_aMessages; | |
396 | ||
397 | /** | |
398 | The severities of each logged message. | |
399 | ||
400 | This array is synchronized with wxLogGui#m_aMessages, i.e. the n-th | |
401 | element of this array corresponds to the severity of the n-th message. | |
402 | The possible severity values are @c wxLOG_XXX constants, e.g. | |
403 | wxLOG_Error, wxLOG_Warning, wxLOG_Message etc. | |
404 | */ | |
405 | wxArrayInt m_aSeverity; | |
406 | ||
407 | /** | |
408 | The time stamps of each logged message. | |
409 | ||
410 | The elements of this array are time_t values corresponding to the time | |
411 | when the message was logged. | |
412 | */ | |
413 | wxArrayLong m_aTimes; | |
414 | ||
415 | /** | |
416 | True if there any error messages. | |
417 | */ | |
418 | bool m_bErrors; | |
419 | ||
420 | /** | |
421 | True if there any warning messages. | |
422 | ||
423 | If both wxLogGui#m_bErrors and this member are false, there are only | |
424 | informational messages to be shown. | |
425 | */ | |
426 | bool m_bWarnings; | |
427 | ||
428 | /** | |
429 | True if there any messages to be shown to the user. | |
430 | ||
431 | This variable is used instead of simply checking whether | |
432 | wxLogGui#m_aMessages array is empty to allow blocking further calls to | |
433 | Flush() while a log dialog is already being shown, even if the messages | |
434 | array hasn't been emptied yet. | |
435 | */ | |
436 | bool m_bHasMessages; | |
23324ae1 FM |
437 | }; |
438 | ||
439 | ||
e54c96f1 | 440 | |
23324ae1 FM |
441 | /** |
442 | @class wxLogStream | |
7c913512 | 443 | |
23324ae1 | 444 | This class can be used to redirect the log messages to a C++ stream. |
7c913512 | 445 | |
23324ae1 FM |
446 | Please note that this class is only available if wxWidgets was compiled with |
447 | the standard iostream library support (@c wxUSE_STD_IOSTREAM must be on). | |
7c913512 | 448 | |
23324ae1 FM |
449 | @library{wxbase} |
450 | @category{logging} | |
7c913512 | 451 | |
e54c96f1 | 452 | @see wxLogStderr, wxStreamToTextRedirector |
23324ae1 FM |
453 | */ |
454 | class wxLogStream : public wxLog | |
455 | { | |
456 | public: | |
457 | /** | |
458 | Constructs a log target which sends all the log messages to the given | |
459 | output stream. If it is @NULL, the messages are sent to @c cerr. | |
460 | */ | |
0a98423e | 461 | wxLogStream(std::ostream *ostr = NULL); |
23324ae1 FM |
462 | }; |
463 | ||
464 | ||
e54c96f1 | 465 | |
23324ae1 FM |
466 | /** |
467 | @class wxLogStderr | |
7c913512 | 468 | |
23324ae1 | 469 | This class can be used to redirect the log messages to a C file stream (not to |
a44f3b5a FM |
470 | be confused with C++ streams). |
471 | ||
472 | It is the default log target for the non-GUI wxWidgets applications which | |
473 | send all the output to @c stderr. | |
7c913512 | 474 | |
23324ae1 FM |
475 | @library{wxbase} |
476 | @category{logging} | |
7c913512 | 477 | |
e54c96f1 | 478 | @see wxLogStream |
23324ae1 FM |
479 | */ |
480 | class wxLogStderr : public wxLog | |
481 | { | |
482 | public: | |
483 | /** | |
484 | Constructs a log target which sends all the log messages to the given | |
485 | @c FILE. If it is @NULL, the messages are sent to @c stderr. | |
486 | */ | |
8067ee11 | 487 | wxLogStderr(FILE* fp = NULL); |
23324ae1 FM |
488 | }; |
489 | ||
490 | ||
e54c96f1 | 491 | |
23324ae1 FM |
492 | /** |
493 | @class wxLogBuffer | |
7c913512 | 494 | |
23324ae1 FM |
495 | wxLogBuffer is a very simple implementation of log sink which simply collects |
496 | all the logged messages in a string (except the debug messages which are output | |
497 | in the usual way immediately as we're presumably not interested in collecting | |
498 | them for later). The messages from different log function calls are separated | |
499 | by the new lines. | |
7c913512 | 500 | |
23324ae1 | 501 | All the messages collected so far can be shown to the user (and the current |
6a93e794 | 502 | buffer cleared) by calling the overloaded wxLogBuffer::Flush method. |
7c913512 | 503 | |
23324ae1 | 504 | @library{wxbase} |
3e6f95dc | 505 | @category{logging} |
23324ae1 FM |
506 | */ |
507 | class wxLogBuffer : public wxLog | |
508 | { | |
509 | public: | |
435c1bc4 FM |
510 | /** |
511 | The default ctor does nothing. | |
512 | */ | |
513 | wxLogBuffer(); | |
514 | ||
23324ae1 FM |
515 | /** |
516 | Shows all the messages collected so far to the user (using a message box in the | |
517 | GUI applications or by printing them out to the console in text mode) and | |
518 | clears the internal buffer. | |
519 | */ | |
520 | virtual void Flush(); | |
521 | ||
522 | /** | |
523 | Returns the current buffer contains. Messages from different log function calls | |
524 | are separated with the new lines in the buffer. | |
6a93e794 FM |
525 | The buffer can be cleared by Flush() which will also show the current |
526 | contents to the user. | |
23324ae1 | 527 | */ |
43c48e1e | 528 | const wxString& GetBuffer() const; |
23324ae1 FM |
529 | }; |
530 | ||
531 | ||
e54c96f1 | 532 | |
23324ae1 FM |
533 | /** |
534 | @class wxLogInterposer | |
7c913512 | 535 | |
6a93e794 FM |
536 | A special version of wxLogChain which uses itself as the new log target. |
537 | It forwards log messages to the previously installed one in addition to | |
23324ae1 | 538 | processing them itself. |
7c913512 | 539 | |
6a93e794 FM |
540 | Unlike wxLogChain which is usually used directly as is, this class must be |
541 | derived from to implement wxLog::DoLog and/or wxLog::DoLogString methods. | |
7c913512 | 542 | |
6a93e794 FM |
543 | wxLogInterposer destroys the previous log target in its destructor. |
544 | If you don't want this to happen, use wxLogInterposerTemp instead. | |
7c913512 | 545 | |
23324ae1 FM |
546 | @library{wxbase} |
547 | @category{logging} | |
548 | */ | |
549 | class wxLogInterposer : public wxLogChain | |
550 | { | |
551 | public: | |
552 | /** | |
553 | The default constructor installs this object as the current active log target. | |
554 | */ | |
6a93e794 | 555 | wxLogInterposer(); |
23324ae1 FM |
556 | }; |
557 | ||
558 | ||
e54c96f1 | 559 | |
23324ae1 FM |
560 | /** |
561 | @class wxLogTextCtrl | |
7c913512 | 562 | |
23324ae1 FM |
563 | Using these target all the log messages can be redirected to a text control. |
564 | The text control must have been created with @c wxTE_MULTILINE style by the | |
565 | caller previously. | |
7c913512 | 566 | |
23324ae1 FM |
567 | @library{wxbase} |
568 | @category{logging} | |
7c913512 | 569 | |
e54c96f1 | 570 | @see wxTextCtrl, wxStreamToTextRedirector |
23324ae1 FM |
571 | */ |
572 | class wxLogTextCtrl : public wxLog | |
573 | { | |
574 | public: | |
575 | /** | |
576 | Constructs a log target which sends all the log messages to the given text | |
4cc4bfaf | 577 | control. The @a textctrl parameter cannot be @NULL. |
23324ae1 | 578 | */ |
8067ee11 | 579 | wxLogTextCtrl(wxTextCtrl* pTextCtrl); |
23324ae1 FM |
580 | }; |
581 | ||
582 | ||
e54c96f1 | 583 | |
23324ae1 FM |
584 | /** |
585 | @class wxLog | |
7c913512 | 586 | |
23324ae1 | 587 | wxLog class defines the interface for the @e log targets used by wxWidgets |
3e6f95dc | 588 | logging functions as explained in the @ref overview_log. |
23324ae1 FM |
589 | The only situations when you need to directly use this class is when you want |
590 | to derive your own log target because the existing ones don't satisfy your | |
591 | needs. Another case is if you wish to customize the behaviour of the standard | |
592 | logging classes (all of which respect the wxLog settings): for example, set | |
593 | which trace messages are logged and which are not or change (or even remove | |
594 | completely) the timestamp on the messages. | |
7c913512 | 595 | |
23324ae1 FM |
596 | Otherwise, it is completely hidden behind the @e wxLogXXX() functions and |
597 | you may not even know about its existence. | |
7c913512 | 598 | |
a44f3b5a FM |
599 | @note For console-mode applications, the default target is wxLogStderr, so |
600 | that all @e wxLogXXX() functions print on @c stderr when @c wxUSE_GUI = 0. | |
601 | ||
6a93e794 FM |
602 | |
603 | @section log_derivingyours Deriving your own log target | |
604 | ||
af588446 VZ |
605 | There are several methods which may be overridden in the derived class to |
606 | customize log messages handling: DoLogRecord(), DoLogTextAtLevel() and | |
607 | DoLogText(). | |
608 | ||
609 | The last method is the simplest one: you should override it if you simply | |
610 | want to redirect the log output elsewhere, without taking into account the | |
611 | level of the message. If you do want to handle messages of different levels | |
612 | differently, then you should override DoLogTextAtLevel(). | |
6a93e794 | 613 | |
af588446 VZ |
614 | Finally, if more control over the output format is needed, then the first |
615 | function must be overridden as it allows to construct custom messages | |
616 | depending on the log level or even do completely different things depending | |
617 | on the message severity (for example, throw away all messages except | |
618 | warnings and errors, show warnings on the screen and forward the error | |
619 | messages to the user's (or programmer's) cell phone -- maybe depending on | |
620 | whether the timestamp tells us if it is day or night in the current time | |
621 | zone). | |
6a93e794 FM |
622 | |
623 | There also functions to support message buffering. Why are they needed? | |
624 | Some of wxLog implementations, most notably the standard wxLogGui class, | |
625 | buffer the messages (for example, to avoid showing the user a zillion of modal | |
626 | message boxes one after another -- which would be really annoying). | |
627 | ||
628 | Flush() shows them all and clears the buffer contents. | |
629 | This function doesn't do anything if the buffer is already empty. | |
630 | ||
af588446 | 631 | @see FlushActive() |
6a93e794 FM |
632 | |
633 | ||
634 | @section log_tracemasks Using trace masks | |
635 | ||
636 | The functions below allow some limited customization of wxLog behaviour | |
637 | without writing a new log target class (which, aside from being a matter of | |
638 | several minutes, allows you to do anything you want). | |
639 | The verbose messages are the trace messages which are not disabled in the | |
640 | release mode and are generated by wxLogVerbose(). | |
641 | They are not normally shown to the user because they present little interest, | |
642 | but may be activated, for example, in order to help the user find some program | |
643 | problem. | |
644 | ||
34085a0d VZ |
645 | As for the (real) trace messages, their handling depends on the currently |
646 | enabled trace masks: if AddTraceMask() was called for the mask of the given | |
647 | message, it will be logged, otherwise nothing happens. | |
6a93e794 | 648 | |
6a93e794 | 649 | For example, |
6a93e794 FM |
650 | @code |
651 | wxLogTrace( wxTRACE_OleCalls, "IFoo::Bar() called" ); | |
652 | @endcode | |
653 | ||
654 | will log the message if it was preceded by: | |
655 | ||
656 | @code | |
657 | wxLog::AddTraceMask( wxTRACE_OleCalls); | |
658 | @endcode | |
659 | ||
6a93e794 FM |
660 | The standard trace masks are given in wxLogTrace() documentation. |
661 | ||
662 | Finally, the @e wxLog::DoLog() function automatically prepends a time stamp | |
663 | to all the messages. The format of the time stamp may be changed: it can be | |
664 | any string with % specifications fully described in the documentation of the | |
665 | standard @e strftime() function. For example, the default format is | |
666 | "[%d/%b/%y %H:%M:%S] " which gives something like "[17/Sep/98 22:10:16] " | |
667 | (without quotes) for the current date. Setting an empty string as the time | |
bce9df55 FM |
668 | format or calling the shortcut wxLog::DisableTimestamp(), disables timestamping |
669 | of the messages completely. | |
6a93e794 FM |
670 | |
671 | See also | |
672 | @li AddTraceMask() | |
673 | @li RemoveTraceMask() | |
674 | @li ClearTraceMasks() | |
675 | @li GetTraceMasks() | |
676 | @li IsAllowedTraceMask() | |
677 | @li SetVerbose() | |
678 | @li GetVerbose() | |
679 | @li SetTimestamp() | |
680 | @li GetTimestamp() | |
681 | @li SetTraceMask() | |
682 | @li GetTraceMask() | |
683 | @li SetRepetitionCounting() | |
684 | @li GetRepetitionCounting() | |
685 | ||
a44f3b5a FM |
686 | @note |
687 | Timestamping is disabled for Visual C++ users in debug builds by | |
6a93e794 FM |
688 | default because otherwise it would be impossible to directly go to the line |
689 | from which the log message was generated by simply clicking in the debugger | |
690 | window on the corresponding error message. If you wish to enable it, please | |
691 | use SetTimestamp() explicitly. | |
692 | ||
693 | ||
694 | @section log_target Manipulating the log target | |
695 | ||
696 | The functions in this section work with and manipulate the active log | |
bc73d5ae | 697 | target. |
6a93e794 FM |
698 | |
699 | Get/Set methods are used to install/query the current active target and, | |
700 | finally, DontCreateOnDemand() disables the automatic creation of a standard | |
701 | log target if none actually exists. It is only useful when the application | |
702 | is terminating and shouldn't be used in other situations because it may | |
703 | easily lead to a loss of messages. | |
704 | ||
705 | See also: | |
6a93e794 FM |
706 | @li GetActiveTarget() |
707 | @li SetActiveTarget() | |
708 | @li DontCreateOnDemand() | |
709 | @li Suspend() | |
710 | @li Resume() | |
711 | ||
3c4f71cc | 712 | |
5bc128d6 RR |
713 | @library{wxcore} |
714 | @category{logging} | |
3c4f71cc | 715 | |
3e6f95dc | 716 | @see @ref overview_log |
5bc128d6 RR |
717 | */ |
718 | class wxLog | |
719 | { | |
720 | public: | |
721 | /** | |
6a93e794 | 722 | Add the @a mask to the list of allowed masks for wxLogTrace(). |
3c4f71cc | 723 | |
5bc128d6 RR |
724 | @see RemoveTraceMask(), GetTraceMasks() |
725 | */ | |
726 | static void AddTraceMask(const wxString& mask); | |
3c4f71cc | 727 | |
5bc128d6 | 728 | /** |
6a93e794 | 729 | Removes all trace masks previously set with AddTraceMask(). |
3c4f71cc | 730 | |
5bc128d6 RR |
731 | @see RemoveTraceMask() |
732 | */ | |
733 | static void ClearTraceMasks(); | |
3c4f71cc | 734 | |
23324ae1 FM |
735 | /** |
736 | Instructs wxLog to not create new log targets on the fly if there is none | |
737 | currently. (Almost) for internal use only: it is supposed to be called by the | |
738 | application shutdown code. | |
6a93e794 FM |
739 | |
740 | Note that this function also calls ClearTraceMasks(). | |
23324ae1 FM |
741 | */ |
742 | static void DontCreateOnDemand(); | |
743 | ||
ba3af101 VZ |
744 | /** |
745 | Globally enable or disable logging. | |
746 | ||
53ff8df7 VZ |
747 | Calling this function with @false argument disables all log messages |
748 | for the current thread. | |
ba3af101 VZ |
749 | |
750 | @see wxLogNull, IsEnabled() | |
751 | ||
752 | @return | |
753 | The old state, i.e. @true if logging was previously enabled and | |
754 | @false if it was disabled. | |
755 | */ | |
756 | static bool EnableLogging(bool enable = true); | |
757 | ||
23324ae1 | 758 | /** |
6a93e794 | 759 | Shows all the messages currently in buffer and clears it. |
232addd1 | 760 | |
6a93e794 | 761 | If the buffer is already empty, nothing happens. |
232addd1 | 762 | |
232addd1 | 763 | If you override this method in a derived class, call the base class |
acad886c | 764 | version first, before doing anything else. |
23324ae1 FM |
765 | */ |
766 | virtual void Flush(); | |
767 | ||
768 | /** | |
769 | Flushes the current log target if any, does nothing if there is none. | |
3c4f71cc | 770 | |
acad886c VZ |
771 | When this method is called from the main thread context, it also |
772 | flushes any previously buffered messages logged by the other threads. | |
773 | When it is called from the other threads it simply calls Flush() on the | |
774 | currently active log target, so it mostly makes sense to do this if a | |
775 | thread has its own logger set with SetThreadActiveTarget(). | |
23324ae1 FM |
776 | */ |
777 | static void FlushActive(); | |
778 | ||
779 | /** | |
780 | Returns the pointer to the active log target (may be @NULL). | |
acad886c VZ |
781 | |
782 | Notice that if SetActiveTarget() hadn't been previously explicitly | |
783 | called, this function will by default try to create a log target by | |
784 | calling wxAppTraits::CreateLogTarget() which may be overridden in a | |
785 | user-defined traits class to change the default behaviour. You may also | |
786 | call DontCreateOnDemand() to disable this behaviour. | |
787 | ||
788 | When this function is called from threads other than main one, | |
789 | auto-creation doesn't happen. But if the thread has a thread-specific | |
790 | log target previously set by SetThreadActiveTarget(), it is returned | |
791 | instead of the global one. Otherwise, the global log target is | |
792 | returned. | |
23324ae1 | 793 | */ |
4cc4bfaf | 794 | static wxLog* GetActiveTarget(); |
23324ae1 FM |
795 | |
796 | /** | |
797 | Returns the current log level limit. | |
ba3af101 VZ |
798 | |
799 | All messages at levels strictly greater than the value returned by this | |
800 | function are not logged at all. | |
801 | ||
802 | @see SetLogLevel(), IsLevelEnabled() | |
23324ae1 FM |
803 | */ |
804 | static wxLogLevel GetLogLevel(); | |
805 | ||
806 | /** | |
807 | Returns whether the repetition counting mode is enabled. | |
808 | */ | |
809 | static bool GetRepetitionCounting(); | |
810 | ||
811 | /** | |
812 | Returns the current timestamp format string. | |
813 | */ | |
382f12e4 | 814 | static const wxString& GetTimestamp(); |
23324ae1 FM |
815 | |
816 | /** | |
34085a0d | 817 | @deprecated |
6a93e794 | 818 | Returns the current trace mask, see Customization() section for details. |
23324ae1 FM |
819 | */ |
820 | static wxTraceMask GetTraceMask(); | |
821 | ||
822 | /** | |
823 | Returns the currently allowed list of string trace masks. | |
3c4f71cc | 824 | |
4cc4bfaf | 825 | @see AddTraceMask(). |
23324ae1 | 826 | */ |
382f12e4 | 827 | static const wxArrayString& GetTraceMasks(); |
23324ae1 FM |
828 | |
829 | /** | |
830 | Returns whether the verbose mode is currently active. | |
831 | */ | |
832 | static bool GetVerbose(); | |
833 | ||
23324ae1 | 834 | /** |
6a93e794 | 835 | Returns @true if the @a mask is one of allowed masks for wxLogTrace(). |
8067ee11 | 836 | |
5bc128d6 | 837 | See also: AddTraceMask(), RemoveTraceMask() |
23324ae1 FM |
838 | */ |
839 | static bool IsAllowedTraceMask(const wxString& mask); | |
840 | ||
ba3af101 VZ |
841 | /** |
842 | Returns true if logging is enabled at all now. | |
843 | ||
844 | @see IsLevelEnabled(), EnableLogging() | |
845 | */ | |
846 | static bool IsEnabled(); | |
847 | ||
848 | /** | |
53ff8df7 | 849 | Returns true if logging at this level is enabled for the current thread. |
ba3af101 VZ |
850 | |
851 | This function only returns @true if logging is globally enabled and if | |
c602c59b VZ |
852 | @a level is less than or equal to the maximal log level enabled for the |
853 | given @a component. | |
ba3af101 | 854 | |
c602c59b VZ |
855 | @see IsEnabled(), SetLogLevel(), GetLogLevel(), SetComponentLevel() |
856 | ||
857 | @since 2.9.1 | |
ba3af101 | 858 | */ |
c602c59b | 859 | static bool IsLevelEnabled(wxLogLevel level, wxString component); |
ba3af101 | 860 | |
23324ae1 | 861 | /** |
4cc4bfaf | 862 | Remove the @a mask from the list of allowed masks for |
e54c96f1 | 863 | wxLogTrace(). |
6a93e794 FM |
864 | |
865 | @see AddTraceMask() | |
23324ae1 FM |
866 | */ |
867 | static void RemoveTraceMask(const wxString& mask); | |
868 | ||
869 | /** | |
5d815500 VZ |
870 | Resumes logging previously suspended by a call to Suspend(). |
871 | All messages logged in the meanwhile will be flushed soon. | |
23324ae1 FM |
872 | */ |
873 | static void Resume(); | |
874 | ||
875 | /** | |
5d815500 VZ |
876 | Sets the specified log target as the active one. |
877 | ||
878 | Returns the pointer to the previous active log target (may be @NULL). | |
879 | To suppress logging use a new instance of wxLogNull not @NULL. If the | |
880 | active log target is set to @NULL a new default log target will be | |
881 | created when logging occurs. | |
acad886c VZ |
882 | |
883 | @see SetThreadActiveTarget() | |
23324ae1 | 884 | */ |
4cc4bfaf | 885 | static wxLog* SetActiveTarget(wxLog* logtarget); |
23324ae1 | 886 | |
c602c59b VZ |
887 | /** |
888 | Sets the log level for the given component. | |
889 | ||
890 | For example, to disable all but error messages from wxWidgets network | |
891 | classes you may use | |
892 | @code | |
893 | wxLog::SetComponentLevel("wx/net", wxLOG_Error); | |
894 | @endcode | |
895 | ||
896 | SetLogLevel() may be used to set the global log level. | |
897 | ||
898 | @param component | |
899 | Non-empty component name, possibly using slashes (@c /) to separate | |
900 | it into several parts. | |
901 | @param level | |
902 | Maximal level of log messages from this component which will be | |
903 | handled instead of being simply discarded. | |
904 | ||
905 | @since 2.9.1 | |
906 | */ | |
907 | static void SetComponentLevel(const wxString& component, wxLogLevel level); | |
908 | ||
23324ae1 | 909 | /** |
4a6665c6 FM |
910 | Specifies that log messages with level greater (numerically) than |
911 | @a logLevel should be ignored and not sent to the active log target. | |
c602c59b VZ |
912 | |
913 | @see SetComponentLevel() | |
23324ae1 FM |
914 | */ |
915 | static void SetLogLevel(wxLogLevel logLevel); | |
916 | ||
917 | /** | |
918 | Enables logging mode in which a log message is logged once, and in case exactly | |
7c913512 | 919 | the same message successively repeats one or more times, only the number of |
23324ae1 FM |
920 | repetitions is logged. |
921 | */ | |
4cc4bfaf | 922 | static void SetRepetitionCounting(bool repetCounting = true); |
23324ae1 | 923 | |
acad886c VZ |
924 | /** |
925 | Sets a thread-specific log target. | |
926 | ||
927 | The log target passed to this function will be used for all messages | |
928 | logged by the current thread using the usual wxLog functions. This | |
929 | shouldn't be called from the main thread which never uses a thread- | |
930 | specific log target but can be used for the other threads to handle | |
931 | thread logging completely separately; instead of buffering thread log | |
932 | messages in the main thread logger. | |
933 | ||
934 | Notice that unlike for SetActiveTarget(), wxWidgets does not destroy | |
935 | the thread-specific log targets when the thread terminates so doing | |
936 | this is your responsibility. | |
937 | ||
938 | This method is only available if @c wxUSE_THREADS is 1, i.e. wxWidgets | |
939 | was compiled with threads support. | |
940 | ||
941 | @param logger | |
942 | The new thread-specific log target, possibly @NULL. | |
943 | @return | |
944 | The previous thread-specific log target, initially @NULL. | |
945 | ||
946 | @since 2.9.1 | |
947 | */ | |
948 | static wxLog *SetThreadActiveTarget(wxLog *logger); | |
949 | ||
23324ae1 FM |
950 | /** |
951 | Sets the timestamp format prepended by the default log targets to all | |
952 | messages. The string may contain any normal characters as well as % | |
953 | prefixed format specificators, see @e strftime() manual for details. | |
954 | Passing an empty string to this function disables message time stamping. | |
955 | */ | |
956 | static void SetTimestamp(const wxString& format); | |
957 | ||
bce9df55 FM |
958 | /** |
959 | Disables time stamping of the log messages. | |
960 | ||
961 | @since 2.9.0 | |
962 | */ | |
963 | static void DisableTimestamp(); | |
964 | ||
23324ae1 | 965 | /** |
34085a0d VZ |
966 | @deprecated |
967 | Sets the trace mask, see @ref log_tracemasks section for details. | |
23324ae1 FM |
968 | */ |
969 | static void SetTraceMask(wxTraceMask mask); | |
970 | ||
971 | /** | |
972 | Activates or deactivates verbose mode in which the verbose messages are | |
973 | logged as the normal ones instead of being silently dropped. | |
974 | */ | |
4cc4bfaf | 975 | static void SetVerbose(bool verbose = true); |
23324ae1 FM |
976 | |
977 | /** | |
6a93e794 FM |
978 | Suspends the logging until Resume() is called. |
979 | ||
980 | Note that the latter must be called the same number of times as the former | |
981 | to undo it, i.e. if you call Suspend() twice you must call Resume() twice as well. | |
982 | ||
23324ae1 FM |
983 | Note that suspending the logging means that the log sink won't be be flushed |
984 | periodically, it doesn't have any effect if the current log target does the | |
6a93e794 FM |
985 | logging immediately without waiting for Flush() to be called (the standard |
986 | GUI log target only shows the log dialog when it is flushed, so Suspend() | |
987 | works as expected with it). | |
3c4f71cc | 988 | |
4cc4bfaf | 989 | @see Resume(), wxLogNull |
23324ae1 FM |
990 | */ |
991 | static void Suspend(); | |
5e6e278d | 992 | |
efce878a | 993 | /** |
bc73d5ae | 994 | Log the given record. |
efce878a VZ |
995 | |
996 | This function should only be called from the DoLog() implementations in | |
bc73d5ae VZ |
997 | the derived classes if they need to call DoLogRecord() on another log |
998 | object (they can, of course, just use wxLog::DoLogRecord() call syntax | |
999 | to call it on the object itself). It should not be used for logging new | |
1000 | messages which can be only sent to the currently active logger using | |
1001 | OnLog() which also checks if the logging (for this level) is enabled | |
1002 | while this method just directly calls DoLog(). | |
efce878a VZ |
1003 | |
1004 | Example of use of this class from wxLogChain: | |
1005 | @code | |
bc73d5ae VZ |
1006 | void wxLogChain::DoLogRecord(wxLogLevel level, |
1007 | const wxString& msg, | |
1008 | const wxLogRecordInfo& info) | |
efce878a VZ |
1009 | { |
1010 | // let the previous logger show it | |
1011 | if ( m_logOld && IsPassingMessages() ) | |
bc73d5ae | 1012 | m_logOld->LogRecord(level, msg, info); |
efce878a VZ |
1013 | |
1014 | // and also send it to the new one | |
1015 | if ( m_logNew && m_logNew != this ) | |
bc73d5ae | 1016 | m_logNew->LogRecord(level, msg, info); |
efce878a VZ |
1017 | } |
1018 | @endcode | |
1019 | ||
bc73d5ae | 1020 | @since 2.9.1 |
efce878a | 1021 | */ |
bc73d5ae | 1022 | void LogRecord(wxLogLevel level, const wxString& msg, time_t timestamp); |
efce878a | 1023 | |
5e6e278d | 1024 | protected: |
bc73d5ae VZ |
1025 | /** |
1026 | @name Logging callbacks. | |
1027 | ||
1028 | The functions which should be overridden by custom log targets. | |
1029 | ||
1030 | When defining a new log target, you have a choice between overriding | |
1031 | DoLogRecord(), which provides maximal flexibility, DoLogTextAtLevel() | |
1032 | which can be used if you don't intend to change the default log | |
1033 | messages formatting but want to handle log messages of different levels | |
1034 | differently or, in the simplest case, DoLogText(). | |
1035 | */ | |
1036 | //@{ | |
5e6e278d FM |
1037 | |
1038 | /** | |
bc73d5ae VZ |
1039 | Called to created log a new record. |
1040 | ||
1041 | Any log message created by wxLogXXX() functions is passed to this | |
1042 | method of the active log target. The default implementation prepends | |
1043 | the timestamp and, for some log levels (e.g. error and warning), the | |
1044 | corresponding prefix to @a msg and passes it to DoLogTextAtLevel(). | |
5e6e278d | 1045 | |
bc73d5ae VZ |
1046 | You may override this method to implement custom formatting of the |
1047 | log messages or to implement custom filtering of log messages (e.g. you | |
1048 | could discard all log messages coming from the given source file). | |
1049 | */ | |
1050 | virtual void DoLogRecord(wxLogLevel level, | |
1051 | const wxString& msg, | |
1052 | const wxLogRecordInfo& info); | |
1053 | ||
1054 | /** | |
1055 | Called to log the specified string at given level. | |
1056 | ||
1057 | The base class versions logs debug and trace messages on the system | |
1058 | default debug output channel and passes all the other messages to | |
1059 | DoLogText(). | |
5e6e278d | 1060 | */ |
bc73d5ae | 1061 | virtual void DoLogTextAtLevel(wxLogLevel level, const wxString& msg); |
5e6e278d FM |
1062 | |
1063 | /** | |
bc73d5ae | 1064 | Called to log the specified string. |
5e6e278d | 1065 | |
bc73d5ae VZ |
1066 | A simple implementation might just send the string to @c stdout or |
1067 | @c stderr or save it in a file (of course, the already existing | |
1068 | wxLogStderr can be used for this). | |
1069 | ||
1070 | The base class version of this function asserts so it must be | |
1071 | overridden if you don't override DoLogRecord() or DoLogTextAtLevel(). | |
5e6e278d | 1072 | */ |
bc73d5ae VZ |
1073 | virtual void DoLogText(const wxString& msg); |
1074 | ||
1075 | //@} | |
23324ae1 FM |
1076 | }; |
1077 | ||
1078 | ||
e54c96f1 | 1079 | |
23324ae1 FM |
1080 | /** |
1081 | @class wxLogNull | |
7c913512 | 1082 | |
3e6f95dc | 1083 | This class allows you to temporarily suspend logging. All calls to the log |
23324ae1 | 1084 | functions during the life time of an object of this class are just ignored. |
7c913512 | 1085 | |
23324ae1 FM |
1086 | In particular, it can be used to suppress the log messages given by wxWidgets |
1087 | itself but it should be noted that it is rarely the best way to cope with this | |
1088 | problem as @b all log messages are suppressed, even if they indicate a | |
1089 | completely different error than the one the programmer wanted to suppress. | |
7c913512 | 1090 | |
23324ae1 | 1091 | For instance, the example of the overview: |
7c913512 | 1092 | |
23324ae1 | 1093 | @code |
6a93e794 | 1094 | wxFile file; |
7c913512 | 1095 | |
23324ae1 FM |
1096 | // wxFile.Open() normally complains if file can't be opened, we don't want it |
1097 | { | |
1098 | wxLogNull logNo; | |
1099 | if ( !file.Open("bar") ) | |
1100 | ... process error ourselves ... | |
1101 | } // ~wxLogNull called, old log sink restored | |
7c913512 | 1102 | |
23324ae1 FM |
1103 | wxLogMessage("..."); // ok |
1104 | @endcode | |
7c913512 | 1105 | |
23324ae1 | 1106 | would be better written as: |
7c913512 | 1107 | |
23324ae1 | 1108 | @code |
6a93e794 | 1109 | wxFile file; |
7c913512 | 1110 | |
23324ae1 FM |
1111 | // don't try to open file if it doesn't exist, we are prepared to deal with |
1112 | // this ourselves - but all other errors are not expected | |
1113 | if ( wxFile::Exists("bar") ) | |
1114 | { | |
1115 | // gives an error message if the file couldn't be opened | |
1116 | file.Open("bar"); | |
1117 | } | |
1118 | else | |
1119 | { | |
1120 | ... | |
1121 | } | |
1122 | @endcode | |
7c913512 FM |
1123 | |
1124 | ||
23324ae1 FM |
1125 | @library{wxbase} |
1126 | @category{logging} | |
1127 | */ | |
6a9994cf | 1128 | class wxLogNull |
23324ae1 FM |
1129 | { |
1130 | public: | |
1131 | /** | |
1132 | Suspends logging. | |
1133 | */ | |
1134 | wxLogNull(); | |
1135 | ||
1136 | /** | |
1137 | Resumes logging. | |
1138 | */ | |
6a93e794 | 1139 | ~wxLogNull(); |
23324ae1 FM |
1140 | }; |
1141 | ||
1142 | ||
e54c96f1 | 1143 | |
23324ae1 FM |
1144 | // ============================================================================ |
1145 | // Global functions/macros | |
1146 | // ============================================================================ | |
1147 | ||
b21126db | 1148 | /** @addtogroup group_funcmacro_log */ |
ef477678 BP |
1149 | //@{ |
1150 | ||
23324ae1 | 1151 | /** |
ef477678 BP |
1152 | This function shows a message to the user in a safe way and should be safe |
1153 | to call even before the application has been initialized or if it is | |
1154 | currently in some other strange state (for example, about to crash). Under | |
1155 | Windows this function shows a message box using a native dialog instead of | |
1156 | wxMessageBox() (which might be unsafe to call), elsewhere it simply prints | |
1157 | the message to the standard output using the title as prefix. | |
7c913512 FM |
1158 | |
1159 | @param title | |
ef477678 BP |
1160 | The title of the message box shown to the user or the prefix of the |
1161 | message string. | |
7c913512 | 1162 | @param text |
ef477678 | 1163 | The text to show to the user. |
7c913512 | 1164 | |
e54c96f1 | 1165 | @see wxLogFatalError() |
ef477678 BP |
1166 | |
1167 | @header{wx/log.h} | |
23324ae1 | 1168 | */ |
ef477678 BP |
1169 | void wxSafeShowMessage(const wxString& title, const wxString& text); |
1170 | ||
1171 | /** | |
1172 | Returns the error code from the last system call. This function uses | |
1173 | @c errno on Unix platforms and @c GetLastError under Win32. | |
23324ae1 | 1174 | |
ef477678 | 1175 | @see wxSysErrorMsg(), wxLogSysError() |
96d7cc9b | 1176 | |
ef477678 BP |
1177 | @header{wx/log.h} |
1178 | */ | |
1179 | unsigned long wxSysErrorCode(); | |
96d7cc9b | 1180 | |
ef477678 BP |
1181 | /** |
1182 | Returns the error message corresponding to the given system error code. If | |
1183 | @a errCode is 0 (default), the last error code (as returned by | |
1184 | wxSysErrorCode()) is used. | |
1185 | ||
1186 | @see wxSysErrorCode(), wxLogSysError() | |
1187 | ||
1188 | @header{wx/log.h} | |
1189 | */ | |
1190 | const wxChar* wxSysErrorMsg(unsigned long errCode = 0); | |
1191 | ||
1192 | //@} | |
1193 | ||
b21126db | 1194 | /** @addtogroup group_funcmacro_log */ |
96d7cc9b FM |
1195 | //@{ |
1196 | /** | |
ef477678 BP |
1197 | For all normal, informational messages. They also appear in a message box |
1198 | by default (but it can be changed). | |
1199 | ||
1200 | @header{wx/log.h} | |
96d7cc9b FM |
1201 | */ |
1202 | void wxLogMessage(const char* formatString, ... ); | |
1203 | void wxVLogMessage(const char* formatString, va_list argPtr); | |
1204 | //@} | |
1205 | ||
b21126db | 1206 | /** @addtogroup group_funcmacro_log */ |
96d7cc9b FM |
1207 | //@{ |
1208 | /** | |
ef477678 BP |
1209 | For verbose output. Normally, it is suppressed, but might be activated if |
1210 | the user wishes to know more details about the program progress (another, | |
1211 | but possibly confusing name for the same function could be @c wxLogInfo). | |
1212 | ||
1213 | @header{wx/log.h} | |
96d7cc9b FM |
1214 | */ |
1215 | void wxLogVerbose(const char* formatString, ... ); | |
1216 | void wxVLogVerbose(const char* formatString, va_list argPtr); | |
1217 | //@} | |
1218 | ||
b21126db | 1219 | /** @addtogroup group_funcmacro_log */ |
96d7cc9b FM |
1220 | //@{ |
1221 | /** | |
ef477678 BP |
1222 | For warnings - they are also normally shown to the user, but don't |
1223 | interrupt the program work. | |
1224 | ||
1225 | @header{wx/log.h} | |
96d7cc9b FM |
1226 | */ |
1227 | void wxLogWarning(const char* formatString, ... ); | |
1228 | void wxVLogWarning(const char* formatString, va_list argPtr); | |
1229 | //@} | |
1230 | ||
b21126db | 1231 | /** @addtogroup group_funcmacro_log */ |
96d7cc9b FM |
1232 | //@{ |
1233 | /** | |
ef477678 BP |
1234 | Like wxLogError(), but also terminates the program with the exit code 3. |
1235 | Using @e abort() standard function also terminates the program with this | |
1236 | exit code. | |
1237 | ||
1238 | @header{wx/log.h} | |
96d7cc9b FM |
1239 | */ |
1240 | void wxLogFatalError(const char* formatString, ... ); | |
ef477678 | 1241 | void wxVLogFatalError(const char* formatString, va_list argPtr); |
96d7cc9b FM |
1242 | //@} |
1243 | ||
b21126db | 1244 | /** @addtogroup group_funcmacro_log */ |
96d7cc9b FM |
1245 | //@{ |
1246 | /** | |
ef477678 BP |
1247 | The functions to use for error messages, i.e. the messages that must be |
1248 | shown to the user. The default processing is to pop up a message box to | |
1249 | inform the user about it. | |
1250 | ||
1251 | @header{wx/log.h} | |
96d7cc9b FM |
1252 | */ |
1253 | void wxLogError(const char* formatString, ... ); | |
1254 | void wxVLogError(const char* formatString, va_list argPtr); | |
1255 | //@} | |
1256 | ||
b21126db | 1257 | /** @addtogroup group_funcmacro_log */ |
96d7cc9b FM |
1258 | //@{ |
1259 | /** | |
ef477678 BP |
1260 | Like wxLogDebug(), trace functions only do something in debug builds and |
1261 | expand to nothing in the release one. The reason for making it a separate | |
1262 | function is that usually there are a lot of trace messages, so it might | |
1263 | make sense to separate them from other debug messages. | |
1264 | ||
34085a0d VZ |
1265 | wxLogTrace(const char*,const char*,...) and can be used instead of |
1266 | wxLogDebug() if you would like to be able to separate trace messages into | |
1267 | different categories which can be enabled or disabled with | |
1268 | wxLog::AddTraceMask() and wxLog::RemoveTraceMask(). | |
ef477678 BP |
1269 | |
1270 | @header{wx/log.h} | |
96d7cc9b | 1271 | */ |
34085a0d VZ |
1272 | void wxLogTrace(const char *mask, const char* formatString, ... ); |
1273 | void wxVLogTrace(const char *mask, const char* formatString, va_list argPtr); | |
ef477678 BP |
1274 | //@} |
1275 | ||
b21126db | 1276 | /** @addtogroup group_funcmacro_log */ |
ef477678 BP |
1277 | //@{ |
1278 | /** | |
1279 | Like wxLogDebug(), trace functions only do something in debug builds and | |
1280 | expand to nothing in the release one. The reason for making it a separate | |
1281 | function is that usually there are a lot of trace messages, so it might | |
1282 | make sense to separate them from other debug messages. | |
1283 | ||
1284 | In this version of wxLogTrace(), trace messages can be separated into | |
1285 | different categories and calls using this function only log the message if | |
1286 | the given @a mask is currently enabled in wxLog. This lets you selectively | |
1287 | trace only some operations and not others by enabling the desired trace | |
1288 | masks with wxLog::AddTraceMask() or by setting the | |
1289 | @ref overview_envvars "@c WXTRACE environment variable". | |
1290 | ||
1291 | The predefined string trace masks used by wxWidgets are: | |
1292 | ||
1293 | @beginDefList | |
1294 | @itemdef{ wxTRACE_MemAlloc, Trace memory allocation (new/delete) } | |
1295 | @itemdef{ wxTRACE_Messages, Trace window messages/X callbacks } | |
1296 | @itemdef{ wxTRACE_ResAlloc, Trace GDI resource allocation } | |
1297 | @itemdef{ wxTRACE_RefCount, Trace various ref counting operations } | |
1298 | @itemdef{ wxTRACE_OleCalls, Trace OLE method calls (Win32 only) } | |
1299 | @endDefList | |
1300 | ||
1301 | @note Since both the mask and the format string are strings, this might | |
1302 | lead to function signature confusion in some cases: if you intend to | |
1303 | call the format string only version of wxLogTrace(), add a "%s" | |
1304 | format string parameter and then supply a second string parameter for | |
1305 | that "%s", the string mask version of wxLogTrace() will erroneously | |
1306 | get called instead, since you are supplying two string parameters to | |
1307 | the function. In this case you'll unfortunately have to avoid having | |
1308 | two leading string parameters, e.g. by adding a bogus integer (with | |
1309 | its "%d" format string). | |
1310 | ||
1311 | @header{wx/log.h} | |
1312 | */ | |
1313 | void wxLogTrace(const char* mask, const char* formatString, ... ); | |
96d7cc9b | 1314 | void wxVLogTrace(const char* mask, |
ef477678 BP |
1315 | const char* formatString, |
1316 | va_list argPtr); | |
96d7cc9b FM |
1317 | //@} |
1318 | ||
b21126db | 1319 | /** @addtogroup group_funcmacro_log */ |
ef477678 BP |
1320 | //@{ |
1321 | /** | |
1322 | Like wxLogDebug(), trace functions only do something in debug builds and | |
1323 | expand to nothing in the release one. The reason for making it a separate | |
1324 | function is that usually there are a lot of trace messages, so it might | |
1325 | make sense to separate them from other debug messages. | |
1326 | ||
22f24132 | 1327 | @deprecated |
ef477678 BP |
1328 | This version of wxLogTrace() only logs the message if all the bits |
1329 | corresponding to the @a mask are set in the wxLog trace mask which can be | |
1330 | set by calling wxLog::SetTraceMask(). This version is less flexible than | |
34085a0d | 1331 | wxLogTrace(const char*,const char*,...) because it doesn't allow defining |
ef477678 BP |
1332 | the user trace masks easily. This is why it is deprecated in favour of |
1333 | using string trace masks. | |
1334 | ||
1335 | The following bitmasks are defined for wxTraceMask: | |
1336 | ||
1337 | @beginDefList | |
1338 | @itemdef{ wxTraceMemAlloc, Trace memory allocation (new/delete) } | |
1339 | @itemdef{ wxTraceMessages, Trace window messages/X callbacks } | |
1340 | @itemdef{ wxTraceResAlloc, Trace GDI resource allocation } | |
1341 | @itemdef{ wxTraceRefCount, Trace various ref counting operations } | |
1342 | @itemdef{ wxTraceOleCalls, Trace OLE method calls (Win32 only) } | |
1343 | @endDefList | |
1344 | ||
1345 | @header{wx/log.h} | |
1346 | */ | |
1347 | void wxLogTrace(wxTraceMask mask, const char* formatString, ... ); | |
1348 | void wxVLogTrace(wxTraceMask mask, const char* formatString, va_list argPtr); | |
1349 | //@} | |
96d7cc9b | 1350 | |
b21126db | 1351 | /** @addtogroup group_funcmacro_log */ |
96d7cc9b FM |
1352 | //@{ |
1353 | /** | |
ef477678 BP |
1354 | The right functions for debug output. They only do something in debug mode |
1355 | (when the preprocessor symbol @c __WXDEBUG__ is defined) and expand to | |
96d7cc9b | 1356 | nothing in release mode (otherwise). |
ef477678 BP |
1357 | |
1358 | @header{wx/log.h} | |
96d7cc9b FM |
1359 | */ |
1360 | void wxLogDebug(const char* formatString, ... ); | |
1361 | void wxVLogDebug(const char* formatString, va_list argPtr); | |
1362 | //@} | |
1363 | ||
b21126db | 1364 | /** @addtogroup group_funcmacro_log */ |
96d7cc9b FM |
1365 | //@{ |
1366 | /** | |
ef477678 BP |
1367 | Messages logged by this function will appear in the statusbar of the |
1368 | @a frame or of the top level application window by default (i.e. when using | |
96d7cc9b | 1369 | the second version of the functions). |
ef477678 | 1370 | |
96d7cc9b | 1371 | If the target frame doesn't have a statusbar, the message will be lost. |
ef477678 BP |
1372 | |
1373 | @header{wx/log.h} | |
96d7cc9b | 1374 | */ |
ef477678 BP |
1375 | void wxLogStatus(wxFrame* frame, const char* formatString, ... ); |
1376 | void wxVLogStatus(wxFrame* frame, const char* formatString, va_list argPtr); | |
96d7cc9b FM |
1377 | void wxLogStatus(const char* formatString, ... ); |
1378 | void wxVLogStatus(const char* formatString, va_list argPtr); | |
1379 | //@} | |
1380 | ||
b21126db | 1381 | /** @addtogroup group_funcmacro_log */ |
96d7cc9b FM |
1382 | //@{ |
1383 | /** | |
ef477678 BP |
1384 | Mostly used by wxWidgets itself, but might be handy for logging errors |
1385 | after system call (API function) failure. It logs the specified message | |
1386 | text as well as the last system error code (@e errno or @e ::GetLastError() | |
1387 | depending on the platform) and the corresponding error message. The second | |
1388 | form of this function takes the error code explicitly as the first | |
1389 | argument. | |
96d7cc9b FM |
1390 | |
1391 | @see wxSysErrorCode(), wxSysErrorMsg() | |
ef477678 BP |
1392 | |
1393 | @header{wx/log.h} | |
96d7cc9b FM |
1394 | */ |
1395 | void wxLogSysError(const char* formatString, ... ); | |
ef477678 | 1396 | void wxVLogSysError(const char* formatString, va_list argPtr); |
39fb8056 FM |
1397 | //@} |
1398 | ||
7d9550df VZ |
1399 | /** @addtogroup group_funcmacro_debug */ |
1400 | //@{ | |
1401 | ||
1402 | /** | |
1403 | @def wxDISABLE_DEBUG_LOGGING_IN_RELEASE_BUILD() | |
1404 | ||
1405 | Use this macro to disable logging at debug and trace levels in release | |
1406 | build when not using IMPLEMENT_APP(). | |
1407 | ||
1408 | @see wxDISABLE_DEBUG_SUPPORT(), | |
1409 | wxDISABLE_ASSERTS_IN_RELEASE_BUILD(), | |
1410 | @ref overview_debugging | |
1411 | ||
1412 | @since 2.9.1 | |
1413 | ||
1414 | @header{wx/log.h} | |
1415 | */ | |
1416 | #define wxDISABLE_DEBUG_LOGGING_IN_RELEASE_BUILD() | |
1417 | ||
1418 | //@} | |
1419 |