1

I'm attempting to write all of my PHP errors to a log file. I'm interested in including not just the line number, but also the specific line of code associated with that line number. This is the code I have so far. What would I have to add/change in order to report the problematic lines of code?

error_reporting(E_ALL);
ini_set('html_errors', 1);
ini_set("log_errors", 1);
ini_set("track_errors", 1);
ini_set("error_log", "./php-error.log");
4
  • debug_backtrace() & error_get_last() Commented Dec 10, 2014 at 3:13
  • I'm not sure how I would integrate those with the log's output. I tried adding "error_log(print_r(debug_backtrace(), true));", but that just gave a blank array. What am I doing wrong? Thanks! Commented Dec 10, 2014 at 3:28
  • Look more into error_get_last(). Commented Dec 10, 2014 at 3:29
  • I've looked into the documentation and tried adding it to my code, but I'm still not seeing how I can get it to report the actual line of code that's throwing the notice (I'm mainly dealing with undefined constant/variable issues). Commented Dec 10, 2014 at 3:44

1 Answer 1

1

There is no solution to automatically print the line of code. You can however get the file and line number using debug_backtrace(). Then you can read the file yourself and find the right line and print it.

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

1 Comment

Ok, thanks! That's good to know, so I don't go off on a wild goose chase. :) The script I have already prints the line number, so I'll just copy-paste the code into Excel to find the problematic string of code.

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.