From a38e10261647fbfd6ffd95a9f04a72529d80a962 Mon Sep 17 00:00:00 2001 From: Menno Dekker Date: Wed, 7 Nov 2012 15:19:00 +0100 Subject: [PATCH] dev: Allow logging of sql statements + parameters and Yii::trace('somemessage', 'vardump') to show in firebug / console when debug=2 for easier debugging --- application/core/LSYii_Application.php | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/application/core/LSYii_Application.php b/application/core/LSYii_Application.php index a6cc6eca4f2..21c62792c79 100644 --- a/application/core/LSYii_Application.php +++ b/application/core/LSYii_Application.php @@ -31,7 +31,35 @@ public function __construct($config = null) if (!file_exists($config)) { $config = APPPATH . 'config/config-sample' . EXT; + } else { + if(is_string($config)) { + $config = require($config); + } + } + + if ($config['config']['debug'] == 2) + { + // If debug = 2 we add firebug / console logging for all db queries and also output debug + // If you want to var_dump $someObject you could do: + // Yii::trace(CVarDumper::dumpAsString($someObject), 'vardump') + // This statement won't cause any harm or output when debug is 1 or 0 + $config['preload'][] = 'log'; + $config['components']['log'] = array( + 'class' => 'CLogRouter', + 'routes' => array( + array( + 'class' => 'CWebLogRoute', + // you can include more levels separated by commas... trace is shown on debug only + 'levels' => 'trace', + // you can include more separated by commas + 'categories' => 'vardump,system.db.*', + // show in firebug/console + 'showInFireBug' => true + ))); + $config['components']['db']['enableProfiling'] = true; + $config['components']['db']['enableParamLogging'] = true; } + parent::__construct($config); // Load the default and environmental settings from different files into self. $ls_config = require(APPPATH . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config-defaults.php'); @@ -49,7 +77,9 @@ public function __construct($config = null) } foreach ($settings as $key => $value) + { $this->setConfig($key, $value); + } } /**