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 03:17] – mnewnham | v5:reference:logging [2024/01/09 11:14] (current) – Remove duplicated information described under Debug Mode dregad | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Logging ====== | ====== Logging ====== | ||
- | ADOdb provides an internal debugging system that exposes the SQL commands used to execute a command, as well as other messages that can provide guidance when, for example, trying to establish a connection to the database. The earliest that debugging can be started is after instantiating the driver but before connection. In its simplest usage, debugging is enabled as follows: | ||
- | <code php> | + | 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. |
- | include '/ | + | |
- | $db = newAdoConnection(' | + | The earliest that debugging can be started is after instantiating the driver but before connection. |
- | /* | + | ===== Usage ===== |
- | * Initialize debugging | + | |
- | */ | + | |
- | $db-> | + | |
- | $db-> | + | Please refer to [[v5: |
- | </ | + | |
- | This might produce output something like: | ||
- | < | ||
- | -----< | ||
- | (mysqli): select * from usersx | ||
- | |||
- | -----< | ||
- | Query: select * from usersx failed. Table ' | ||
- | 1146: Table ' | ||
- | ADOConnection._Execute(select * from usersx, false)% line 1313, file: C: | ||
- | ADOConnection.Execute(select * from usersx)% line 46, file: C: | ||
- | </ | ||
- | |||
- | The output is suitable for viewing in a browser, with messages from the database driver as well as backtrace data if there are problems. Note that debugging can be switched on and off during code execution as required. | ||
- | |||
- | ===== Alternative Debugging Levels ===== | ||
- | The following alternative levels are available. Each produces a slightly different output. | ||
- | |||
- | ^ Debug Level ^ Description | ||
- | |true | ||
- | |-1 |The most minimal logging level. Formatted as the default option, but does not include backtrace data or any ADOdb debugging/ | ||
- | |-99 |Adds ADOdb messages to the above format, but no backtrace data | | ||
- | |99 |The logging equivalent of **true** | ||
- | |2 |Use the datalogging object as described below| | ||
- | | ||
===== Overriding The Default Logging Function ===== | ===== Overriding The Default Logging Function ===== | ||
Line 61: | Line 31: | ||
</ | </ | ||
- | ===== The ADOdataLoggingObject ===== | ||
- | From ADOdb Version 5.22, the Data Logging Object may be used to provide a much more granular control of messages, by also including elements such as logging level and error numbers in the debug output. There are no internal methods for extracting and displaying the information, | ||
- | The logging object is described below | ||
- | |||
- | <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, or any message | ||
- | * deliberately pushed into the object | ||
- | */ | ||
- | 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> | ||
- | |||
- | |||
- | DEFINE(' | ||
- | DEFINE(' | ||
- | |||
- | use Monolog\Logger; | ||
- | use Monolog\Handler\StreamHandler; | ||
- | |||
- | require '/ | ||
- | |||
- | /* | ||
- | * Tags log messages with ADOdb | ||
- | */ | ||
- | $loggingObject = new \Monolog\Logger(' | ||
- | $loggingObject-> | ||
- | |||
- | |||
- | /** | ||
- | * Override function for logging | ||
- | * | ||
- | * @param | ||
- | * @param | ||
- | * @return void | ||
- | */ | ||
- | function logMessage($obj, | ||
- | { | ||
- | global $loggingObject; | ||
- | $message = sprintf(' | ||
- | |||
- | $loggingObject-> | ||
- | |||
- | } | ||
- | </ |
v5/reference/logging.1577758624.txt.gz · Last modified: 2019/12/31 03:17 by mnewnham