diff --git a/oslo_log/_options.py b/oslo_log/_options.py index 3a282e5f..356cf9a8 100644 --- a/oslo_log/_options.py +++ b/oslo_log/_options.py @@ -118,6 +118,11 @@ generic_log_opts = [ deprecated_for_removal=True, deprecated_reason='Windows support is no longer maintained.', help='Log output to Windows Event Log.'), + cfg.BoolOpt('log_color', + default=False, + help='(Optional) Set the \'color\' key according to log ' + 'levels. This option takes effect only when logging ' + 'to stderr or stdout is used. ' + _IGNORE_MESSAGE), cfg.IntOpt('log_rotate_interval', default=1, help='The amount of time before the log files are rotated. ' diff --git a/oslo_log/log.py b/oslo_log/log.py index 4bb24424..0ce16acd 100644 --- a/oslo_log/log.py +++ b/oslo_log/log.py @@ -405,7 +405,10 @@ def _setup_logging_from_conf(conf, project, version): log_root.addHandler(filelog) if conf.use_stderr: - streamlog = handlers.ColorHandler() + if conf.log_color: + streamlog = handlers.ColorHandler() + else: + streamlog = logging.StreamHandler() log_root.addHandler(streamlog) if conf.use_journal: @@ -425,9 +428,10 @@ def _setup_logging_from_conf(conf, project, version): # if None of the above are True, then fall back to standard out if not logpath and not conf.use_stderr and not conf.use_journal: - # pass sys.stdout as a positional argument - # python2.6 calls the argument strm, in 2.7 it's stream - streamlog = handlers.ColorHandler(sys.stdout) + if conf.log_color: + streamlog = handlers.ColorHandler(sys.stdout) + else: + streamlog = logging.StreamHandler(sys.stdout) log_root.addHandler(streamlog) if conf.publish_errors: diff --git a/releasenotes/notes/log_color-531437cab4477bcb.yaml b/releasenotes/notes/log_color-531437cab4477bcb.yaml new file mode 100644 index 00000000..6fefc9e6 --- /dev/null +++ b/releasenotes/notes/log_color-531437cab4477bcb.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + The new ``log_color`` option has been added. When this option is set to + ``False``, color keys are not set.