Page 1 of 1
Return Line of Code?
Posted: Wed Mar 26, 2008 8:30 am
by imichaeldotorg
I'm working on a script where I would like to be able to print the currently executing line of PHP code in a log. Is there an easy way to retrieve this information? For instance, I'd like a logging funciton to be able to out put "MySQL Query exceuted on Line 3432".
Thanks!
Re: Return Line of Code?
Posted: Wed Mar 26, 2008 9:56 am
by Inkyskin
To be honest, you dont really want to be logging every bit of code executed - it'll double the execution time, and provide no real benefit. MySQL however will log every query it runs (If it's set up to in the config).
You can log mysql commands with PHP to file file, but you might be better off just outputting that info into a html comment to view at the bottom of your page. If you start logging those in a file its going to get huge pretty quickly.
Re: Return Line of Code?
Posted: Wed Mar 26, 2008 9:56 am
by pickle
Closest I can think of is __LINE__
Re: Return Line of Code?
Posted: Wed Mar 26, 2008 10:35 am
by imichaeldotorg
I'm aware I don't want to be doing this in a production environment, yeah.
What I want is my error logging function to have a CRAZYHIGHDEBUG mode that will dump the error message and line number for specific debugging purposes. __LINE__ seems to work for now. Thanks.
Re: Return Line of Code?
Posted: Wed Mar 26, 2008 12:48 pm
by hawleyjr
imichaeldotorg wrote:I'm aware I don't want to be doing this in a production environment, yeah.
What I want is my error logging function to have a CRAZYHIGHDEBUG mode that will dump the error message and line number for specific debugging purposes. __LINE__ seems to work for now. Thanks.
You are better off doing something like this:
Code: Select all
define('OUTPUT_LINE_INFO',TRUE);
echo 'my house';
function test(){
if( OUTPUT_LINE_INFO === TRUE ){
echo 'In Function: ' __FUNCTION__;
}
return 'Blah';
}
test();
...
more code
...
if( OUTPUT_LINE_INFO === TRUE ){
echo 'Execute Line Number: ' __LINE__ . ' In File: ' . __FILE__;
}
echo 'End';