Skip to content

Instantly share code, notes, and snippets.

View skewty's full-sized avatar

skewty skewty

  • Vancouver, BC, Canada
View GitHub Profile
@skewty
skewty / logit.py
Last active August 18, 2022 20:28
Python decorator to log synchronous function / method usage and exceptions
import logging
import sys
def _get_logger_in_scope(scope: dict) -> logging.Logger | None:
for prop in ("log", "logger", "LOG", "LOGGER"):
if prop in scope and isinstance(scope[prop], logging.Logger):
return scope[prop]
for value in scope.values():
if isinstance(value, logging.Logger):
@skewty
skewty / EmojiFormatter.py
Created February 3, 2023 23:32
Python logging using Emoji for loglevel
import logging
class EmojiFormatter(logging.Formatter):
"""Formatter that adds `levelemoji` field. Override emojis used my modifying EMOJI_MAP.
Example:
logging.basicConfig(format="%(asctime)s %(levelemoji)s %(message)s")
"""
# the INFO level should have the "Information" (U+2139) emoji but it doesn't seem to work in the next line