Skip to content

Instantly share code, notes, and snippets.

@mzpqnxow
Created September 22, 2018 19:30
Show Gist options
  • Save mzpqnxow/e8dbb2d8f3bed1aaa9aebe4417583038 to your computer and use it in GitHub Desktop.
Save mzpqnxow/e8dbb2d8f3bed1aaa9aebe4417583038 to your computer and use it in GitHub Desktop.
A stupid fancy logging.Logger extension that let's the developer have some new 'aesthics` focused functions, including overriding standard ones
class StupidFancyLogger(logging.Logger):
"""Extension of logging.Logger that has stupid fancyprint wrapper funcs
If you want your app to print stupid line prefixes and endings, this an
example of a way to do that. It's pretty simple, it just provides some
new methods in the Logger class, i.e., StupidFancyLogger.indented()
logger = StupidFancyLogger(...)
logger.indented(msg, count=8, log_level=logging.INFO):
"""
FANCY = [" ..## ",
" ..#### ",
" ......## ",
" ..... ",
" ... ",
" .. ",
"--- ",
" .. ",
" ....## ",
" .... ",
(" << ", " >>")]
def __init__(self, name):
super(self.__class__, self).__init__(name)
def line(self, log_level=logging.INFO, count=1):
for _ in xrange(0, count):
self.log(log_level, "")
def info(self, msg, *args, **kwargs):
super(self.__class__, self).info(msg, *args, **kwargs)
def goodbye(self, exit_code=0):
self.line()
self.info("Exiting...")
self.line()
sys.exit(exit_code)
def fatal(self, msg, exit_code=1, *args, **kwargs):
super(self.__class__, self).fatal(msg, *args, **kwargs)
self.line()
self.info("Exiting...")
self.line()
sys.exit(exit_code)
def indented(self, msg, count=8, log_level=logging.INFO):
self.log(log_level, "%s%s" % (" " * count, msg))
def error(self, msg, *args, **kwargs):
super(self.__class__, self).error(msg, *args, **kwargs)
def h1(self, msg, log_level=logging.INFO, *args, **kwargs):
self.log(log_level, "%s%s" % (self.FANCY[0], msg))
def title(self, msg, log_level=logging.INFO, *args, **kwargs):
self.log(log_level, "%s%s" % (self.FANCY[6], msg))
def ok(self, msg, log_level=logging.INFO):
self.log(log_level, "%sOK, %s" % (self.FANCY[7], msg))
def net(self, msg, log_level=logging.INFO):
self.log(
log_level, "%s%s%s", self.FANCY[10][0], msg, self.FANCY[10][1])
def go(self, msg, log_level=logging.INFO):
self.log(log_level, "%sGO, %s", self.FANCY[7], msg)
def fail(self, msg, log_level=logging.INFO):
self.log(log_level, "%sFAIL, %s", self.FANCY[7], msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment