Add user_name project_name and color option to log

* adds project_name and user_name to context for logging
 * adds color argument to logging which allows for colored
   log output based on the log level

Change-Id: If37d646fdba77d4214f72b19e5df02da5f7dbac6
This commit is contained in:
Vishvananda Ishaya 2012-06-01 23:12:56 +00:00
parent d05b7ba026
commit df80f437ac

View File

@ -279,6 +279,21 @@ class LegacyNovaFormatter(logging.Formatter):
return '\n'.join(formatted_lines)
class NovaColorHandler(logging.StreamHandler):
LEVEL_COLORS = {
logging.DEBUG: '\033[00;32m', # GREEN
logging.INFO: '\033[00;36m', # CYAN
logging.AUDIT: '\033[01;36m', # BOLD CYAN
logging.WARN: '\033[01;33m', # BOLD YELLOW
logging.ERROR: '\033[01;31m', # BOLD RED
logging.CRITICAL: '\033[01;31m', # BOLD RED
}
def format(self, record):
record.color = self.LEVEL_COLORS[record.levelno]
return logging.StreamHandler.format(self, record)
class PublishErrorsHandler(logging.Handler):
def emit(self, record):
if 'list_notifier_drivers' in FLAGS:
@ -357,7 +372,7 @@ def _setup_logging_from_flags():
os.chmod(logpath, mode)
if FLAGS.use_stderr:
streamlog = logging.StreamHandler()
streamlog = NovaColorHandler()
nova_root.addHandler(streamlog)
elif not FLAGS.log_file: