|
12 | 12 | import time |
13 | 13 | from datetime import datetime |
14 | 14 | import logging |
| 15 | +from rich.logging import RichHandler |
15 | 16 |
|
16 | 17 | # ----------------- |
17 | 18 | # LOGGING SETUP |
18 | 19 | # ----------------- |
19 | 20 | def setup_logging(): |
20 | | - """Setup logging for C2 server activities""" |
| 21 | + """Setup rich logging for C2 server activities""" |
21 | 22 | if not os.path.exists('logs'): |
22 | 23 | os.makedirs('logs') |
23 | 24 | timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") |
24 | 25 | log_filename = f'logs/c2_server_alt_{timestamp}.log' |
| 26 | + FORMAT = "[%(asctime)s] %(levelname)-8s %(message)s" |
25 | 27 | logging.basicConfig( |
26 | | - level=logging.INFO, |
27 | | - format='%(asctime)s - %(levelname)s - %(message)s', |
| 28 | + level="INFO", |
| 29 | + format=FORMAT, |
| 30 | + datefmt="%Y-%m-%d %H:%M:%S", |
28 | 31 | handlers=[ |
29 | | - logging.FileHandler(log_filename, encoding='utf-8'), |
30 | | - logging.StreamHandler() |
| 32 | + RichHandler(rich_tracebacks=True, markup=True, show_time=False, show_level=True, show_path=False), |
| 33 | + logging.FileHandler(log_filename, encoding='utf-8') |
31 | 34 | ] |
32 | 35 | ) |
33 | | - logger = logging.getLogger(__name__) |
34 | | - logger.info("=" * 60) |
35 | | - logger.info("C2 SERVER (ALT, HTTP POST) STARTED") |
36 | | - logger.info("=" * 60) |
37 | | - logger.info(f"Log file: {log_filename}") |
38 | | - logger.info(f"Timestamp: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}") |
| 36 | + logger = logging.getLogger("rich") |
| 37 | + logger.info("[bold green]========================================[/bold green]") |
| 38 | + logger.info("[bold cyan]C2 SERVER (ALT, HTTP POST) STARTED[/bold cyan]") |
| 39 | + logger.info("[bold green]========================================[/bold green]") |
| 40 | + logger.info(f"Log file: [bold yellow]{log_filename}[/bold yellow]") |
| 41 | + logger.info(f"Timestamp: [bold magenta]{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}[/bold magenta]") |
39 | 42 | return logger |
40 | 43 |
|
41 | 44 | # ----------------- |
|
0 commit comments