onlinecode

how to create log file in php?

create log file 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);
}

What is a Log File?

A log file is an event that took place at a certain time and might have metadata that contextualizes it.

Log files are a historical record of everything and anything that happens within a system, including events such as transactions, errors, and intrusions. That data can be transmitted in different ways and can be in structured, semi-structured, and unstructured formats.

Types of Logs File?

Nearly every component in a network generates a different type of data and each component collects that data in its own log. Because of that, many types of logs exist, including:

Hope this code and post will help you implement log file in PHP. if you need any help or any feedback give it in the comment section or if 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 onlincode. we will give you this type of more interesting post in featured also so, For more interesting posts and code Keep reading our blogs onlincode.org

Exit mobile version