|
10 | 10 | from urllib3.exceptions import MaxRetryError |
11 | 11 |
|
12 | 12 | from .constants import BITCOINCORE_CONTAINER |
13 | | -from .k8s import get_default_namespace, get_mission |
| 13 | +from .k8s import get_default_namespace, get_mission, pod_log |
14 | 14 | from .process import run_command |
15 | 15 |
|
16 | 16 |
|
@@ -79,25 +79,18 @@ def grep_logs(pattern: str, show_k8s_timestamps: bool, no_sort: bool): |
79 | 79 |
|
80 | 80 | for tank in tanks: |
81 | 81 | pod_name = tank.metadata.name |
82 | | - # Get container names for this pod |
83 | | - containers = tank.spec.containers |
84 | | - if not containers: |
85 | | - continue |
86 | | - |
87 | | - # Use the first container name |
88 | | - container_name = containers[0].name |
89 | | - if not container_name: |
90 | | - continue |
91 | | - |
92 | | - # Get logs from the specific container |
93 | | - command = f"kubectl logs {pod_name} -c {container_name} --timestamps" |
94 | | - logs = run_command(command) |
| 82 | + logs = pod_log(pod_name, BITCOINCORE_CONTAINER) |
95 | 83 |
|
96 | 84 | if logs is not False: |
97 | | - # Process logs |
98 | | - for log_entry in logs.splitlines(): |
99 | | - if re.search(pattern, log_entry): |
100 | | - matching_logs.append((log_entry, pod_name)) |
| 85 | + try: |
| 86 | + for line in logs: |
| 87 | + log_entry = line.decode("utf-8").rstrip() |
| 88 | + if re.search(pattern, log_entry): |
| 89 | + matching_logs.append((log_entry, pod_name)) |
| 90 | + except Exception as e: |
| 91 | + print(e) |
| 92 | + except KeyboardInterrupt: |
| 93 | + print("Interrupted streaming log!") |
101 | 94 |
|
102 | 95 | # Sort logs if needed |
103 | 96 | if not no_sort: |
|
0 commit comments