Skip to content

Instantly share code, notes, and snippets.

@ciel334288
Created December 31, 2020 09:25
Show Gist options
  • Select an option

  • Save ciel334288/3c68f30b1ed674bdf7e5045922d23178 to your computer and use it in GitHub Desktop.

Select an option

Save ciel334288/3c68f30b1ed674bdf7e5045922d23178 to your computer and use it in GitHub Desktop.
python logging
import os,\
logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.ERROR)
LOGS = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'logs')
filehandler = logging.FileHandler(os.path.join(LOGS, 'main.log'), mode='a')
formatter = logging.Formatter('%(asctime)s : %(name)s : %(message)s')
logger.addHandler(filehandler)
filehandler.setFormatter(formatter)
logger.info("Exception!!!") # std console output
logger.error("Exception!!!") # std console output and log file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment