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"

2
  • What role does the Apache tag play in this question? Are you using PHP's error_log feature or relying on Apache logging? Commented May 19, 2015 at 14:27
  • we are on relying on apache logging Commented May 20, 2015 at 8:00

4 Answers 4

1

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

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

Comments

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;

Comments

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.

Comments

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.

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.