Show log directory contents and optionally open file manager. Args: open_file_manager: Whether to open the system file manager
(open_file_manager: bool = True)
| 81 | |
| 82 | |
| 83 | def show_log_directory(open_file_manager: bool = True) -> None: |
| 84 | """Show log directory contents and optionally open file manager. |
| 85 | |
| 86 | Args: |
| 87 | open_file_manager: Whether to open the system file manager |
| 88 | """ |
| 89 | log_dir = get_log_directory() |
| 90 | |
| 91 | print(f"\n{Colors.BRIGHT_CYAN}📁 Log Directory: {log_dir}{Colors.RESET}") |
| 92 | |
| 93 | if not log_dir.exists() or not log_dir.is_dir(): |
| 94 | print(f"{Colors.RED}Log directory does not exist: {log_dir}{Colors.RESET}\n") |
| 95 | return |
| 96 | |
| 97 | log_files = list(log_dir.glob("*.log")) |
| 98 | |
| 99 | if not log_files: |
| 100 | print(f"{Colors.YELLOW}No log files found in directory.{Colors.RESET}\n") |
| 101 | return |
| 102 | |
| 103 | # Sort by modification time (newest first) |
| 104 | log_files.sort(key=lambda x: x.stat().st_mtime, reverse=True) |
| 105 | |
| 106 | print(f"{Colors.DIM}{'─' * 60}{Colors.RESET}") |
| 107 | print(f"{Colors.BOLD}{Colors.BRIGHT_YELLOW}Available Log Files (newest first):{Colors.RESET}") |
| 108 | |
| 109 | for i, log_file in enumerate(log_files[:10], 1): |
| 110 | mtime = datetime.fromtimestamp(log_file.stat().st_mtime) |
| 111 | size = log_file.stat().st_size |
| 112 | size_str = f"{size:,}" if size < 1024 else f"{size / 1024:.1f}K" |
| 113 | print(f" {Colors.GREEN}{i:2d}.{Colors.RESET} {Colors.BRIGHT_WHITE}{log_file.name}{Colors.RESET}") |
| 114 | print(f" {Colors.DIM}Modified: {mtime.strftime('%Y-%m-%d %H:%M:%S')}, Size: {size_str}{Colors.RESET}") |
| 115 | |
| 116 | if len(log_files) > 10: |
| 117 | print(f" {Colors.DIM}... and {len(log_files) - 10} more files{Colors.RESET}") |
| 118 | |
| 119 | print(f"{Colors.DIM}{'─' * 60}{Colors.RESET}") |
| 120 | |
| 121 | # Open file manager |
| 122 | if open_file_manager: |
| 123 | _open_directory_in_file_manager(log_dir) |
| 124 | |
| 125 | print() |
| 126 | |
| 127 | |
| 128 | def _open_directory_in_file_manager(directory: Path) -> None: |
no test coverage detected