Here is an example of a Python program to create logging in a file.
Create a Log File in Python Using Logging Library Example
The following Python program will create a log named application.log and will write the error information of an unsuccessful installation of HMS ERP application.
import logging def main(): logging.basicConfig( filename='application.log', level=logging.ERROR ) appname = 'HMS ERP' appmodule = 'IPD' filename = 'ipdform.fmb' mode = 'r' logging.critical('Application %s failed', appname) logging.error("Couldn't find module %r", appmodule) if __name__ == '__main__': main()
Output:
application.log CRITICAL:root:Application HMS ERP failed ERROR:root:Couldn't find module 'IPD'