$logFile = '/path/to/log/file.log'; $message = 'An error occurred!'; writeLog($logFile, $message);
$logFile = '/path/to/log/file.log'; $message = 'User login success!'; $ipAddress = $_SERVER['REMOTE_ADDR']; $userAgent = $_SERVER['HTTP_USER_AGENT']; $logMessage = date('Y-m-d H:i:s') . ' ' . $message . ' IP: ' . $ipAddress . ' User Agent: ' . $userAgent; writeLog($logFile, $logMessage);In this example, we're writing a log message about a successful user login. The log message includes the date and time, the message, the user's IP address, and their user agent. To determine the package library for the writeLog function, we need to know which PHP framework or library we're using. Laravel, for example, has its own logging system that can be configured to use multiple channels with different log levels. Other PHP frameworks like CodeIgniter and Zend also have built-in logging systems. If we're not using a framework, we can still write our own logging function using the PHP built-in functions fopen, fwrite, and fclose.