2

I am trying to handle errors on my website. I logs each error in my log files, but I would like to know how to customize the message that is recorded in the log file.

For now, I get this message:

2013/09/30 10:08:59 [error] [exception.CException] exception 'CException' with message 'Error test' in myDomain.com\protected\controllers\SiteController.php:234

Can you help me?

3
  • you can use Yii::log($message, $level, $category); Commented Sep 30, 2013 at 10:48
  • Thank you for your answer, but i have a other question. How do you make for removing the "stack trace" ? Commented Sep 30, 2013 at 12:22
  • I think you can modify this line defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3); in your index.php file Commented Sep 30, 2013 at 14:25

1 Answer 1

2

For manual customization log messages you need to create your own LogRoute class. In your situation you need inherit class from CFileLogRoute and override method formatLogMessage (such in example):

class MyFileLogRoute extends CFileLogRoute{
    protected function formatLogMessage($message,$level,$category,$time)
    {
        //enter code here your custom message format
        return @date('Y/m/d H:i:s',$time)." [$level] [$category] $message\n";
    }
}

Than configure your configuration file:

       'log' => array(
           'class' => 'CLogRouter',
           'routes' => array(
               array(
                   'class' => 'MyFileLogRoute',
                   'levels' => 'error, warning, info',
                   'categories' => 'application.*',
                   'logPath' => dirname(__FILE__).'/../../../../../logs/',
               ),
               ...

And yes, @ragingprodigy is right: you can set define('YII_DEBUG', 0) or define('YII_TRACE_LEVEL', 0) in index.php to remove stack trace from log messages

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.