create log file in php – how to create log file in php?

how to create log file in PHP?

In this post, we will show you how to create log file in PHP, hear for how to create log file in PHP we will give you a demo and an example for implementation.

Here is code for create log file in PHP

$log_time = date('Y-m-d h:i:sa');
$log_msg = "how to create log file in php?";
 
wh_log("************** Start Log For Day : '" . $log_time . "'**********");
wh_log($log_msg);
wh_log("************** END Log For Day : '" . $log_time . "'**********");

function wh_log($log_msg)
{
	$log_filename = "log";
	if (!file_exists($log_filename)) 
	{
		// create directory/folder uploads.
		mkdir($log_filename, 0777, true);
	}
	$log_file_data = $log_filename.'/log_' . date('d-M-Y') . '.log';
    file_put_contents($log_file_data, $log_msg . "\n", FILE_APPEND);
}

Hope this code and post will help you the implement log file in PHP. if you need any help or any feedback give it in the comment section or you have a good idea about this post you can give it in the comment section. Your comment will help us to help you more and improve infinityknow.

Leave a Reply

Your email address will not be published. Required fields are marked *