v5:reference:logging
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
v5:reference:logging [2020/01/01 03:07] – [Developer Considerations] mnewnham | v5:reference:logging [2021/03/24 21:50] – mnewnham | ||
---|---|---|---|
Line 60: | Line 60: | ||
} | } | ||
</ | </ | ||
- | |||
- | ===== 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; | ||
- | } | ||
- | </ | ||
- | |||
- | ==== Available Constants ==== | ||
- | If the object logging is used, then the following constants are available. | ||
- | ^ Constant | ||
- | | ADODB_OUTP | ||
- | | ADODB_OUTP_OBJECT | ||
- | | ADODB_OUTP_MIN_LEVEL | ||
- | |||
- | ==== Behavior of existing debug mssage ==== | ||
- | Many drivers use the logging feature to pass state information, | ||
- | <code php> | ||
- | foreach($options as $k=>$v) { | ||
- | if ($this-> | ||
- | ADOconnection:: | ||
- | } | ||
- | $this-> | ||
- | } | ||
- | </ | ||
- | If object logging is enabled, each message will be automatically converted to a data logging object, with a logging level of **LOG_INFO**. | ||
- | ==== Change In Behavior Of ADG_OUTP ==== | ||
- | If the logging object is used then the first argument of the override function is an ADOdataLoggingObject | ||
- | <code php> | ||
- | logMessage(ADOdataLoggingObject $obj, bool $newline=false) {} | ||
- | </ | ||
- | ==== 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(ADOdataLoggingObject $obj, bool $newline=false) | ||
- | { | ||
- | global $loggingObject; | ||
- | $message = sprintf(' | ||
- | |||
- | $loggingObject-> | ||
- | |||
- | } | ||
- | </ | ||
- | |||
- | ===== Developer Considerations ===== | ||
- | When migrating a call to **ADOConection:: | ||
- | <code php> | ||
- | $ok = @db2_bind_param($stmtid, | ||
- | if (!$ok) | ||
- | { | ||
- | $this-> | ||
- | $this-> | ||
- | if ($this-> | ||
- | ADOConnection:: | ||
- | return false; | ||
- | } | ||
- | </ | ||
- | |||
- | We get an error something like "Bind failed: Invalid data type". But if we convert to an object, | ||
- | |||
- | <code php> | ||
- | $ok = @db2_bind_param($stmtid, | ||
- | if (!$ok) | ||
- | { | ||
- | $this-> | ||
- | $this-> | ||
- | if ($this-> | ||
- | { | ||
- | $obj = new ADOdataLoggingObject; | ||
- | $obj-> | ||
- | $obj-> | ||
- | $obj-> | ||
- | $obj-> | ||
- | $obj-> | ||
- | | ||
- | ADOConnection:: | ||
- | return false; | ||
- | } | ||
- | </ | ||
- | |||
- | produces a much more useful error | ||
v5/reference/logging.txt · Last modified: 2024/01/09 11:14 by dregad