Python 3 Script to Add Logging to Stdout Using logging Module Full Project For Beginners



In order to get started you need to install the below library using the pip command as shown below



pip install logging



After installing this library you need to make an file and copy paste the following code

See also  Python 3 Script to Get Realtime Price of Mutual Funds Using mftool Library Full Project For Beginners



import logging

def main():
    # Configure the logging system
    logging.basicConfig(filename ='app.log',
                        level = logging.ERROR)
    # Variables (to make the calls that follow work)
    hostname = ''
    item = 'spam'
    filename = 'data.csv'
    mode = 'r'
    # Example logging calls (insert into your program)
    logging.critical('Host %s unknown', hostname)
    logging.error("Couldn't find %r", item)
    logging.warning('Feature is deprecated')'Opening file %r, mode = %r', filename, mode)
    logging.debug('Got here')
if __name__ == '__main__':

Leave a Reply