mirror of
https://github.com/datafolklabs/cement.git
synced 2026-02-06 14:16:46 +00:00
Change the way ext_colorlog.py locates its config
By having the Meta.label be dynamically fetched when "colorize" is set, one can subclass ColorLogHandler to add further functionality (ie. mailing when a fatal error occurs). Now a subclass Handler can be defined, its own class Meta sets the config_defaults and the original ColorLogHandler receives the config from it.
This commit is contained in:
parent
28e01d4a1f
commit
aac6f85e7e
@ -64,7 +64,7 @@ class ColorLogHandler(LoggingLogHandler):
|
||||
|
||||
def _get_console_format(self):
|
||||
format = super(ColorLogHandler, self)._get_console_format()
|
||||
colorize = self.app.config.get('log.colorlog', 'colorize_console_log')
|
||||
colorize = self.app.config.get('log.{}'.format(self.Meta.label), 'colorize_console_log')
|
||||
if sys.stdout.isatty() or 'CEMENT_TEST' in os.environ:
|
||||
if is_true(colorize):
|
||||
format = "%(log_color)s" + format
|
||||
@ -72,13 +72,13 @@ class ColorLogHandler(LoggingLogHandler):
|
||||
|
||||
def _get_file_format(self):
|
||||
format = super(ColorLogHandler, self)._get_file_format()
|
||||
colorize = self.app.config.get('log.colorlog', 'colorize_file_log')
|
||||
colorize = self.app.config.get('log.{}'.format(self.Meta.label), 'colorize_file_log')
|
||||
if is_true(colorize):
|
||||
format = "%(log_color)s" + format
|
||||
return format
|
||||
|
||||
def _get_console_formatter(self, format):
|
||||
colorize = self.app.config.get('log.colorlog', 'colorize_console_log')
|
||||
colorize = self.app.config.get('log.{}'.format(self.Meta.label), 'colorize_console_log')
|
||||
if sys.stdout.isatty() or 'CEMENT_TEST' in os.environ:
|
||||
if is_true(colorize):
|
||||
formatter = self._meta.formatter_class(
|
||||
@ -96,7 +96,7 @@ class ColorLogHandler(LoggingLogHandler):
|
||||
return formatter
|
||||
|
||||
def _get_file_formatter(self, format):
|
||||
colorize = self.app.config.get('log.colorlog', 'colorize_file_log')
|
||||
colorize = self.app.config.get('log.{}'.format(self.Meta.label), 'colorize_file_log')
|
||||
if is_true(colorize):
|
||||
formatter = self._meta.formatter_class(
|
||||
format,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user