I got fed up writing several lines of code in order to capture certain information or write it to a file, so I developed the "Simple Debug Tool'. With one line of code at the appropriate point, I can leave messages, record the value of variables and the content of arrays.
Whether you're trying to debug the controller or model files on the catalog or the admin side of your mod, just a simple line of code puts all the information you're looking for into a log file where you can easily check what's happening.
This simple modification extends the "Log" class and add two new methods:
Code: Select all
$this->log->debug($output);
$this->log->resetDebug()
$this->log->debug($output)
This line of code writes $output to a file (system/logs/debug.txt). $output can be a string, a variable or an array and can be helpful in debugging a script that is giving unexpected results. Simply add the line at an appropriate point in the script eg.
Code: Select all
// (Adds the string to the log)
$this->log->debug('I have reached "X" point in the script');
// (Adds the content of the variable $language_id to the log)
$this->log->debug($language_id);
// (Adds the content of the POSTed variable 'status' to the log)
$this->log->debug($this->request->post['status']);
// (Adds the content of the complete POST array to the log)
$this->log->debug($this->request->post);
// (Adds the content of the session variable 'user_id' to the log)
$this->log->debug($this->session->data['user_id']);
// (Adds the selected database data to the log)
$this->log->debug($query->rows);
You can also combine two or more elements to provide the information you need. For example, if your Mysql(i) query is returning an unexpected result, you can test the actual query that is being sent:
Code: Select all
$this->log->debug("SELECT DISTINCT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "'");
Code: Select all
2015-02-06 13:20:58 - SELECT DISTINCT * FROM oc_product p LEFT JOIN oc_product_description pd ON (p.product_id = pd.product_id) WHERE p.product_id = '30' AND pd.language_id = '1'
You can use an optional second parameter to provide a "label" for the output eg:
Code: Select all
$this->log->debug('The complete POST array', $this->request->post);
Code: Select all
$this->log->debug('The complete POST array');.
$this->log->debug($this->request->post);
Output
The following piece of code:
Code: Select all
$this->log->debug('Session Variables', $this->session->data);
Code: Select all
2015-02-06 09:57:44 - Session Variables
2015-02-06 09:57:44 - Array
(
[currency] => USD
[backup_scheduled_date] =>
[user_id] => 1
[token] => 02a3b5fcb99d883713d8d19fbec3bf11
)
Simply empties the log file so you don't have to scroll to the end of a long file if you haven't deleted previous entries.
Available Now
Get it from here: http://www.opencart.com/index.php?route ... n_id=20809