wxlogwxlog class defines the interface for the log targets used by wxwidgets logging functions as explained in the wxlog overview. the only situations when you need to directly use this class is when you want to derive your own log target because the existing ones don't satisfy your needs. another case is if you wish to customize the behaviour of the standard logging classes (all of which respect the wxlog settings): for example, set which trace messages are logged and which are not or change (or even remove completely) the timestamp on the messages. otherwise, it is completely hidden behind the wxlogxxx() functions and you may not even know about its existence. see log overview for the descriptions of wxwidgets logging facilities. derived from no base class include files <wx/log.h> function groups
global functions
global functionsthe functions in this section work with and manipulate the active log target. the onlog() is called by the wxlogxxx() functions and invokes the dolog() of the active log target if any. get/set methods are used to install/query the current active target and, finally, dontcreateondemand() disables the automatic creation of a standard log target if none actually exists. it is only useful when the application is terminating and shouldn't be used in other situations because it may easily lead to a loss of messages.
onlog
logging functionsthere are two functions which must be implemented by any derived class to actually process the log messages: dolog and dologstring. the second function receives a string which just has to be output in some way and the easiest way to write a new log target is to override just this function in the derived class. if more control over the output format is needed, then the first function must be overridden which allows to construct custom messages depending on the log level or even do completely different things depending on the message severity (for example, throw away all messages except warnings and errors, show warnings on the screen and forward the error messages to the user's (or programmer's) cell phone - maybe depending on whether the timestamp tells us if it is day or night in the current time zone). there also functions to support message buffering. why are they needed? some of wxlog implementations, most notably the standard wxloggui class, buffer the messages (for example, to avoid showing the user a zillion of modal message boxes one after another -- which would be really annoying). flush() shows them all and clears the buffer contents. this function doesn't do anything if the buffer is already empty.
customizationthe functions below allow some limited customization of wxlog behaviour without writing a new log target class (which, aside of being a matter of several minutes, allows you to do anything you want). the verbose messages are the trace messages which are not disabled in the release mode and are generated by wxlogverbose. they are not normally shown to the user because they present little interest, but may be activated, for example, in order to help the user find some program problem. as for the (real) trace messages, their handling depends on the settings of the (application global) trace mask. there are two ways to specify it: either by using settracemask and gettracemask and using wxlogtrace which takes an integer mask or by using addtracemask for string trace masks. the difference between bit-wise and string trace masks is that a message using integer trace mask will only be logged if all bits of the mask are set in the current mask while a message using string mask will be logged simply if the mask had been added before to the list of allowed ones. for example,
// wxtraceolecalls is one of standard bit masks wxlogtrace(wxtracerefcount | wxtraceolecalls, "active object ref count: %d", nref);will do something only if the current trace mask contains both wxtracerefcount and wxtraceole, but
// wxtrace_olecalls is one of standard string masks wxlogtrace(wxtrace_olecalls, "ifoo::bar() called");will log the message if it was preceded by
wxlog::addtracemask(wxtrace_olecalls);using string masks is simpler and allows to easily add custom ones, so this is the preferred way of working with trace messages. the integer trace mask is kept for compatibility and for additional (but very rarely needed) flexibility only. the standard trace masks are given in wxlogtrace documentation. finally, the wxlog::dolog() function automatically prepends a time stamp to all the messages. the format of the time stamp may be changed: it can be any string with % specifications fully described in the documentation of the standard strftime() function. for example, the default format is "[%d/%b/%y %h:%m:%s] " which gives something like "[17/sep/98 22:10:16] " (without quotes) for the current date. setting an empty string as the time format disables timestamping of the messages completely. nb: timestamping is disabled for visual c++ users in debug builds by default because otherwise it would be impossible to directly go to the line from which the log message was generated by simply clicking in the debugger window on the corresponding error message. if you wish to enable it, please use settimestamp explicitly.
addtracemask
wxlog::addtracemaskstatic void addtracemask(const wxstring& mask) add the mask to the list of allowed masks for wxlogtrace. see also
wxlog::cleartracemasksstatic void cleartracemasks() removes all trace masks previously set with addtracemask. see also
wxlog::gettracemasksstatic const wxarraystring & gettracemasks() returns the currently allowed list of string trace masks. see also
wxlog::onlogstatic void onlog(wxloglevel level, const char * message) forwards the message at specified level to the dolog() function of the active log target if there is any, does nothing otherwise.
wxlog::getactivetargetstatic wxlog * getactivetarget() returns the pointer to the active log target (may be null).
wxlog::setactivetargetstatic wxlog * setactivetarget(wxlog * logtarget) sets the specified log target as the active one. returns the pointer to the previous active log target (may be null). to suppress logging use a new instance of wxlognull not null. if the active log target is set to null a new default log target will be created when logging occurs.
wxlog::suspendstatic void suspend() suspends the logging until resume is called. note that the latter must be called the same number of times as the former to undo it, i.e. if you call suspend() twice you must call resume() twice as well. note that suspending the logging means that the log sink won't be be flushed periodically, it doesn't have any effect if the current log target does the logging immediately without waiting for flush to be called (the standard gui log target only shows the log dialog when it is flushed, so suspend() works as expected with it). see also
wxlog::resumestatic void resume() resumes logging previously suspended by a call to suspend. all messages logged in the meanwhile will be flushed soon.
wxlog::dologvirtual void dolog(wxloglevel level, const wxchar *msg, time_t timestamp) called to process the message of the specified severity. msg is the text of the message as specified in the call of wxlogxxx() function which generated it and timestamp is the moment when the message was generated. the base class version prepends the timestamp to the message, adds a prefix corresponding to the log level and then calls dologstring with the resulting string.
wxlog::dologstringvirtual void dologstring(const wxchar *msg, time_t timestamp) called to log the specified string. the timestamp is already included into the string but still passed to this function. a simple implementation may just send the string to stdout or, better, stderr.
wxlog::dontcreateondemandstatic void dontcreateondemand() instructs wxlog to not create new log targets on the fly if there is none currently. (almost) for internal use only: it is supposed to be called by the application shutdown code. note that this function also calls cleartracemasks.
wxlog::flushvirtual void flush() shows all the messages currently in buffer and clears it. if the buffer is already empty, nothing happens.
wxlog::flushactivestatic void flushactive() flushes the current log target if any, does nothing if there is none. see also
wxlog::setverbosestatic void setverbose(bool verbose = true) activates or deactivates verbose mode in which the verbose messages are logged as the normal ones instead of being silently dropped.
wxlog::getverbosestatic bool getverbose() returns whether the verbose mode is currently active.
wxlog::setloglevelstatic void setloglevel(wxloglevel loglevel) specifies that log messages with level > loglevel should be ignored and not sent to the active log target.
wxlog::getloglevelstatic wxloglevel getloglevel() returns the current log level limit.
wxlog::setrepetitioncountingstatic void setrepetitioncounting(bool repetcounting = true) enables logging mode in which a log message is logged once, and in case exactly the same message successively repeats one or more times, only the number of repetitions is logged.
wxlog::getrepetitioncountingstatic bool getrepetitioncounting() returns whether the repetition counting mode is enabled.
wxlog::settimestampvoid settimestamp(const char * format) sets the timestamp format prepended by the default log targets to all messages. the string may contain any normal characters as well as % prefixed format specificators, see strftime() manual for details. passing a null value (not empty string) to this function disables message timestamping.
wxlog::gettimestampconst char * gettimestamp() const returns the current timestamp format string.
wxlog::settracemaskstatic void settracemask(wxtracemask mask) sets the trace mask, see customization section for details.
wxlog::gettracemaskreturns the current trace mask, see customization section for details.
wxlog::isallowedtracemaskstatic bool isallowedtracemask(const wxchar *mask) returns true if the mask is one of allowed masks for wxlogtrace. see also: addtracemask, removetracemask
wxlog::removetracemaskstatic void removetracemask(const wxstring& mask) remove the mask from the list of allowed masks for wxlogtrace. see also: addtracemask
|