FirePHP Logger for Yii Framework


I made this a few weeks ago. It is a Yii Framework extension which routes log messages to FirePHP.

Requirements

Installation

  1. Download and extract the “shiki” folder to your extensions directory. This is usually /protected/extensions.
  2. Download the FirePHP core class and put it somewhere in your /protected directory. I usually put these files in /protected/vendors.
  3. Modify your config file to include this LogRoute class and set the fbPath property to the path of fb.php. Use a Yii alias (e.g. application.vendors.FirePHPCore031.lib.FirePHPCore.fb):

config file code (e.g. /protected/config/main.php)

'log'=>array(
    'class'=>'CLogRouter',
    'routes'=>array(
        // the default (file logger)
        array(
            'class'=>'CFileLogRoute',
            'levels'=>'error, warning',
        ),
        // the FirePHP LogRoute
        array(
            'class' => 'ext.shiki.firePHPLogRoute.ShikiFirePHPLogRoute', // "ext" alias points to /protected/extensions
            'fbPath' => 'application.vendors.FirePHPCore031.lib.FirePHPCore.fb', // set path to fb.php
        ),
    ),
),

Usage

Once you’ve got the extension setup in the config, you can use Yii’s logging methods to log messages to FirePHP.

// logging an INFO message (arrays will work and looks awesome in FirePHP)
Yii::log(array('username' => 'Shiki', 'profiles' => array('twidl', 'twitter', 'facebook')), CLogger::LEVEL_INFO);

// logging a WARNING message
Yii::log("You didn't setup a profile, are you really a person?", CLogger::LEVEL_WARNING);

// logging with a CATEGORY (categories are displayed as "labels" in FirePHP -- just an additional info text)
Yii::log('Profile successfully created', CLogger::LEVEL_INFO, 'application.user.profiles');

// tracing simple text
Yii::trace('Loading application.user.profiles.ninja', 'application.user.profiles');

// logging an ERROR
Yii::log('We have successfully determined that you are not a person', CLogger::LEVEL_ERROR, 'Any category/label will work');