import logging


def _print_violations(package_file_path, violations):
    """Print violations for a file.

    :param package_file_path: File path.
    :param violations: List of Violation elements.
    :return: Number of violations for the file.
    """
    for violation in violations:
        message_element = violation.find("Message")
        if message_element is not None:
            message = message_element.text
        else:
            message = "[empty message]"
        logging.error(
            "%s:%s: %s: %s",
            package_file_path,
            violation.attrib["lineNumber"],
            violation.attrib["ruleName"],
            message,
        )

    return len(violations)