Skip to content

Instantly share code, notes, and snippets.

@mwestwood
Created August 25, 2023 19:58
Show Gist options
  • Save mwestwood/ec60ea723c4edae261ed99e35a793175 to your computer and use it in GitHub Desktop.
Save mwestwood/ec60ea723c4edae261ed99e35a793175 to your computer and use it in GitHub Desktop.
import logging
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(message)s')
logger = logging.getLogger()
# Add a file handler to log to a text file
file_handler = logging.FileHandler('output.log')
file_handler.setLevel(logging.INFO)
file_handler.setFormatter(logging.Formatter('%(asctime)s - %(message)s'))
logger.addHandler(file_handler)
# Your script code starts here
logger.info("This message will be logged to both console and output.log")
logger.info("Another message")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment