Log in php

Below is the function which can be used to log data in PHP


 function myLog($text)
    {
    // open  the log file
    $filename = "myAppLog.log";

   
    //Open the file in Append mode
    $f = fopen($filename, "a") or die("Could not open the log file.");

   
   //Write the log to the file. The timestamp can be altered as per the requirement
    fwrite($f, date("d-m-Y, H:i")." - $text\n") or die("Could not write file");

    fclose($f);

    }

No comments:

Post a Comment