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 demo and example for implement.

how to create a log file
how to create log file

Hear is code for create log file in php

$log_time = date('Y-m-d h:i:sa');
$log_msg = "TEST LOG MSG";
wh_log("************** Start Log For Day : '" . $log_time . "'**********");
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 helped you for implement log file in php. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs