Page 1 of 1

print to a log file

Posted: Mon Mar 12, 2007 3:12 am
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

Posted: Mon Mar 12, 2007 3:17 am
by volka
You might find the filesystem functions useful, http://de2.php.net/manual/en/ref.filesystem.php

Posted: Mon Mar 12, 2007 3:57 am
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.

Thanks all

Posted: Mon Mar 12, 2007 6:51 pm
by johnhelen
thanks all for your help

Posted: Mon Mar 12, 2007 6:54 pm
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.

Posted: Mon Mar 12, 2007 7:27 pm
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.