I’m having some difficulty understanding Yii’s error logging mechanism. I’ve got the debug set to false in index.php:
defined(‘YII_DEBUG’) or define(‘YII_DEBUG’, false);
I’ve enabled the ‘log’ module in my config\main as per the below:
'log' => array(
'class' => 'CLogRouter',
'routes' => array(
array(
'class' => 'CFileLogRoute',
'levels' => 'error, warning',
),
array(
'class' => 'CWebLogRoute',
),
),
),
Normally, this works fine. However, when there’s an error in the program, the log is displayed at the bottom of the page on the production site, which is a security risk as it includes the database query information.
How do I disable the display of this log (while retaining a copy of the log on the server) on the production server?
Disable the CWebLogRoute if debug is off:
array(
'class'=>'CWebLogRoute',
'enabled'=>defined('YII_DEBUG'),
),
huanito
(Jonnykent)
October 3, 2011, 9:58pm
5
Disable the CWebLogRoute if debug is off:
array(
'class'=>'CWebLogRoute',
'enabled'=>defined('YII_DEBUG'),
),
There’s a minor gotcha there since YII_DEBUG is always defined in yiibase like this
defined(‘YII_DEBUG’) or define(‘YII_DEBUG’,false);
and this test, placed anywhere after the line in the index call to
Yii::createWebApplication($config)->run();
will always show YII_DEBUG as defined, no matter that it is defined by define(‘YII_DEBUG’,false);
if (defined('YII_DEBUG'))
echo "defined!";
else
echo " NOT defined!";
tri
(tri - Tommy Riboe)
October 3, 2011, 10:15pm
6
If you don’t define YII_DEBUG, Yii will do it in YiiBase.php:
defined('YII_DEBUG') or define('YII_DEBUG',false);
Test for true instead. This should work
'enabled'=>YII_DEBUG,
(not tested)
/Tommy
huanito
(Jonnykent)
October 5, 2011, 5:20am
7
tri:
If you don’t define YII_DEBUG, Yii will do it in YiiBase.php:
defined('YII_DEBUG') or define('YII_DEBUG',false);
Test for true instead. This should work
'enabled'=>YII_DEBUG,
(not tested)
/Tommy
Thanks Tommy. I was just pointing out the logical error and leaving the solution as an exercise.