How use CDbLogRouter?

Hello,

at the moment i’m using Yii Debug toolbar extension…but i neet to use it AND log errors into database.

This is my config file:





        'log' =>

            array(

                'class' => 'CLogRouter',

                'routes' => array(

			'class' => 'ext.yii-debug-toolbar.YiiDebugToolbarRoute'

		)

            ),



How can I do this? Thanks :)

You can add several routes, just make sure each route is in it’s own array.


'routes' => array(

   array(

      'class' => ...

   ),

   array(

      'class' => ...

   )

)

in /protected/config/main.php add this:

STEP 1:


array(

                    'class' => 'CDbLogRoute',

                    'connectionID' => 'db',

                    'autoCreateLogTable' => false,

                    'logTableName' => 'tbl_logger',

                    'levels' => 'info'

                    // nota:categories removed from me   

                    //'categories' => 'cclinica',

                ),

STEP 2:

make new table in yuor database named "tbl_logger" with 5 fields:


CREATE TABLE IF NOT EXISTS `tbl_logger` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `level` varchar(128) NOT NULL,

  `category` varchar(128) NOT NULL,

  `logtime` int(11) NOT NULL,

  `message` text NOT NULL,

  PRIMARY KEY (`id`)

) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

STEP 3:

In yuor code write where u want:


Yii::log($user . ' whit this IP:'. $ip .'blablabla...', 'info', 'level');

enjoy :)

Hello, thanks for reply.

@Paskuale, I’ve tried with your suggest but it does not works, sigh.





                if (1==1)

                {

                    Yii::log('Errore durante il salvataggio del reset', CLogger::LEVEL_INFO);

                    throw new CHttpException(500, 'Si è verificato un errore, riprova.');

                }



This return error 500, but the log table is empty…