4

I'm trying to ensure that CakePHP writes to a custom log file when my app is in production mode.

I'm writing to the log using the log method:-

$this->log($url, 'payment');

This work's fine when I'm in a development mode, but when I switch to production mode it no longer writes to the file (which is what I want it to do).

I've tried configuring a file logging option in bootstrap.php which is partially fixing the issue:-

CakeLog::levels(array('payment'));
CakeLog::config('payment', array(
    'engine' => 'FileLog',
    'types' => array('payment'),
    'file' => 'payment',
));

This now writes to the log file in production mode, but it is also writing other errors to my payment.log which I don't want in there.

I've tried reading through the docs but either it doesn't explain how to achieve this or I am misunderstanding it.

What am I doing wrong? Thanks for any help.

drmonkeyninja
  • 8,490
  • 4
  • 31
  • 59

1 Answers1

6

I think this may help you:

Call:

CakeLog::write('info', 'log msg', array('payments'));

Bootstrap:

CakeLog::config('payments', array(
    'engine' => 'FileLog',
    'types' => array('info'),
    'scopes' => array('payments')
));

As documentation describes, scopes are available in 2.2: http://book.cakephp.org/2.0/en/core-libraries/logging.html#logging-scopes

You tagged the question with cakephp 2.1. Maybe you just need to upgrade: http://book.cakephp.org/2.0/en/appendices/2-2-migration-guide.html

bremenkanp
  • 61
  • 2
  • Unfortunately I don't have the luxury of upgrading Cake for this project. I was hoping this is something that is doable in CakePHP 2.1. – drmonkeyninja Sep 09 '13 at 09:21