the singleton pattern let' create new file called logger py and write the following code in the filelogger py def log_message(msg)with open("/var/log/filename log"" "as log_filelog_file write("{ }\nformat(msg)nowwe can use our new logger function to write log messages to the file system in our main_script py filemain_script py import logger for in range( )logger log_message("log message {}format( )the first line of the file-import logger tells python to import the logger py file (note that you do not add py when you import the fileimporting file allows you to use the functions defined in the logger py file in the main_script py file in the preceding code snippetwe have loop where we tell python to write message log message every time the loop runswhere is the index of the loop in the range open the filename log file and verify that the messages were indeed written as expected as the number of log messages increasesyou will find you want to distinguish between them the most useful distinction is the terms used to describe the severity of the event causing the message in question for the sake of our loggerwe will handle the following levelscritical error warning info debug luckilywe only have single file to update (aren' you glad we moved this logger to its own file?