0

By changing /Cake/Log/Engine/Filelog.php's write function I can change "error.log" and "debug.log" file names.

Is there any way to change these file names without hacking CakePHP 2 core files.

3
  • why would you want to? they contain errors and debug information, seems fitting. You can create additional log files i.e. CakeLog::write('my_log', 'message'); and cake will create a log file called my_log) Commented Dec 23, 2012 at 21:54
  • Because there exists no size limitation. If I don't care for 2 weeks I had an error.log file which is 2 megabytes. I want to add date("d-m-Y) to file name. Commented Dec 23, 2012 at 22:01
  • you then should use similar approaches as logrotate does. moving its content into "error-x.log" files leaving the newest primary file as it is: name "error.log". you can do that with a crontask cronjob on a regular basis for example. no need to put this overhead into the application layer here. Commented Dec 23, 2012 at 22:19

5 Answers 5

2

As of CakePHP 2.4.0 this feature is added: http://bakery.cakephp.org/articles/markstory/2013/08/30/cakephp_2_4_0_is_ready

FileLogs can now have a max size and simple rotation configured.

Filelog class has file size limit and number of files to rotate.

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

Comments

1

In your comment above, you said that the reason you're wanting to change the names of these log files is because the files in question have no size limitations. The thing is: If you have an error log that is 2MB in size, then you've clearly got bigger fish to fry. As far as I know, there is no way to change those file names without hacking the core. If you're really worried about the size of those two log files, then you could setup a cronjob that checks the size of those two files every 24 hours. If the log file size is bigger than the predetermined limit that you've set, you could send an alert email to yourself. To be honest: The best approach to take is to test your application extensively beforehand so that any entry in those two files becomes a surprise instead of a routine.

Comments

0

There is no inbuilt config to get what you want. But you can easily make your custom logger class which extends FileLog and override the relevant function and use that.

Comments

0

in cake 3 you can set rotate config easily in /config/app.php

'Log' => [
     'error' => [
          'className' => 'Cake\Log\Engine\FileLog',
          'rotate'=>2,
           //other config

Comments

0

In CakePHP 2 you can change same configuration in /app/config/bootstrap.php:

CakeLog::config('debug', array(
    'engine' => 'File',
    'types' => array('notice', 'info', 'debug'),
    'file' => 'debug',
));
CakeLog::config('error', array(
    'engine' => 'File',`enter code here`
    'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
    'file' => 'error',
));

Comments

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.