Created
November 28, 2020 06:25
-
-
Save attomos/b1ab348014fcc18a7f8bf3db60afdc82 to your computer and use it in GitHub Desktop.
Why assert failure does not show in logs? Checkout before() and after() 😉
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import traceback | |
from datetime import datetime | |
def setup_logging(): | |
# logging.getLogger("requests").setLevel(logging.WARNING) | |
# logging.getLogger("urllib3").setLevel(logging.WARNING) | |
# logging.getLogger("paramiko").setLevel(logging.WARNING) | |
today = datetime.today().strftime("%Y.%m.%d") | |
logging.basicConfig( | |
level=logging.INFO, | |
format="%(asctime)s [%(levelname)5s] %(message)s", | |
handlers=[logging.FileHandler(f"main_{today}.log"), logging.StreamHandler(),], | |
) | |
def main(): | |
logging.info("hello") | |
assert 1 == 2, "number of images should match" | |
def before(): | |
setup_logging() | |
main() | |
def after(): | |
try: | |
setup_logging() | |
main() | |
except Exception as e: | |
logging.error(e) | |
exc = traceback.format_exc() | |
logging.error(exc) | |
# traceback.print_exc() | |
if __name__ == "__main__": | |
after() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment