$filePath = '/var/www/html/my_app.log'; if (!file_exists($filePath)) { // create log file if it doesn't exist touch($filePath); } // log a warning message $msg = "This is a warning message"; error_log($msg, 3, $filePath);The above code creates a log file if it doesn't already exist and logs a warning message to that file using the "error_log" function with the third parameter set to "3", which indicates that the message should be appended to the log file. By default, error_log function is using the PHP's error_log configuration, which often means it sends messages to a system error handler that may also write to your web server's error log. There's another reason why sometimes you might want to use something other than the system error handler: the handler's default can cause potentially sensitive information to appear in the error logs. Therefore, always be careful when logging info that could contain sensitive information.