Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/52789-creating-a-log-file/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/52789-creating-a-log-file/#findComment-260613
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.