| 2.3.4. Logging events with the vmLogger object |
| Prev | 2.3. Core Modules & their Functions, Environment Variables | Next |
|---|
VirtueMart allows logging events that occur during the execution
of the script. The global variable $vmLogger, which
is used for logging purposes is an object of the class
Log_display. This class is a child class of the Log
class, which is a PEAR extension.
You must declare
global $vmLogger;to be able to use this variable inside of a function.
"Logging" means to log a message to display them to the user.
While a function is executed (because its execution was triggered by
the variable $func) in the file
virtuemart_parser.php, the events are buffered.
When the function call has ended, the contents of the log are flushed
and all messages are displayed to the user in the order they were
added to the log: first in, first out.
After that implicit flushing is enabled - what means that you can log a message and it is printed into the HTML code where you call the log function.
Currently the Log_display class used by VM offers 9 log levels:
System is unusable (PEAR_LOG_EMERG)
Immediate action required (PEAR_LOG_ALERT)
Critical conditions (PEAR_LOG_CRIT), formatted by CSS style
log_crit
Error conditions (PEAR_LOG_ERR), formatted by CSS style
log_error
Warning conditions (PEAR_LOG_WARNING), formatted by CSS style
log_warning
Normal but significant (PEAR_LOG_NOTICE)
Informational (PEAR_LOG_INFO), formatted by CSS style
log_info
Debug-level messages (PEAR_LOG_DEBUG) formatted by CSS style
log_debug
Advice messages (PEAR_LOG_TIP, added for VM), formatted by
CSS style log_tip
Please note that Debug log entries are only shown to the user, when DEBUG is enabled by configuration.
To log an event, you can use a special function for each log level:
$vmLogger->emerg( 'My emergency message to the user' );
$vmLogger->alert( 'My alarm message to the user' );
$vmLogger->crit( 'My critical message to the user' );
$vmLogger->err( 'My error message to the user' ); // Mainly used to log errors in a function
$vmLogger->warning( 'My warning message to the user' ); // Mainly used to trigger warnings
$vmLogger->notice( 'My Notice to the user' );
$vmLogger->info( 'My informational message to the user' ); // Used to give success messages
$vmLogger->debug( 'My debug message to the user' ); // Only displayed when DEBUG is enabled
$vmLogger->tip( 'My advice to the user' ); // Used to display Advice messages to the user