Skip to content

Commit

Permalink
dev: Allow logging of sql statements + parameters and Yii::trace('som…
Browse files Browse the repository at this point in the history
…emessage', 'vardump') to show in firebug / console when debug=2 for easier debugging
  • Loading branch information
mennodekker committed Nov 7, 2012
1 parent 41531ea commit a38e102
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions application/core/LSYii_Application.php
Expand Up @@ -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');
Expand All @@ -49,7 +77,9 @@ public function __construct($config = null)
}

foreach ($settings as $key => $value)
{
$this->setConfig($key, $value);
}
}

/**
Expand Down

8 comments on commit a38e102

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,

If we want to debug some var, and use vardump for this, it's very difficult to find vardump trace.

Maybe it's best to have an $config['config']['debugsql'] var.

And this can be set in config-default.php

@c-schmitz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we add debug sql info only on debug level 4?

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think debug SQL is dfferent from debug.
View possibility included in Yii to have some debug : notice/strict etc ...

But add a $config['config']['debugsql'] for sql debugging.

Carsten : are you OK if i move it trye to move it config-default.php ? I have to remove it from LSYii_Application.phpto have my own debug mode.

@c-schmitz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mennodekker This patch seems to have completely broken the installer. Can you have another look please? I think Shnoulle has a good idea with making this a separate config param.

@mennodekker
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

broken installer is fixed in 82fc410
config option that respects existing routes added in 61f4731

@Schnoulle, in console i now get two separate panels for vardump and sql log. not sure if it still is a problem with your custom logging, if you let me know your config i can maybe figure out a way to fix it

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Menno, I look to have a $categories var :)

@mennodekker
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way I tried to make it now is that you can have your own route with all params you like in your own config.php and the ones for debug / debugsql will be added to that instead of replacing it. So you can have the http://www.yiiframework.com/extension/yii-debug-toolbar/ for example, while for people who don't add that to their config have the console logging.

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,

Sorry, don't have time to review it.

But seems OK with : array_key_exists \o/ and the easy way to use debug mode :).
Now, just add some Yii::trace(CVarDumper::dumpAsString($anotherTest),'vardump') for "not dev user" purpose ;).

Please sign in to comment.