Skip to content

Instantly share code, notes, and snippets.

@Liad-n
Created January 16, 2021 19:56
Show Gist options
  • Save Liad-n/8116714af87193e2a4159a1537c1c28c to your computer and use it in GitHub Desktop.
Save Liad-n/8116714af87193e2a4159a1537c1c28c to your computer and use it in GitHub Desktop.
basic_logging
log_file_path = r'log.log'
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
LOG_FORMAT = "%(levelname)s %(asctime)s - %(message)s"
formatter = logging.Formatter(LOG_FORMAT, datefmt="%Y-%m-%d %H:%M:%S")
file_handler = logging.FileHandler(log_file_path)
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(formatter)
stream_handler = logging.StreamHandler(sys.stdout)
stream_handler.setLevel(logging.INFO)
logger.addHandler(file_handler)
logger.addHandler(stream_handler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment