-1

I want to save all script errors in a txt file, I know that there is a function to change the log file:

ini_set("error_log", "file path");

Is that function changing the error_log path in the php.ini?

Or it just log that PHP file errors to a specific file rather that the error_log file?

So for example if I have a file called 'file.php' and that file contains some PHP code, If an error occurs there it's saved to that custom files.

But for other PHP files, When an error occurs, It's saved to the default error_log file.

How to do that?

  • Have you tried it? Is this some way of trying to tell us that you tried using `ini_set("error_log", "...")` and it didn't work? Have you tried googling? 100% duplicate: https://stackoverflow.com/questions/3531703/how-to-log-errors-and-warnings-into-a-file – Xatenev Jul 07 '18 at 19:09
  • Possible duplicate of [How to log errors and warnings into a file?](https://stackoverflow.com/questions/3531703/how-to-log-errors-and-warnings-into-a-file) – Xatenev Jul 07 '18 at 19:10
  • 1
    Must be hard to try it and see what happens – Andreas Jul 07 '18 at 19:11
  • @Xatenev, I viewed that question twice, It's not answering my question –  Jul 07 '18 at 19:19
  • I googled my question and that question appeared , Before asking that question –  Jul 07 '18 at 19:19

1 Answers1

1

Take a look at PHP's built-in function error_log():

http://php.net/manual/en/function.error-log.php

It will give you a variety of options including the one you are after.

D. Simmons
  • 245
  • 1
  • 8
  • Yes but that's if I have the error message stored in a variable –  Jul 07 '18 at 19:21
  • If you cannot trap the errors programmatically then your original idea should work using ini_set() which is changing PHP configuration variables at runtime. After script execution, the original value in php.ini is preserved. – D. Simmons Jul 07 '18 at 19:26
  • Try ensuring the log file has write permissions? – D. Simmons Jul 08 '18 at 07:53