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:
parent
d05b7ba026
commit
df80f437ac
17
nova/log.py
17
nova/log.py
@ -279,6 +279,21 @@ class LegacyNovaFormatter(logging.Formatter):
|
|||||||
return '\n'.join(formatted_lines)
|
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):
|
class PublishErrorsHandler(logging.Handler):
|
||||||
def emit(self, record):
|
def emit(self, record):
|
||||||
if 'list_notifier_drivers' in FLAGS:
|
if 'list_notifier_drivers' in FLAGS:
|
||||||
@ -357,7 +372,7 @@ def _setup_logging_from_flags():
|
|||||||
os.chmod(logpath, mode)
|
os.chmod(logpath, mode)
|
||||||
|
|
||||||
if FLAGS.use_stderr:
|
if FLAGS.use_stderr:
|
||||||
streamlog = logging.StreamHandler()
|
streamlog = NovaColorHandler()
|
||||||
nova_root.addHandler(streamlog)
|
nova_root.addHandler(streamlog)
|
||||||
|
|
||||||
elif not FLAGS.log_file:
|
elif not FLAGS.log_file:
|
||||||
|
Loading…
Reference in New Issue
Block a user