Yii 1.1: How to log context information to logger (session id, user, ...)

5 followers

Logging context information (session, user, ...) to the logfile can be of great help tracking down problems with specific users.

This requires Yii 1.0.6

config/main.php

<?php
return array(
    // ... 
    'preload'=>array('log', 'session'),
 
    // ...
    'components'=>array(
        // ... 
        'log'=>array(
        'class'=>'CLogRouter',
        'routes'=>array(
            array(
                'class'=>'CWebLogRoute',
                'levels'=>'trace,info,error,warning',
                'filter' => array(
                    'class' => 'CLogFilter',
                    'prefixSession' => true,
                    'prefixUser' => false,
                    'logUser' => false,
                    'logVars' => array(),
                ),
            ),
        ),

You could also extend CLogFilter to do your own log message decoration.

Links ΒΆ

Russian Version

Be the first person to leave a comment

Please to leave your comment.

Write new article
  • Written by: olafure
  • Updated by: ajsharma
  • Category: Tutorials
  • Yii Version: 1.1
  • Votes: +2
  • Viewed: 11,380 times
  • Created on: Jun 5, 2009
  • Last updated: May 6, 2012
  • Tags: Logging