Jump to content

[MOD] Logging debug messages to database


MrBaseball34

Recommended Posts

First, create the ps_debug_table with the SQL below.

CREATE TABLE `ps_debug_table` (
   `line_id` INT(11) NOT NULL AUTO_INCREMENT,
   `proc_id` VARCHAR(100) NULL DEFAULT NULL,
   `debug_msg` TEXT NULL,
   `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
   PRIMARY KEY (`line_id`)
)
ENGINE=MyISAM
ROW_FORMAT=DEFAULT


Second, you need to add the DebugLog function to the Tools class in classes/Tools.php

 /**
 * Logs message to ps_debug_table
 *
 * @param $module string - module where error occured
 * @param $msg string    - message to log
 *
 * line_id column is an autoincrement 
 * timestamp column has default of current time_stamp
 */
 static public function DebugLog($_mod, $_msg) {
   Db::getInstance()->Execute("INSERT INTO `"._DB_PREFIX_."debug_table` 
                               (proc_id, debug_msg) VALUES ('$_mod', '$_msg')");
 }



Third, insert this flag into ps_configuration table using this SQL:
{Note, set value to 0 to turn off this logging feature}

INSERT INTO `ps_configuration` 
 (`name`, `value`, `date_add`, `date_upd`) 
VALUES 
 ('PS_LOG_DEBUG_TABLE', '1', '2010-08-25 00:00:00', '2010-08-25 00:00:00');



Next, in anywhere you want to log your debug messages, place this code before you need to log them:

 $debug_log = Configuration::get('PS_LOG_DEBUG_TABLE');



Then, when you want to log a debug message, all you have to do is this:

if($debug_log) { 
 $error_msg = "Msg: Problem with SQL -- ".$sql." : ".mysql_error();
 Tools::DebugLog(__CLASS__." (".__LINE__.")", $error_msg); 
}

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...