Skip to content

Commit

Permalink
Decouple logs output color from the logging level
Browse files Browse the repository at this point in the history
Previously, each logging level was coupled with a specific
output color. This isn't always ideal because we might need
to log at a certain level but use a custom color (based on
user feedback / see linked issue).

This patch decouples the logs output color from the logging
level.

Fixes #10519
  • Loading branch information
healthy-pod committed Jan 6, 2022
1 parent 7f8a684 commit 3969a38
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
Empty file added news/10519.bugfix.rst
Empty file.
2 changes: 1 addition & 1 deletion src/pip/_internal/resolution/resolvelib/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ def describe_trigger(parent: Candidate) -> str:
+ "the dependency conflict\n"
)

logger.info(msg)
logger.critical(msg, extra={"color": "black"})

return DistributionNotFound(
"ResolutionImpossible: for help visit "
Expand Down
6 changes: 5 additions & 1 deletion src/pip/_internal/utils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ def emit(self, record: logging.LogRecord) -> None:
else:
message = self.format(record)
renderable = self.render_message(record, message)
if record.levelno is not None:
# If a custom color is passed use it, otherwise use default colors.
color_attribute = "color"
if hasattr(record, color_attribute):
style = Style(color=getattr(record, color_attribute))
elif record.levelno is not None:
if record.levelno >= logging.ERROR:
style = Style(color="red")
elif record.levelno >= logging.WARNING:
Expand Down

0 comments on commit 3969a38

Please sign in to comment.