1

We want to monitor all php errors. We can check all errors with error_log file. Error logs files become so heavy.

So it is very difficult to check errors in error_log file.

Could it possible to write php error_log file on date-wise example '19-05_2015_error.log'

or we can write error like "fetal.log" "notice.log"

nitin jain
  • 298
  • 6
  • 19

4 Answers4

1

You can absolutely do it in PHP. A popular logging library is Monolog.

Jake Opena
  • 1,475
  • 1
  • 11
  • 18
1

You can change the PHP config at beginning of your application, create the log file dynamically.

<?php

function logByDate(){
    $sPath = '/logs/application/PhpError_' . date('Y-m-d') . '.log';
    ini_set('error_log', $sPath);
}

// To validate only, it is not necessary
echo 'Actual log ' . ini_get('error_log') . PHP_EOL; 

logByDate(); //Call it at beginning

// To validate only, it is not necessary
echo 'Validate new log ' . ini_get('error_log') . PHP_EOL;
Sven R.
  • 1,049
  • 17
  • 24
Mauricio Florez
  • 1,112
  • 8
  • 14
0

To get logs in daily format (19-05_2015_error.log) you can use logrotate if you're on a UNIX stack (but it' a bit more complicated if you're on a Windows stack). There are some useful hints on controlling duplication and suppressing error messages.

Community
  • 1
  • 1
alimack
  • 611
  • 2
  • 9
  • 20
0

As far as I know, the mod_log_config module does not accept variables for file names so that excludes the most straightforward possibility. Apache-based solutions you can actually use include basically:

Said that, I think PHP has pretty good built-in logging. You can do exactly what you are asking for with the error_log() function (together with e.g. date('Y-m-d')). You can even define a different file for different error types. Sure, that will not capture errors that prevent PHP code from running (such as parse errors, request time-outs...) but you can set the error_log directive as fallback mechanism—these situations should be rare enough to keep the log file manageable.

One more thought: make sure your development box has full error reporting enabled (many devs use third-party bundles with default settings and happily write buggy code). It isn't normal to have so many logged errors in a production server.

Álvaro González
  • 142,137
  • 41
  • 261
  • 360