What are the best practices for logging functions in PHP to include file names and line numbers?

When logging functions in PHP, it is important to include file names and line numbers to easily track where the log messages are coming from. One way to achieve this is by using the magic constants `__FILE__` and `__LINE__` which will automatically insert the current file name and line number into the log message.

function logMessage($message) {
    $logMessage = '[' . date('Y-m-d H:i:s') . '] ' . $message . ' - ' . __FILE__ . ':' . __LINE__ . PHP_EOL;
    file_put_contents('logfile.txt', $logMessage, FILE_APPEND);
}

// Example usage
logMessage('Error occurred');