import logging
logging.basicConfig(filename='example.log', encoding='utf-8', level=logging.DEBUG)
logging.debug('This message should go to the log file')
logging.info('So should this')
logging.warning('And this, too')
logging.error('And non-ASCII stuff, too, like Øresund and Malmö')
In computing, a log file is a file that records either events that
occur in an operating system or other software runs, or messages between
different users of a communication software. Logging is the act of
keeping a log. ... Many operating systems, software frameworks and
programs include a logging system.
# logging
import logging
# log the execution time and a message of an action
logging.basicConfig(filename='fileName.log',
level=logging.INFO,
format='%(levelname)s:%(asctime)s:%(message)s',
datefmt="%Y-%m-%d %H:%M:%S")
logging.info('ADD TWO NUMBERS')
print(5+5)
# output in console -> 10
# output in fileName.log -> INFO:2021-12-25 17:47:27:ADD TWO NUMBERS
# Logging is a means of tracking events that happen when some software runs. Logging is important for software developing, debugging and running. If you don’t have any logging record and your program crashes, there are very little chances that you detect the cause of the problem.
import logging
LOG_FILENAME = 'example.log'
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)
logging.debug('This message should go to the log file')