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.

1
  • No. I was never able to find a solution to this problem. Commented Apr 28, 2014 at 15:16

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.