ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:reference:logging

This is an old revision of the document!


Logging

Debugging

Debug Level Description
true Default
-1
-99
99
2 Use the datalogging object

The default logging behavior is to send all messages to STDOUT, but the behavior may be modified by either:

  1. Defining a constant ADODB_OUTP which holds the name of the function that overrides the standard value
  2. A variable $ADODB_OUTP which is globalized and achieves the same as above. This function can be dynamically changed.

Function Definition

The overriding function must accept 2 arguments:

  1. A String which contains the message
  2. A boolean which indicates whether to throw a newling. This may be discarded based on how the function works

Example

DEFINE ('ADODB_OUTP','myLogger');
 
function myLogger($msg,$discard)
{
    print "\nThis is my messsage: $msg";
} 

The ADOdataLoggingObject

When the debug level is true, any output is placed in an ADOdataLoggingObject, which must be extracted via an overriding ``ADODB_OUTP`` function. There are no internal methods for extracting and displaying the information. The messages are unformatted.

**
* 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 Monolog can be used directly with the ADOdataLoggingObject. in this example, we use it to create a classic text log from the ADOdb output.

use Monolog\Logger;
use Monolog\Handler\StreamHandler;
 
require '/dev/github/vendor/autoload.php';
 
 
/*
* Tags log messages with ADOdb
*/
$loggingObject = new \Monolog\Logger('ADOdb');
$loggingObject->pushHandler(new StreamHandler('/var/logs/adodb.log', Logger::WARNING));
 
 
function logMessage($message,$newline=false)
{
	print_r($message);
 
	$message = json_encode($message);
 
	global $loggingObject;
 
	$level = -1;
	switch ($level)
	{
		default:
		$loggingObject->log(Logger::WARNING,$message);
		break;
	}
}
 
 
DEFINE('ADODB_OUTP','logMessage').
DEFINE('ADODB_OUTP_OBJECT',1).
v5/reference/logging.1577754027.txt.gz · Last modified: 2019/12/31 02:00 by mnewnham