Yii Framework Forum: Tip: how to specify a different log file for tests - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Tip: how to specify a different log file for tests Easy solution to file permission problem Rate Topic: -----

#1 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 17 October 2010 - 03:56 PM

If you want to write file logging output to a separate log file during tests, thus avoiding the potential problem of a different user account lacking write permission to the log file, you can add string key(s) to the 'routes' array.

Remember to add corresponding key(s) in the main configuration, thus allowing mergeArray() to replace the existing route declaration(s).

return CMap::mergeArray(
  require(dirname(__FILE__).'/main.php'),
  array(
    'components'=>array(
      ...
      'log'=>array(
        'routes'=>array(
          'stdlog' => array(
            'class'=>'CFileLogRoute',
            'logFile'=>'test.log',
            //'categories'=>'system.*',
          'otherlog' => array(
            'class'=>'CFileLogRoute',
            'logFile'=>'other.log',
            'categories'=>'my_category.*',
          ),
          ...

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
2

#2 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 18 October 2010 - 02:36 AM

This looks interesting somehow - but i don't understand how you use the array keys to prevent permission problems. Could you please explain a little more?
0

#3 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 18 October 2010 - 06:41 AM

View PostMike, on 18 October 2010 - 02:36 AM, said:

This looks interesting somehow - but i don't understand how you use the array keys to prevent permission problems. Could you please explain a little more?


With the default 644 file permission, only the file owner will have write access. The web server process doesn't normally use the same account as a command line user. Of course, it's possible to remove any existing log file before and after a (command line) test session.

I decided to work around the problem by switching to a different log file name in the test configuration file log route. The easiest way to suspend the main configuration log route would be to have the test configuration replace it. For this to happen, the key has to be of string type, not implicit numeric type. The latter will be renumbered by mergeArray() instead of replacing any existing key.

/Tommy

This post has been edited by tri: 18 October 2010 - 06:48 AM

Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
1

#4 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 18 October 2010 - 07:17 AM

I see, nice trick.
0

#5 User is offline   Bhaumik 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 22-July 11

Posted 02 September 2011 - 08:01 AM

How do i write the log in to the particular file?
anybody help?

i'd like to generate custom log on the particular controller's action called. so how do i write the custom log file for this?
0

#6 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 02 September 2011 - 08:56 AM

View PostBhaumik, on 02 September 2011 - 08:01 AM, said:

How do i write the log in to the particular file?
anybody help?

i'd like to generate custom log on the particular controller's action called. so how do i write the custom log file for this?


You can specify a category in the call to Yii::log().

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#7 User is offline   Bhaumik 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 22-July 11

Posted 05 September 2011 - 02:49 AM

How do i get all the log data in the particular file?

i've get only the current log only.

Can anyone help?


print_r($logger->getLogs('info', 'mytest'));

it shows only current log not past.
0

#8 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 05 September 2011 - 05:14 AM

View PostBhaumik, on 05 September 2011 - 02:49 AM, said:

...
it shows only current log not past.


Your question is not related to the tip this thread is about. Please start a new thread preferrably in "General discussion for Yii 1.1".

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users