Geoprocessing With Python Official

: Retrieves all messages (status, warnings, and errors) from the last tool executed.

: The standard Python function to create or open text files for logging or data extraction. Benefits of Geoprocessing with Python Saving Processing Results to a text file - Esri Community Geoprocessing with Python

After running a tool, you can capture its status and messages using arcpy.GetMessages() and write them to a .txt file: : Retrieves all messages (status, warnings, and errors)