Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Message Log

$
0
0
Hi Dear,
How can i change formate message in cLogRoute, I want add Ip address and username and change date format,

format date in database is second, i want save local time in database,
I create separe class file in protext/extension
class LogDb   extends CDbLogRoute
{
    protected function formatLogMessage($message, $level, $category, $time)
    {
//        if ($time === null)
//            $time = time();

          $message= $_SERVER['REMOTE_ADDR']. Yii::app()->user->name.$message;

//        return date('Y/m/d H:i:s',$time)." [$level] [$category] $message\n";

        return @date( 'M d H:i:s') . ' [' . sprintf( '%-30s', $category ) . '] ' . ': <' . $level . '> ' . $message . PHP_EOL;
    }
}

and in main.php
            'log'=>array(
                'class'=>'CLogRouter',
                'routes'=>array(
                    array(
                        'class'=>'CDbLogRoute',
                    )   ,
                    array(
                        'class'=>'application.extensions.LogDb',
                        'autoCreateLogTable'=>true,
                        'connectionID'=>'db',
//                        'logTableName'=>'log_yii2',
//                        'enabled'=>true,
                        'levels'=>'error, warning',
//                        'logFile' => 'Log',
                    ),

but message in database not changed!!!

tanks for attension

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>