Log error and other information

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rasspass
Forum Newbie
Posts: 4
Joined: Mon Mar 14, 2011 12:20 pm

Log error and other information

Post by rasspass »

I need to know what is going in different stages of execution process. I am thinking to echo/print statements in in many different PHP files and write them into some text file. Is there a log file that I can customize it for my needs or is there a way to write to a text file? Please note that I have multiple PHP/HTML files that I need to trace and print message/status to a text file. Your suggestion is appreciated in advance.
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: Log error and other information

Post by danwguy »

I would create a function in a seperate php file to write to a text file and take input kinda of like this...

Code: Select all

function logerror($input)
{
$myFile = "errorfile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $input \n;
fwrite($fh, $stringData);
fclose($fh);
}
then you can call that function with whatever you want to input into it like this...

Code: Select all

$error1 = logerror(put your text here that you want to be input to that text file);
and viola you have a text file on your server that contains whatever you want to put into it.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Log error and other information

Post by Weirdan »

Post Reply