Plus Debug Logger

From EQdkp Plus
Jump to navigation Jump to search

General description

The Plus Debug Logger (PDL) is the central point for debug messages in 1.0 instead of the local solutions used by various developers in the current system. It performs the task of an error handler for php errors as well.

Usage

The PDL is initialised early in the common.php and can be globally reached by using the $pdl object. Every debug message is associated to a type. Predefined types are "unknown", "php_error", "sql_error", "sql_query", "pdc_query" and "pdh_error" but of course you can (and should if you want to log custom errors) also register your own types.

Register a new type

Example call:

$this->pdl->register_type("sql_error", null, array($this, 'psl_html_format_sql_error'), array(2,3), true);

The register_type function takes 4 parameters:

  • The name of the debug type you want to register, this must be unique
  • optional: plaintext output format function, used for file logging (an error should be in one line, timestamp and newline will be automatically added)
  • optional: html output format function, used to format the error on the bottom of the page
  • optional: debug level array (if your eqdkp system runs in one of the specified debug levels those errors will be shown on the bottom of the page)
  • optional: log to file, defaults to false.

Note: The html function is a method of the current object in this case, it could also be the name of a globally known function!

Log something

If you want to log something you just call the log method like this:

$this->pdl->log("sql_error", $sql, $error['message'], $error['code'], $dbname, $table_prefix);

The first parameter always has to be the log type, followed by an arbitrary number of other parameters, which will be stored and can be used in the output format functions.

Writing your own output format functions

An html output format function might look like this example:

function pdl_html_format_sql_error($log_entry){
  $text =  '<b>Query:</b>' . $log_entry['args'][0] . '<br /><br />
            <b>Message:</b>' . $log_entry['args'][1] . '<br /><br />
            <b>Code:</b>' . $log_entry['args'][2] . '<br />
            <b>Database:</b>' . $log_entry['args'][3] . '<br />
            <b>Table Prefix:</b>' . $log_entry['args'][4] . '<br />';
  return $text;
}

Whereas the passed $log_entry variable looks like this:

$log_entry['timestamp'] = TIMESTAMP;
$log_entry['args'] = array();

It contains an auto generated timestamp and an array containing the parameters passed to the log call.

Quick Debug

For Quick Debug a Variable, use the Debug function. If $variable is "backtrace", the output of debug_backtrace() will be shown.

 $this->pdl->debug($variable='backtrace', $die=false)

Set Deprecated Methods

Call the deprecated method and pass the name of the function you want to set deprecated.

$this->pdl->deprecated($name);