Skip to content

Instantly share code, notes, and snippets.

@rh0dium
Last active August 17, 2020 21:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rh0dium/4747211 to your computer and use it in GitHub Desktop.
Save rh0dium/4747211 to your computer and use it in GitHub Desktop.
Color logging inside of PyCharm
# Get and install logutils
# pip install logutils
# === settings.py ===
class PseudoTTY(object):
"""This allows a a fake tty which will allow PyCharm to always say its a tty"""
def __init__(self, underlying):
"""Define my underlying class"""
self.__underlying = underlying
def __getattr__(self, name):
"""Pass me along to my parent"""
return getattr(self.__underlying, name)
def isatty(self):
"""Force this to always be True"""
return True
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'standard': {
'format': "[%(asctime)s] %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] %(message)s",
'datefmt': "%d/%b/%Y %H:%M:%S"
},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logutils.colorize.ColorizingStreamHandler',
'formatter': 'standard',
'stream': PseudoTTY(sys.stdout)
},
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler',
'include_html': True,
},
'logfile': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filename': "./django.log",
'maxBytes': 50000,
'backupCount': 2,
'formatter': 'standard',
},
},
'loggers': {
'django': {
'handlers': ['console', 'logfile'],
'propagate': True,
'level': 'ERROR',
},
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': False,
},
'': {
'handlers': ['console', 'logfile'],
'level': os.environ.get('AXIS_DEBUG_LEVEL', 'ERROR'),
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment