In this post we will show you how to create log file in PHP. This quick Post tutorial help to create logging functionality in your PHP application using core PHP code. You don’t need any PHP library or any plugin.
There is general requirement of any application, how to catch the logging information into your application. your application is running and accidentally it will down. How can you get what will problem occurred in your code and what was caused to fail system, by help of log file you can get any problem and information what happened in your application.
Creating logging in PHP application is very easy. You just need to create a single
log.php file use it any where in application do you need.
$log_time = date('Y-m-d h:i:sa');
$log_msg = "Log file in PHP";
wh_log("************** Start Log For Day : '" . $log_time . "'**********");
wh_log("************** END Log For Day : '" . $log_time . "'**********");
$log_filename = "log";
// 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 your coding ability. we will give you this type of more interesting post in featured also