Log port cleanup operations to debug log file. Args: message: Log message to write log_dir: Optional custom log directory (default: project_root/.logs/debug_attached)
(message: str, log_dir: Path | None = None)
| 190 | |
| 191 | |
| 192 | def log_port_cleanup(message: str, log_dir: Path | None = None) -> None: |
| 193 | """Log port cleanup operations to debug log file. |
| 194 | |
| 195 | Args: |
| 196 | message: Log message to write |
| 197 | log_dir: Optional custom log directory (default: project_root/.logs/debug_attached) |
| 198 | """ |
| 199 | try: |
| 200 | # Default to project root .logs directory if not specified |
| 201 | if log_dir is None: |
| 202 | # Assume this module is in ci/util/, so project root is two levels up |
| 203 | project_root = Path(__file__).parent.parent.parent |
| 204 | log_dir = project_root / ".logs" / "debug_attached" |
| 205 | |
| 206 | log_file = log_dir / "port_cleanup.log" |
| 207 | |
| 208 | # Create directory if it doesn't exist |
| 209 | log_dir.mkdir(parents=True, exist_ok=True) |
| 210 | |
| 211 | # Append log entry with timestamp |
| 212 | timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") |
| 213 | with open(log_file, "a", encoding="utf-8") as f: |
| 214 | f.write(f"[{timestamp}] {message}\n") |
| 215 | except KeyboardInterrupt as ki: |
| 216 | handle_keyboard_interrupt(ki) |
| 217 | raise |
| 218 | except Exception: |
| 219 | # Silently ignore logging errors - don't fail the operation |
| 220 | pass |
| 221 | |
| 222 | |
| 223 | def kill_port_users(port: str) -> None: |
no test coverage detected