Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. | ||
--Rich Cook |
AFC Base is the base class of all AFC classes.
It must be instantiated in all your application in order to be able to use any AFC class.
The class offers some good (and standardized) utilities, such as afc_log() and afc_debug() that will help you develop your programs.
Since all AFC classes can reference an AFC Base, they gain the same flexibility and standardization in sending log and debug messages, and the application can give the user the ability to set the debug and info level he/she wants.
You can create a new instance of AFC Base by calling afc_new() and remember to free it before exiting with the standard call afc_delete()
AFC Base offers some utility functions that can be used inside any program taking advatages of AFC classes. As mentioned before, take a look at afc_log() afc_debug() and afc_log_fast() functions. But there are also some macro you should take under consideration. In this section we'll examine deeply AFC debugging and logging functions, to let you have a glance of what you can do with them.
AFC Base standardized the way feedback should be outputted to the user and/or developer, by giving always the same aspect on error/warning/log messages. This will ease the pain of understand what's going on in the backyard and helps better understanding the various aspect of a program.
All we're going to discuss here is already implemented on standard AFC (maybe, something is missing, but the main parts are already all there). All these things can apply to your own classes and applications too, without any problem.
A log message appears when something inside the application went wrong. AFC implement different levels of severity, from a simple message defined with AFC_LOG_MESSAGE to the critical almost-blocking error, defined with AFC_LOG_CRITICAL. Depending by the setting of the AFC Base in use, an AFC_LOG_CRITICAL error can cause the application to abort immediately. See afc_set_tag() for more info.
Loggin functions are described in deep detail on afc_log() and afc_log_fast() API documentation section. Here we'd like to introduce you some macro (based on afc_log() and afc_log_fast() respectively) that can ease you even more.
AFC_LOG (afc, level, error, descr, info)
AFC_LOG_FAST (afc, error)
AFC_LOG_FAST_INFO (afc, error, info)
Pointer to a valid (already allocated) AFC class.
Log message error level. See afc_log() for more info
Error code related to the problem enocuntered. Every app can use its own.
Textual description of the error enocuntered.
Optional string with additional info about the error.
To simple send debug messages to the user/developers, AFC Base offers two functions: afc_debug() and afc_debug_adv() Please refer to the afc_debug() and afc_debug_adv() API pages for in deep documentation about these functions. What we want to discuss here are two handy macros:
If debug level is set to AFC_DEBUG_EVENRYTHING, displays the current function name during program execution.
Writes a debug message on the standard error. Debug message level is defined by level and the message is stored in str.