Format the log record with colors.
(self, record)
| 51 | self.use_color = use_color |
| 52 | |
| 53 | def format(self, record): |
| 54 | """Format the log record with colors.""" |
| 55 | if not self.use_color: |
| 56 | return super().format(record) |
| 57 | |
| 58 | # Get the base formatted message |
| 59 | formatted = super().format(record) |
| 60 | |
| 61 | # Choose color scheme based on level |
| 62 | if record.levelname in ["ERROR", "CRITICAL"]: |
| 63 | colors = self.BOLD_COLORS |
| 64 | else: |
| 65 | colors = self.COLORS |
| 66 | |
| 67 | # Apply colors to level name and message |
| 68 | color = colors.get(record.levelname, colors["RESET"]) |
| 69 | reset = colors["RESET"] |
| 70 | |
| 71 | # Color the entire message for errors/critical, just the level for others |
| 72 | if record.levelname in ["ERROR", "CRITICAL"]: |
| 73 | return f"{color}{formatted}{reset}" |
| 74 | else: |
| 75 | # Replace the level name with colored version |
| 76 | level_colored = f"{color}{record.levelname}{reset}" |
| 77 | return formatted.replace(record.levelname, level_colored, 1) |
| 78 | |
| 79 | |
| 80 | def setup_logger( |
no outgoing calls
no test coverage detected