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!
Return Line of Code?
Moderator: General Moderators
Re: Return Line of Code?
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.
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?
Closest I can think of is __LINE__
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
-
imichaeldotorg
- Forum Newbie
- Posts: 2
- Joined: Wed Mar 26, 2008 8:28 am
Re: Return Line of Code?
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.
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?
You are better off doing something like this: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.
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';