print to a log file

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
johnhelen
Forum Commoner
Posts: 45
Joined: Mon Feb 19, 2007 9:17 pm

print to a log file

Post by johnhelen »

Hello

I can use echo to display something in the screen. However, how I can print something from a php script to a log file. Can I do that. I am using php with apache server

Many thanks
shoa
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

You might find the filesystem functions useful, http://de2.php.net/manual/en/ref.filesystem.php
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

The quickest way is to use the error_log() function.

By default this will send a string to the apache error log (your/path/to/apache/logs/error_log)

You can also make it do other things depending on the parameters you pass

error_log('Send me something',1,'myemail@example.com');

Would send the message to an email address.
johnhelen
Forum Commoner
Posts: 45
Joined: Mon Feb 19, 2007 9:17 pm

Thanks all

Post by johnhelen »

thanks all for your help
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

If what you are logging are not errors, don't log them to the error log.

Search around hotscripts or other code archives for loggin applications. There are a ton of them out there.
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

with the error_log() function you can send to any file you want, although it is called error_log you dont have to use it for that. If you feel more comfortable wrap it in a function called WriteToLog() or something.
Post Reply