v5:reference:logging
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
v5:reference:logging [2019/12/31 02:00] – [Debugging] mnewnham | v5:reference:logging [2024/01/09 11:14] (current) – Remove duplicated information described under Debug Mode dregad | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Logging ====== | ====== Logging ====== | ||
- | ===== Debugging | + | ADOdb provides an internal debugging system that exposes the executed SQL commands, as well as other messages that can help when troubleshooting errors when, for example, trying to establish a connection to the database or an SQL statement fails. |
- | ^ Debug Level ^ Description | + | |
- | | true | Default | + | The earliest that debugging can be started is after instantiating the driver but before connection. |
- | | -1 | + | |
- | | -99 | | | + | ===== Usage ===== |
- | | 99 | + | |
- | | 2 | Use the datalogging object| | + | Please refer to [[v5: |
- | | + | |
- | ==== Overriding The Default Logging Function ==== | + | |
+ | ===== Overriding The Default Logging Function | ||
The default logging behavior is to send all messages to STDOUT, but the behavior may be modified by either: | The default logging behavior is to send all messages to STDOUT, but the behavior may be modified by either: | ||
- Defining a constant **ADODB_OUTP** which holds the name of the function that overrides the standard value | - Defining a constant **ADODB_OUTP** which holds the name of the function that overrides the standard value | ||
- A variable **$ADODB_OUTP** which is globalized and achieves the same as above. This function can be dynamically changed. | - A variable **$ADODB_OUTP** which is globalized and achieves the same as above. This function can be dynamically changed. | ||
- | === Function Definition === | + | === Function Definition ==== |
The overriding function must accept 2 arguments: | The overriding function must accept 2 arguments: | ||
- A String which contains the message | - A String which contains the message | ||
- | - A boolean which indicates whether to throw a newling. This may be discarded based on how the function works | + | - A boolean which indicates whether to throw a newline. This may be discarded based on how the function works |
- | === Example === | + | ==== Example |
<code php> | <code php> | ||
DEFINE (' | DEFINE (' | ||
Line 27: | Line 29: | ||
print " | print " | ||
} | } | ||
- | </ | ||
- | ==== The ADOdataLoggingObject ==== | ||
- | When the debug level is true, any output is placed in an ADOdataLoggingObject, | ||
- | |||
- | <code php> | ||
- | ** | ||
- | * An object in which to log/store activity data | ||
- | */ | ||
- | class ADODataLoggingObject | ||
- | { | ||
- | /* | ||
- | * The SQL statement(s) processed, if any | ||
- | */ | ||
- | public $sql; | ||
- | |||
- | /* | ||
- | * The bind data, if any | ||
- | */ | ||
- | public $inputArray; | ||
- | |||
- | /* | ||
- | * The database driver error | ||
- | */ | ||
- | public $errorNo = 0; | ||
- | |||
- | /* | ||
- | * The database driver error message | ||
- | */ | ||
- | public $errorMessage; | ||
- | |||
- | /* | ||
- | * The ADOdb Meta error number | ||
- | */ | ||
- | public $metaErrorNo = 0; | ||
- | |||
- | /* | ||
- | * The ADOdb Meta error message | ||
- | */ | ||
- | public $metaErrorMessage; | ||
- | |||
- | /* | ||
- | * The backtrace | ||
- | */ | ||
- | public $backTrace; | ||
- | |||
- | /* | ||
- | * An error level that can be set if required | ||
- | * default INFO | ||
- | */ | ||
- | public $errorLevel = LOG_INFO; | ||
- | } | ||
</ | </ | ||
- | ==== Using Monolog For Logging Data ==== | ||
- | The PHP standard logging class [[https:// | ||
- | <code php> | ||
- | use Monolog\Logger; | ||
- | use Monolog\Handler\StreamHandler; | ||
- | |||
- | require '/ | ||
- | |||
- | |||
- | /* | ||
- | * Tags log messages with ADOdb | ||
- | */ | ||
- | $loggingObject = new \Monolog\Logger(' | ||
- | $loggingObject-> | ||
- | |||
- | |||
- | function logMessage($message, | ||
- | { | ||
- | print_r($message); | ||
- | |||
- | $message = json_encode($message); | ||
- | |||
- | global $loggingObject; | ||
- | |||
- | $level = -1; | ||
- | switch ($level) | ||
- | { | ||
- | default: | ||
- | $loggingObject-> | ||
- | break; | ||
- | } | ||
- | } | ||
- | |||
- | |||
- | DEFINE(' | ||
- | DEFINE(' | ||
- | |||
- | </ |
v5/reference/logging.1577754027.txt.gz · Last modified: 2019/12/31 02:00 by mnewnham