import logging
logging.basicConfig(level=logging.INFO, filename='myserver.log', format=
    '%(asctime)s %(message)s')
logging.info('some message')
How to add logging to a file with timestamps to a Python TCP Server for Raspberry Pi