chiprivers Posted May 24, 2007 Share Posted May 24, 2007 I want to create a basic text file log of the processes performed by my script throughout a day. I think I can use fopen(), fwrite() and fclose() to do this but I have not used this before. So I have two questions, firstly, can I use these function? ie $target = fopen($fielName,a); fwrite($target,"text to write"); fclose($target); Secondly, if the file that I am trying to open does not exist, will it create the file! And lastly, is there a better way to do this? Quote Link to comment https://forums.phpfreaks.com/topic/52789-creating-a-log-file/ Share on other sites More sharing options...
MadTechie Posted May 24, 2007 Share Posted May 24, 2007 did you look in the manuel Quote Link to comment https://forums.phpfreaks.com/topic/52789-creating-a-log-file/#findComment-260612 Share on other sites More sharing options...
Stuie_b Posted May 24, 2007 Share Posted May 24, 2007 The following function should be what your looking for, function logToFile($action){ $log_data = "- Log Entry - ".date("d/m/y G:i.s")." - $action Performed - "; //Change this line too what you want entered into the log file $fp = fopen("logfile.log","a"); fwrite($fp,$log_data); fclose($fp); } Simply call the function each time you wont too add an entry too the log, In answer too your second question the log file be created on the fly as long as the directory has the correct chmod privs. hope it helps Stuie Quote Link to comment https://forums.phpfreaks.com/topic/52789-creating-a-log-file/#findComment-260613 Share on other sites More sharing options...
chiprivers Posted May 24, 2007 Author Share Posted May 24, 2007 I have this now working as above but I am not sure how to make a new line, at the moment all my entries are following along the same line in the text file. I have tried \n but this is obviusly not correct! Quote Link to comment https://forums.phpfreaks.com/topic/52789-creating-a-log-file/#findComment-260766 Share on other sites More sharing options...
Stuie_b Posted May 25, 2007 Share Posted May 25, 2007 Too create a new line just create one as you would here by hitting the return key within your $log_data string hope it helps stuie Quote Link to comment https://forums.phpfreaks.com/topic/52789-creating-a-log-file/#findComment-261341 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.