the singleton pattern in the log filewe want each message to be prepended with the level associated with the message this helps us easily scan the file for specific types of messages you can use this convention with certain command-line toolslike using grep in nix environment to show only messages of certain level after upgrading our logging functionit looks like thislogger py def critical(msg)with open("/var/log/filename log"" "as log_filelog_file write("[critical{ }\nformat(msg)def error(msg)with open("/var/log/filename log"" "as log_filelog_file write("[error{ }\nformat(msg)def warn(msg)with open("/var/log/filename log"" "as log_filelog_file write("[warn{ }\nformat(msg)def info(msg)with open("/var/log/filename log"" "as log_filelog_file write("[info{ }\nformat(msg)def debug(msg)with open("/var/log/filename log"" "as log_filelog_file write("[debug{ }\nformat(msg)you do not need to change the way you import the codeyou just use the level of message you want to saveas followstest_error_log py import logger trya exceptlogger error("something went wrong"