Skip to content

Conversation

@albestro
Copy link
Contributor

@albestro albestro commented Dec 16, 2025

Follow up of eth-cscs/alps-uenv#276 (comment), covering just the "colored" part for highlighting messages.

image image

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds colored output formatting to warning, error, and critical log messages in the console handler, making them easier to identify at a glance. The changes enhance the logging system by prepending level names to warnings and above, and applying ANSI color codes for visual distinction.

  • Introduces a ColoredFormatter class to apply colors to log messages based on severity
  • Configures the console handler to use the new colored formatter
  • Adds visual differentiation for WARNING (yellow), ERROR (red), and CRITICAL (red background) messages

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +36 to +43
class ColoredFormatter(logging.Formatter):
# ANSI escape codes (CSI Control Sequence Introducer)
COLORS = {
logging.WARNING: "\033[1;33m",
logging.ERROR: "\033[1;31m",
logging.CRITICAL: "\033[1;41m",
}
RESET = "\033[0m"
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ColoredFormatter class applies ANSI color codes unconditionally, which may cause issues in non-TTY environments (e.g., CI/CD pipelines, log files viewed in plain text editors). Consider checking if the output stream is a TTY using sys.stdout.isatty() before applying colors, or provide a way to disable colored output.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should not be a problem afaict, since I've already seen colors in CI/CD logs (and ANSI escape codes in raw log output)

Copy link
Member

@bcumming bcumming Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a simple tool like this, I don't think we need to worry about toggling color output, because doing it properly requires a combination of detecting TTY, inspecting the environment (https://no-color.org/) and supporting explicit --color and --no-color flags, and determining the precedence of each method.

@eth-cscs eth-cscs deleted a comment from Copilot AI Dec 17, 2025
@bcumming bcumming merged commit 4c3c115 into eth-cscs:main Dec 17, 2025
2 checks passed
@albestro albestro deleted the alby/colored-log branch December 17, 2025 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants