]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: log.h | |
3 | // Purpose: interface of wxLogWindow | |
4 | // Author: wxWidgets team | |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | /** | |
10 | @class wxLogWindow | |
11 | @wxheader{log.h} | |
12 | ||
13 | This class represents a background log window: to be precise, it collects all | |
14 | log messages in the log frame which it manages but also passes them on to the | |
15 | log target which was active at the moment of its creation. This allows, for | |
16 | example, to show all the log messages in a frame but still continue to process | |
17 | them normally by showing the standard log dialog. | |
18 | ||
19 | @library{wxbase} | |
20 | @category{logging} | |
21 | ||
22 | @see wxLogTextCtrl | |
23 | */ | |
24 | class wxLogWindow : public wxLogInterposer | |
25 | { | |
26 | public: | |
27 | /** | |
28 | Creates the log frame window and starts collecting the messages in it. | |
29 | ||
30 | @param parent | |
31 | The parent window for the log frame, may be @NULL | |
32 | @param title | |
33 | The title for the log frame | |
34 | @param show | |
35 | @true to show the frame initially (default), otherwise | |
36 | Show() must be called later. | |
37 | @param passToOld | |
38 | @true to process the log messages normally in addition to | |
39 | logging them in the log frame (default), @false to only log them in the | |
40 | log frame. | |
41 | */ | |
42 | wxLogWindow(wxFrame parent, const wxChar title, bool show = true, | |
43 | bool passToOld = true); | |
44 | ||
45 | /** | |
46 | Returns the associated log frame window. This may be used to position or resize | |
47 | it but use Show() to show or hide it. | |
48 | */ | |
49 | wxFrame* GetFrame() const; | |
50 | ||
51 | /** | |
52 | Called if the user closes the window interactively, will not be | |
53 | called if it is destroyed for another reason (such as when program | |
54 | exits). | |
55 | Return @true from here to allow the frame to close, @false to | |
56 | prevent this from happening. | |
57 | ||
58 | @see OnFrameDelete() | |
59 | */ | |
60 | virtual bool OnFrameClose(wxFrame frame); | |
61 | ||
62 | /** | |
63 | Called immediately after the log frame creation allowing for | |
64 | any extra initializations. | |
65 | */ | |
66 | virtual void OnFrameCreate(wxFrame frame); | |
67 | ||
68 | /** | |
69 | Called right before the log frame is going to be deleted: will | |
70 | always be called unlike OnFrameClose(). | |
71 | */ | |
72 | virtual void OnFrameDelete(wxFrame frame); | |
73 | ||
74 | /** | |
75 | Shows or hides the frame. | |
76 | */ | |
77 | void Show(bool show = true); | |
78 | }; | |
79 | ||
80 | ||
81 | ||
82 | /** | |
83 | @class wxLogInterposerTemp | |
84 | @wxheader{log.h} | |
85 | ||
86 | A special version of wxLogChain which uses itself as the | |
87 | new log target. It forwards log messages to the previously installed one in | |
88 | addition to | |
89 | processing them itself. Unlike wxLogInterposer, it doesn't | |
90 | delete the old target which means it can be used to temporarily redirect log | |
91 | output. | |
92 | ||
93 | As per wxLogInterposer, this class must be derived from to implement | |
94 | wxLog::DoLog | |
95 | and/or wxLog::DoLogString methods. | |
96 | ||
97 | @library{wxbase} | |
98 | @category{logging} | |
99 | */ | |
100 | class wxLogInterposerTemp : public wxLogChain | |
101 | { | |
102 | public: | |
103 | /** | |
104 | The default constructor installs this object as the current active log target. | |
105 | */ | |
106 | }; | |
107 | ||
108 | ||
109 | ||
110 | /** | |
111 | @class wxLogChain | |
112 | @wxheader{log.h} | |
113 | ||
114 | This simple class allows to chain log sinks, that is to install a new sink but | |
115 | keep passing log messages to the old one instead of replacing it completely as | |
116 | wxLog::SetActiveTarget does. | |
117 | ||
118 | It is especially useful when you want to divert the logs somewhere (for | |
119 | example to a file or a log window) but also keep showing the error messages | |
120 | using the standard dialogs as wxLogGui does by default. | |
121 | ||
122 | Example of usage: | |
123 | ||
124 | @code | |
125 | wxLogChain *logChain = new wxLogChain(new wxLogStderr); | |
126 | ||
127 | // all the log messages are sent to stderr and also processed as usually | |
128 | ... | |
129 | ||
130 | // don't delete logChain directly as this would leave a dangling | |
131 | // pointer as active log target, use SetActiveTarget() instead | |
132 | delete wxLog::SetActiveTarget(...something else or @NULL...); | |
133 | @endcode | |
134 | ||
135 | @library{wxbase} | |
136 | @category{logging} | |
137 | */ | |
138 | class wxLogChain : public wxLog | |
139 | { | |
140 | public: | |
141 | /** | |
142 | Sets the specified @c logger (which may be @NULL) as the default log | |
143 | target but the log messages are also passed to the previous log target if any. | |
144 | */ | |
145 | wxLogChain(wxLog* logger); | |
146 | ||
147 | /** | |
148 | Destroys the previous log target. | |
149 | */ | |
150 | ~wxLogChain(); | |
151 | ||
152 | /** | |
153 | Detaches the old log target so it won't be destroyed when the wxLogChain object | |
154 | is destroyed. | |
155 | */ | |
156 | void DetachOldLog(); | |
157 | ||
158 | /** | |
159 | Returns the pointer to the previously active log target (which may be @NULL). | |
160 | */ | |
161 | wxLog* GetOldLog() const; | |
162 | ||
163 | /** | |
164 | Returns @true if the messages are passed to the previously active log | |
165 | target (default) or @false if PassMessages() | |
166 | had been called. | |
167 | */ | |
168 | bool IsPassingMessages() const; | |
169 | ||
170 | /** | |
171 | By default, the log messages are passed to the previously active log target. | |
172 | Calling this function with @false parameter disables this behaviour | |
173 | (presumably temporarily, as you shouldn't use wxLogChain at all otherwise) and | |
174 | it can be reenabled by calling it again with @a passMessages set to @true. | |
175 | */ | |
176 | void PassMessages(bool passMessages); | |
177 | ||
178 | /** | |
179 | Sets another log target to use (may be @NULL). The log target specified | |
180 | in the @ref ctor() constructor or in a previous call to | |
181 | this function is deleted. | |
182 | This doesn't change the old log target value (the one the messages are | |
183 | forwarded to) which still remains the same as was active when wxLogChain | |
184 | object was created. | |
185 | */ | |
186 | void SetLog(wxLog* logger); | |
187 | }; | |
188 | ||
189 | ||
190 | ||
191 | /** | |
192 | @class wxLogGui | |
193 | @wxheader{log.h} | |
194 | ||
195 | This is the default log target for the GUI wxWidgets applications. It is passed | |
196 | to wxLog::SetActiveTarget at the program | |
197 | startup and is deleted by wxWidgets during the program shut down. | |
198 | ||
199 | @library{wxbase} | |
200 | @category{logging} | |
201 | */ | |
202 | class wxLogGui : public wxLog | |
203 | { | |
204 | public: | |
205 | /** | |
206 | Default constructor. | |
207 | */ | |
208 | wxLogGui(); | |
209 | }; | |
210 | ||
211 | ||
212 | ||
213 | /** | |
214 | @class wxLogStream | |
215 | @wxheader{log.h} | |
216 | ||
217 | This class can be used to redirect the log messages to a C++ stream. | |
218 | ||
219 | Please note that this class is only available if wxWidgets was compiled with | |
220 | the standard iostream library support (@c wxUSE_STD_IOSTREAM must be on). | |
221 | ||
222 | @library{wxbase} | |
223 | @category{logging} | |
224 | ||
225 | @see wxLogStderr, wxStreamToTextRedirector | |
226 | */ | |
227 | class wxLogStream : public wxLog | |
228 | { | |
229 | public: | |
230 | /** | |
231 | Constructs a log target which sends all the log messages to the given | |
232 | output stream. If it is @NULL, the messages are sent to @c cerr. | |
233 | */ | |
234 | wxLogStream(std::ostream ostr = NULL); | |
235 | }; | |
236 | ||
237 | ||
238 | ||
239 | /** | |
240 | @class wxLogStderr | |
241 | @wxheader{log.h} | |
242 | ||
243 | This class can be used to redirect the log messages to a C file stream (not to | |
244 | be confused with C++ streams). It is the default log target for the non-GUI | |
245 | wxWidgets applications which send all the output to @c stderr. | |
246 | ||
247 | @library{wxbase} | |
248 | @category{logging} | |
249 | ||
250 | @see wxLogStream | |
251 | */ | |
252 | class wxLogStderr : public wxLog | |
253 | { | |
254 | public: | |
255 | /** | |
256 | Constructs a log target which sends all the log messages to the given | |
257 | @c FILE. If it is @NULL, the messages are sent to @c stderr. | |
258 | */ | |
259 | wxLogStderr(FILE fp = NULL); | |
260 | }; | |
261 | ||
262 | ||
263 | ||
264 | /** | |
265 | @class wxLogBuffer | |
266 | @wxheader{log.h} | |
267 | ||
268 | wxLogBuffer is a very simple implementation of log sink which simply collects | |
269 | all the logged messages in a string (except the debug messages which are output | |
270 | in the usual way immediately as we're presumably not interested in collecting | |
271 | them for later). The messages from different log function calls are separated | |
272 | by the new lines. | |
273 | ||
274 | All the messages collected so far can be shown to the user (and the current | |
275 | buffer cleared) by calling the overloaded wxLogBuffer::Flush | |
276 | method. | |
277 | ||
278 | @library{wxbase} | |
279 | @category{FIXME} | |
280 | */ | |
281 | class wxLogBuffer : public wxLog | |
282 | { | |
283 | public: | |
284 | /** | |
285 | Shows all the messages collected so far to the user (using a message box in the | |
286 | GUI applications or by printing them out to the console in text mode) and | |
287 | clears the internal buffer. | |
288 | */ | |
289 | virtual void Flush(); | |
290 | ||
291 | /** | |
292 | Returns the current buffer contains. Messages from different log function calls | |
293 | are separated with the new lines in the buffer. | |
294 | The buffer can be cleared by Flush() which will | |
295 | also show the current contents to the user. | |
296 | */ | |
297 | const wxString GetBuffer(); | |
298 | }; | |
299 | ||
300 | ||
301 | ||
302 | /** | |
303 | @class wxLogInterposer | |
304 | @wxheader{log.h} | |
305 | ||
306 | A special version of wxLogChain which uses itself as the | |
307 | new log target. It forwards log messages to the previously installed one in | |
308 | addition to | |
309 | processing them itself. | |
310 | ||
311 | Unlike wxLogChain which is usually used directly as is, | |
312 | this class must be derived from to implement wxLog::DoLog | |
313 | and/or wxLog::DoLogString methods. | |
314 | ||
315 | wxLogInterposer destroys the previous log target in its destructor. If you | |
316 | don't want this to happen, use wxLogInterposerTemp instead. | |
317 | ||
318 | @library{wxbase} | |
319 | @category{logging} | |
320 | */ | |
321 | class wxLogInterposer : public wxLogChain | |
322 | { | |
323 | public: | |
324 | /** | |
325 | The default constructor installs this object as the current active log target. | |
326 | */ | |
327 | }; | |
328 | ||
329 | ||
330 | ||
331 | /** | |
332 | @class wxLogTextCtrl | |
333 | @wxheader{log.h} | |
334 | ||
335 | Using these target all the log messages can be redirected to a text control. | |
336 | The text control must have been created with @c wxTE_MULTILINE style by the | |
337 | caller previously. | |
338 | ||
339 | @library{wxbase} | |
340 | @category{logging} | |
341 | ||
342 | @see wxTextCtrl, wxStreamToTextRedirector | |
343 | */ | |
344 | class wxLogTextCtrl : public wxLog | |
345 | { | |
346 | public: | |
347 | /** | |
348 | Constructs a log target which sends all the log messages to the given text | |
349 | control. The @a textctrl parameter cannot be @NULL. | |
350 | */ | |
351 | wxLogTextCtrl(wxTextCtrl textctrl); | |
352 | }; | |
353 | ||
354 | ||
355 | ||
356 | /** | |
357 | @class wxLog | |
358 | @wxheader{log.h} | |
359 | ||
360 | wxLog class defines the interface for the @e log targets used by wxWidgets | |
361 | logging functions as explained in the @ref overview_wxlogoverview "wxLog | |
362 | overview". | |
363 | The only situations when you need to directly use this class is when you want | |
364 | to derive your own log target because the existing ones don't satisfy your | |
365 | needs. Another case is if you wish to customize the behaviour of the standard | |
366 | logging classes (all of which respect the wxLog settings): for example, set | |
367 | which trace messages are logged and which are not or change (or even remove | |
368 | completely) the timestamp on the messages. | |
369 | ||
370 | Otherwise, it is completely hidden behind the @e wxLogXXX() functions and | |
371 | you may not even know about its existence. | |
372 | ||
373 | See @ref overview_wxlogoverview "log overview" for the descriptions of wxWidgets | |
374 | logging facilities. | |
375 | ||
376 | @section overview_wxLog_deriving Deriving your own log target | |
377 | ||
378 | There are two functions which must be implemented by any derived class to | |
379 | actually process the log messages: DoLog() and | |
380 | DoLogString(). The second function receives a string | |
381 | which just has to be output in some way and the easiest way to write a new log | |
382 | target is to override just this function in the derived class. If more control | |
383 | over the output format is needed, then the first function must be overridden | |
384 | which allows to construct custom messages depending on the log level or even | |
385 | do completely different things depending on the message severity (for example, | |
386 | throw away all messages except warnings and errors, show warnings on the | |
387 | screen and forward the error messages to the user's (or programmer's) cell | |
388 | phone - maybe depending on whether the timestamp tells us if it is day or | |
389 | night in the current time zone). | |
390 | There also functions to support message buffering. Why are they needed? | |
391 | Some of wxLog implementations, most notably the standard wxLogGui class, | |
392 | buffer the messages (for example, to avoid showing the user a zillion of modal | |
393 | message boxes one after another -- which would be really annoying). | |
394 | Flush() shows them all and clears the buffer contents. | |
395 | This function doesn't do anything if the buffer is already empty. | |
396 | See also: | |
397 | @li Flush() | |
398 | @li FlushActive() | |
399 | ||
400 | @section overview_wxLog_Trace_Masks Using trace masks | |
401 | ||
402 | The functions below allow some limited customization of wxLog behaviour | |
403 | without writing a new log target class (which, aside of being a matter of | |
404 | several minutes, allows you to do anything you want). | |
405 | The verbose messages are the trace messages which are not disabled in the | |
406 | release mode and are generated by wxLogVerbose(). They | |
407 | are not normally shown to the user because they present little interest, but | |
408 | may be activated, for example, in order to help the user find some program | |
409 | problem. | |
410 | As for the (real) trace messages, their handling depends on the settings of | |
411 | the (application global) @e trace mask which can either be specified using | |
412 | SetTraceMask(), GetTraceMask() and wxLogTrace() which takes an integer mask | |
413 | or using AddTraceMask() for string trace masks. | |
414 | The difference between bit-wise and string trace masks is that a message using | |
415 | integer trace mask will only be logged if all bits of the mask are set in the | |
416 | current mask while a message using string mask will be logged simply if the | |
417 | mask had been added before to the list of allowed ones. | |
418 | For example, | |
419 | ||
420 | @code | |
421 | wxLogTrace( wxTraceRefCount|wxTraceOleCalls, "Active object ref count: %d", nRef ); | |
422 | @endcode | |
423 | ||
424 | will do something only if the current trace mask contains both | |
425 | @c wxTraceRefCount and @c wxTraceOle, but | |
426 | ||
427 | @code | |
428 | wxLogTrace( wxTRACE_OleCalls, "IFoo::Bar() called" ); | |
429 | @endcode | |
430 | ||
431 | will log the message if it was preceded by | |
432 | ||
433 | @code | |
434 | wxLog::AddTraceMask( wxTRACE_OleCalls); | |
435 | @endcode | |
436 | ||
437 | Using string masks is simpler and allows to easily add custom ones, so this is | |
438 | the preferred way of working with trace messages. The integer trace mask is | |
439 | kept for compatibility and for additional (but very rarely needed) flexibility | |
440 | only. | |
441 | The standard trace masks are given in wxLogTrace() documentation. | |
442 | Finally, the @e wxLog::DoLog() function automatically prepends a time stamp | |
443 | to all the messages. The format of the time stamp may be changed: it can be | |
444 | any string with % specifications fully described in the documentation of the | |
445 | standard @e strftime() function. For example, the default format is | |
446 | "[%d/%b/%y %H:%M:%S] " which gives something like "[17/Sep/98 22:10:16] " | |
447 | (without quotes) for the current date. Setting an empty string as the time | |
448 | format disables timestamping of the messages completely. | |
449 | See also | |
450 | @li AddTraceMask() | |
451 | @li RemoveTraceMask() | |
452 | @li ClearTraceMasks() | |
453 | @li GetTraceMasks() | |
454 | @li IsAllowedTraceMask() | |
455 | @li SetVerbose() | |
456 | @li GetVerbose() | |
457 | @li SetTimestamp() | |
458 | @li GetTimestamp() | |
459 | @li SetTraceMask() | |
460 | @li GetTraceMask() | |
461 | @li SetRepetitionCounting() | |
462 | @li GetRepetitionCounting() | |
463 | ||
464 | @note Timestamping is disabled for Visual C++ users in debug builds by | |
465 | default because otherwise it would be impossible to directly go to the line | |
466 | from which the log message was generated by simply clicking in the debugger | |
467 | window on the corresponding error message. If you wish to enable it, please | |
468 | use SetTimestamp() explicitly. | |
469 | ||
470 | @section overview_wxLog_Target Manipulating the log target | |
471 | ||
472 | The functions in this section work with and manipulate the active log | |
473 | target. The OnLog() is called by the @e wxLogXXX() functions | |
474 | and invokes the DoLog() of the active log target if any. | |
475 | Get/Set methods are used to install/query the current active target and, | |
476 | finally, DontCreateOnDemand() disables the automatic creation of a standard | |
477 | log target if none actually exists. It is only useful when the application | |
478 | is terminating and shouldn't be used in other situations because it may | |
479 | easily lead to a loss of messages. See also | |
480 | @li OnLog() | |
481 | @li GetActiveTarget() | |
482 | @li SetActiveTarget() | |
483 | @li DontCreateOnDemand() | |
484 | @li Suspend() | |
485 | @li Resume() | |
486 | ||
487 | @library{wxcore} | |
488 | @category{logging} | |
489 | ||
490 | @see wxLog::RemoveTraceMask, wxLog::GetTraceMasks | |
491 | */ | |
492 | class wxLog | |
493 | { | |
494 | public: | |
495 | /** | |
496 | Add the @a mask to the list of allowed masks for | |
497 | wxLogTrace(). | |
498 | ||
499 | @see RemoveTraceMask(), GetTraceMasks() | |
500 | */ | |
501 | static void AddTraceMask(const wxString& mask); | |
502 | ||
503 | /** | |
504 | Removes all trace masks previously set with | |
505 | AddTraceMask(). | |
506 | ||
507 | @see RemoveTraceMask() | |
508 | */ | |
509 | static void ClearTraceMasks(); | |
510 | ||
511 | */ | |
512 | ||
513 | ||
514 | /** | |
515 | Disables time stamping of the log messages. | |
516 | This function is new since wxWidgets version 2.9 | |
517 | */ | |
518 | void SetTimestamp(const wxString& format); | |
519 | ||
520 | /** | |
521 | Called to process the message of the specified severity. @a msg is the text | |
522 | of the message as specified in the call of @e wxLogXXX() function which | |
523 | generated it and @a timestamp is the moment when the message was generated. | |
524 | The base class version prepends the timestamp to the message, adds a prefix | |
525 | corresponding to the log level and then calls | |
526 | DoLogString() with the resulting string. | |
527 | */ | |
528 | virtual void DoLog(wxLogLevel level, const wxString& msg, | |
529 | time_t timestamp); | |
530 | ||
531 | /** | |
532 | Called to log the specified string. The timestamp is already included in the | |
533 | string but still passed to this function. | |
534 | A simple implementation may just send the string to @c stdout or, better, | |
535 | @c stderr. | |
536 | */ | |
537 | virtual void DoLogString(const wxString& msg, time_t timestamp); | |
538 | ||
539 | /** | |
540 | Instructs wxLog to not create new log targets on the fly if there is none | |
541 | currently. (Almost) for internal use only: it is supposed to be called by the | |
542 | application shutdown code. | |
543 | Note that this function also calls | |
544 | ClearTraceMasks(). | |
545 | */ | |
546 | static void DontCreateOnDemand(); | |
547 | ||
548 | /** | |
549 | Shows all the messages currently in buffer and clears it. If the buffer | |
550 | is already empty, nothing happens. | |
551 | */ | |
552 | virtual void Flush(); | |
553 | ||
554 | /** | |
555 | Flushes the current log target if any, does nothing if there is none. | |
556 | ||
557 | @see Flush() | |
558 | */ | |
559 | static void FlushActive(); | |
560 | ||
561 | /** | |
562 | Returns the pointer to the active log target (may be @NULL). | |
563 | */ | |
564 | static wxLog* GetActiveTarget(); | |
565 | ||
566 | /** | |
567 | Returns the current log level limit. | |
568 | */ | |
569 | static wxLogLevel GetLogLevel(); | |
570 | ||
571 | /** | |
572 | Returns whether the repetition counting mode is enabled. | |
573 | */ | |
574 | static bool GetRepetitionCounting(); | |
575 | ||
576 | /** | |
577 | Returns the current timestamp format string. | |
578 | */ | |
579 | static const wxString GetTimestamp(); | |
580 | ||
581 | /** | |
582 | Returns the current trace mask, see Customization() section | |
583 | for details. | |
584 | */ | |
585 | static wxTraceMask GetTraceMask(); | |
586 | ||
587 | /** | |
588 | Returns the currently allowed list of string trace masks. | |
589 | ||
590 | @see AddTraceMask(). | |
591 | */ | |
592 | static const wxArrayString GetTraceMasks(); | |
593 | ||
594 | /** | |
595 | Returns whether the verbose mode is currently active. | |
596 | */ | |
597 | static bool GetVerbose(); | |
598 | ||
599 | /** | |
600 | Returns @true if the @a mask is one of allowed masks for | |
601 | wxLogTrace(). | |
602 | ||
603 | See also: AddTraceMask(), RemoveTraceMask() | |
604 | */ | |
605 | static bool IsAllowedTraceMask(const wxString& mask); | |
606 | ||
607 | /** | |
608 | There are two functions which must be implemented by any derived class to | |
609 | actually process the log messages: DoLog() and | |
610 | DoLogString(). The second function receives a string | |
611 | which just has to be output in some way and the easiest way to write a new log | |
612 | target is to override just this function in the derived class. If more control | |
613 | over the output format is needed, then the first function must be overridden | |
614 | which allows to construct custom messages depending on the log level or even | |
615 | do completely different things depending on the message severity (for example, | |
616 | throw away all messages except warnings and errors, show warnings on the | |
617 | screen and forward the error messages to the user's (or programmer's) cell | |
618 | phone - maybe depending on whether the timestamp tells us if it is day or | |
619 | night in the current time zone). | |
620 | There also functions to support message buffering. Why are they needed? | |
621 | Some of wxLog implementations, most notably the standard wxLogGui class, | |
622 | buffer the messages (for example, to avoid showing the user a zillion of modal | |
623 | message boxes one after another -- which would be really annoying). | |
624 | Flush() shows them all and clears the buffer contents. | |
625 | This function doesn't do anything if the buffer is already empty. | |
626 | Flush() | |
627 | ||
628 | FlushActive() | |
629 | */ | |
630 | ||
631 | ||
632 | /** | |
633 | Forwards the message at specified level to the @e DoLog() function of the | |
634 | active log target if there is any, does nothing otherwise. | |
635 | */ | |
636 | static void OnLog(wxLogLevel level, const wxString& message); | |
637 | ||
638 | /** | |
639 | Remove the @a mask from the list of allowed masks for | |
640 | wxLogTrace(). | |
641 | See also: AddTraceMask() | |
642 | */ | |
643 | static void RemoveTraceMask(const wxString& mask); | |
644 | ||
645 | /** | |
646 | Resumes logging previously suspended by a call to | |
647 | Suspend(). All messages logged in the meanwhile will be | |
648 | flushed soon. | |
649 | */ | |
650 | static void Resume(); | |
651 | ||
652 | /** | |
653 | Sets the specified log target as the active one. Returns the pointer to the | |
654 | previous active log target (may be @NULL). To suppress logging use a new | |
655 | instance of wxLogNull not @NULL. If the active log target is set to @NULL a | |
656 | new default log target will be created when logging occurs. | |
657 | */ | |
658 | static wxLog* SetActiveTarget(wxLog* logtarget); | |
659 | ||
660 | /** | |
661 | Specifies that log messages with level logLevel should be ignored | |
662 | and not sent to the active log target. | |
663 | */ | |
664 | static void SetLogLevel(wxLogLevel logLevel); | |
665 | ||
666 | /** | |
667 | Enables logging mode in which a log message is logged once, and in case exactly | |
668 | the same message successively repeats one or more times, only the number of | |
669 | repetitions is logged. | |
670 | */ | |
671 | static void SetRepetitionCounting(bool repetCounting = true); | |
672 | ||
673 | /** | |
674 | Sets the timestamp format prepended by the default log targets to all | |
675 | messages. The string may contain any normal characters as well as % | |
676 | prefixed format specificators, see @e strftime() manual for details. | |
677 | Passing an empty string to this function disables message time stamping. | |
678 | */ | |
679 | static void SetTimestamp(const wxString& format); | |
680 | ||
681 | /** | |
682 | Sets the trace mask, see Customization() | |
683 | section for details. | |
684 | */ | |
685 | static void SetTraceMask(wxTraceMask mask); | |
686 | ||
687 | /** | |
688 | Activates or deactivates verbose mode in which the verbose messages are | |
689 | logged as the normal ones instead of being silently dropped. | |
690 | */ | |
691 | static void SetVerbose(bool verbose = true); | |
692 | ||
693 | /** | |
694 | Suspends the logging until Resume() is called. Note that | |
695 | the latter must be called the same number of times as the former to undo it, | |
696 | i.e. if you call Suspend() twice you must call Resume() twice as well. | |
697 | Note that suspending the logging means that the log sink won't be be flushed | |
698 | periodically, it doesn't have any effect if the current log target does the | |
699 | logging immediately without waiting for Flush() to be | |
700 | called (the standard GUI log target only shows the log dialog when it is | |
701 | flushed, so Suspend() works as expected with it). | |
702 | ||
703 | @see Resume(), wxLogNull | |
704 | */ | |
705 | static void Suspend(); | |
706 | }; | |
707 | ||
708 | ||
709 | ||
710 | /** | |
711 | @class wxLogNull | |
712 | @wxheader{log.h} | |
713 | ||
714 | This class allows to temporarily suspend logging. All calls to the log | |
715 | functions during the life time of an object of this class are just ignored. | |
716 | ||
717 | In particular, it can be used to suppress the log messages given by wxWidgets | |
718 | itself but it should be noted that it is rarely the best way to cope with this | |
719 | problem as @b all log messages are suppressed, even if they indicate a | |
720 | completely different error than the one the programmer wanted to suppress. | |
721 | ||
722 | For instance, the example of the overview: | |
723 | ||
724 | @code | |
725 | wxFile file; | |
726 | ||
727 | // wxFile.Open() normally complains if file can't be opened, we don't want it | |
728 | { | |
729 | wxLogNull logNo; | |
730 | if ( !file.Open("bar") ) | |
731 | ... process error ourselves ... | |
732 | } // ~wxLogNull called, old log sink restored | |
733 | ||
734 | wxLogMessage("..."); // ok | |
735 | @endcode | |
736 | ||
737 | would be better written as: | |
738 | ||
739 | @code | |
740 | wxFile file; | |
741 | ||
742 | // don't try to open file if it doesn't exist, we are prepared to deal with | |
743 | // this ourselves - but all other errors are not expected | |
744 | if ( wxFile::Exists("bar") ) | |
745 | { | |
746 | // gives an error message if the file couldn't be opened | |
747 | file.Open("bar"); | |
748 | } | |
749 | else | |
750 | { | |
751 | ... | |
752 | } | |
753 | @endcode | |
754 | ||
755 | ||
756 | @library{wxbase} | |
757 | @category{logging} | |
758 | */ | |
759 | class wxLogNull : public wxLog | |
760 | { | |
761 | public: | |
762 | /** | |
763 | Suspends logging. | |
764 | */ | |
765 | wxLogNull(); | |
766 | ||
767 | /** | |
768 | Resumes logging. | |
769 | */ | |
770 | }; | |
771 | ||
772 | ||
773 | ||
774 | // ============================================================================ | |
775 | // Global functions/macros | |
776 | // ============================================================================ | |
777 | ||
778 | /** @ingroup group_funcmacro_log */ | |
779 | //@{ | |
780 | ||
781 | /** | |
782 | This function shows a message to the user in a safe way and should be safe | |
783 | to call even before the application has been initialized or if it is | |
784 | currently in some other strange state (for example, about to crash). Under | |
785 | Windows this function shows a message box using a native dialog instead of | |
786 | wxMessageBox() (which might be unsafe to call), elsewhere it simply prints | |
787 | the message to the standard output using the title as prefix. | |
788 | ||
789 | @param title | |
790 | The title of the message box shown to the user or the prefix of the | |
791 | message string. | |
792 | @param text | |
793 | The text to show to the user. | |
794 | ||
795 | @see wxLogFatalError() | |
796 | ||
797 | @header{wx/log.h} | |
798 | */ | |
799 | void wxSafeShowMessage(const wxString& title, const wxString& text); | |
800 | ||
801 | /** | |
802 | Returns the error code from the last system call. This function uses | |
803 | @c errno on Unix platforms and @c GetLastError under Win32. | |
804 | ||
805 | @see wxSysErrorMsg(), wxLogSysError() | |
806 | ||
807 | @header{wx/log.h} | |
808 | */ | |
809 | unsigned long wxSysErrorCode(); | |
810 | ||
811 | /** | |
812 | Returns the error message corresponding to the given system error code. If | |
813 | @a errCode is 0 (default), the last error code (as returned by | |
814 | wxSysErrorCode()) is used. | |
815 | ||
816 | @see wxSysErrorCode(), wxLogSysError() | |
817 | ||
818 | @header{wx/log.h} | |
819 | */ | |
820 | const wxChar* wxSysErrorMsg(unsigned long errCode = 0); | |
821 | ||
822 | //@} | |
823 | ||
824 | /** @ingroup group_funcmacro_log */ | |
825 | //@{ | |
826 | /** | |
827 | For all normal, informational messages. They also appear in a message box | |
828 | by default (but it can be changed). | |
829 | ||
830 | @header{wx/log.h} | |
831 | */ | |
832 | void wxLogMessage(const char* formatString, ... ); | |
833 | void wxVLogMessage(const char* formatString, va_list argPtr); | |
834 | //@} | |
835 | ||
836 | /** @ingroup group_funcmacro_log */ | |
837 | //@{ | |
838 | /** | |
839 | For verbose output. Normally, it is suppressed, but might be activated if | |
840 | the user wishes to know more details about the program progress (another, | |
841 | but possibly confusing name for the same function could be @c wxLogInfo). | |
842 | ||
843 | @header{wx/log.h} | |
844 | */ | |
845 | void wxLogVerbose(const char* formatString, ... ); | |
846 | void wxVLogVerbose(const char* formatString, va_list argPtr); | |
847 | //@} | |
848 | ||
849 | /** @ingroup group_funcmacro_log */ | |
850 | //@{ | |
851 | /** | |
852 | For warnings - they are also normally shown to the user, but don't | |
853 | interrupt the program work. | |
854 | ||
855 | @header{wx/log.h} | |
856 | */ | |
857 | void wxLogWarning(const char* formatString, ... ); | |
858 | void wxVLogWarning(const char* formatString, va_list argPtr); | |
859 | //@} | |
860 | ||
861 | /** @ingroup group_funcmacro_log */ | |
862 | //@{ | |
863 | /** | |
864 | Like wxLogError(), but also terminates the program with the exit code 3. | |
865 | Using @e abort() standard function also terminates the program with this | |
866 | exit code. | |
867 | ||
868 | @header{wx/log.h} | |
869 | */ | |
870 | void wxLogFatalError(const char* formatString, ... ); | |
871 | void wxVLogFatalError(const char* formatString, va_list argPtr); | |
872 | //@} | |
873 | ||
874 | /** @ingroup group_funcmacro_log */ | |
875 | //@{ | |
876 | /** | |
877 | The functions to use for error messages, i.e. the messages that must be | |
878 | shown to the user. The default processing is to pop up a message box to | |
879 | inform the user about it. | |
880 | ||
881 | @header{wx/log.h} | |
882 | */ | |
883 | void wxLogError(const char* formatString, ... ); | |
884 | void wxVLogError(const char* formatString, va_list argPtr); | |
885 | //@} | |
886 | ||
887 | /** @ingroup group_funcmacro_log */ | |
888 | //@{ | |
889 | /** | |
890 | Like wxLogDebug(), trace functions only do something in debug builds and | |
891 | expand to nothing in the release one. The reason for making it a separate | |
892 | function is that usually there are a lot of trace messages, so it might | |
893 | make sense to separate them from other debug messages. | |
894 | ||
895 | wxLogDebug(const char*,const char*,...) and | |
896 | wxLogDebug(wxTraceMask,const char*,...) can be used instead if you would | |
897 | like to be able to separate trace messages into different categories which | |
898 | can be enabled or disabled with the static functions provided in wxLog. | |
899 | ||
900 | @header{wx/log.h} | |
901 | */ | |
902 | void wxLogTrace(const char* formatString, ... ); | |
903 | void wxVLogTrace(const char* formatString, va_list argPtr); | |
904 | //@} | |
905 | ||
906 | /** @ingroup group_funcmacro_log */ | |
907 | //@{ | |
908 | /** | |
909 | Like wxLogDebug(), trace functions only do something in debug builds and | |
910 | expand to nothing in the release one. The reason for making it a separate | |
911 | function is that usually there are a lot of trace messages, so it might | |
912 | make sense to separate them from other debug messages. | |
913 | ||
914 | In this version of wxLogTrace(), trace messages can be separated into | |
915 | different categories and calls using this function only log the message if | |
916 | the given @a mask is currently enabled in wxLog. This lets you selectively | |
917 | trace only some operations and not others by enabling the desired trace | |
918 | masks with wxLog::AddTraceMask() or by setting the | |
919 | @ref overview_envvars "@c WXTRACE environment variable". | |
920 | ||
921 | The predefined string trace masks used by wxWidgets are: | |
922 | ||
923 | @beginDefList | |
924 | @itemdef{ wxTRACE_MemAlloc, Trace memory allocation (new/delete) } | |
925 | @itemdef{ wxTRACE_Messages, Trace window messages/X callbacks } | |
926 | @itemdef{ wxTRACE_ResAlloc, Trace GDI resource allocation } | |
927 | @itemdef{ wxTRACE_RefCount, Trace various ref counting operations } | |
928 | @itemdef{ wxTRACE_OleCalls, Trace OLE method calls (Win32 only) } | |
929 | @endDefList | |
930 | ||
931 | @note Since both the mask and the format string are strings, this might | |
932 | lead to function signature confusion in some cases: if you intend to | |
933 | call the format string only version of wxLogTrace(), add a "%s" | |
934 | format string parameter and then supply a second string parameter for | |
935 | that "%s", the string mask version of wxLogTrace() will erroneously | |
936 | get called instead, since you are supplying two string parameters to | |
937 | the function. In this case you'll unfortunately have to avoid having | |
938 | two leading string parameters, e.g. by adding a bogus integer (with | |
939 | its "%d" format string). | |
940 | ||
941 | @header{wx/log.h} | |
942 | */ | |
943 | void wxLogTrace(const char* mask, const char* formatString, ... ); | |
944 | void wxVLogTrace(const char* mask, | |
945 | const char* formatString, | |
946 | va_list argPtr); | |
947 | //@} | |
948 | ||
949 | /** @ingroup group_funcmacro_log */ | |
950 | //@{ | |
951 | /** | |
952 | Like wxLogDebug(), trace functions only do something in debug builds and | |
953 | expand to nothing in the release one. The reason for making it a separate | |
954 | function is that usually there are a lot of trace messages, so it might | |
955 | make sense to separate them from other debug messages. | |
956 | ||
957 | This version of wxLogTrace() only logs the message if all the bits | |
958 | corresponding to the @a mask are set in the wxLog trace mask which can be | |
959 | set by calling wxLog::SetTraceMask(). This version is less flexible than | |
960 | wxLogDebug(const char*,const char*,...) because it doesn't allow defining | |
961 | the user trace masks easily. This is why it is deprecated in favour of | |
962 | using string trace masks. | |
963 | ||
964 | The following bitmasks are defined for wxTraceMask: | |
965 | ||
966 | @beginDefList | |
967 | @itemdef{ wxTraceMemAlloc, Trace memory allocation (new/delete) } | |
968 | @itemdef{ wxTraceMessages, Trace window messages/X callbacks } | |
969 | @itemdef{ wxTraceResAlloc, Trace GDI resource allocation } | |
970 | @itemdef{ wxTraceRefCount, Trace various ref counting operations } | |
971 | @itemdef{ wxTraceOleCalls, Trace OLE method calls (Win32 only) } | |
972 | @endDefList | |
973 | ||
974 | @header{wx/log.h} | |
975 | */ | |
976 | void wxLogTrace(wxTraceMask mask, const char* formatString, ... ); | |
977 | void wxVLogTrace(wxTraceMask mask, const char* formatString, va_list argPtr); | |
978 | //@} | |
979 | ||
980 | /** @ingroup group_funcmacro_log */ | |
981 | //@{ | |
982 | /** | |
983 | The right functions for debug output. They only do something in debug mode | |
984 | (when the preprocessor symbol @c __WXDEBUG__ is defined) and expand to | |
985 | nothing in release mode (otherwise). | |
986 | ||
987 | @header{wx/log.h} | |
988 | */ | |
989 | void wxLogDebug(const char* formatString, ... ); | |
990 | void wxVLogDebug(const char* formatString, va_list argPtr); | |
991 | //@} | |
992 | ||
993 | /** @ingroup group_funcmacro_log */ | |
994 | //@{ | |
995 | /** | |
996 | Messages logged by this function will appear in the statusbar of the | |
997 | @a frame or of the top level application window by default (i.e. when using | |
998 | the second version of the functions). | |
999 | ||
1000 | If the target frame doesn't have a statusbar, the message will be lost. | |
1001 | ||
1002 | @header{wx/log.h} | |
1003 | */ | |
1004 | void wxLogStatus(wxFrame* frame, const char* formatString, ... ); | |
1005 | void wxVLogStatus(wxFrame* frame, const char* formatString, va_list argPtr); | |
1006 | void wxLogStatus(const char* formatString, ... ); | |
1007 | void wxVLogStatus(const char* formatString, va_list argPtr); | |
1008 | //@} | |
1009 | ||
1010 | /** @ingroup group_funcmacro_log */ | |
1011 | //@{ | |
1012 | /** | |
1013 | Mostly used by wxWidgets itself, but might be handy for logging errors | |
1014 | after system call (API function) failure. It logs the specified message | |
1015 | text as well as the last system error code (@e errno or @e ::GetLastError() | |
1016 | depending on the platform) and the corresponding error message. The second | |
1017 | form of this function takes the error code explicitly as the first | |
1018 | argument. | |
1019 | ||
1020 | @see wxSysErrorCode(), wxSysErrorMsg() | |
1021 | ||
1022 | @header{wx/log.h} | |
1023 | */ | |
1024 | void wxLogSysError(const char* formatString, ... ); | |
1025 | void wxVLogSysError(const char* formatString, va_list argPtr); | |
1026 | //@} | |
1027 |