@@ -51,11 +51,14 @@ def _rpc(tank: str, method: str, params: str, namespace: Optional[str] = None):
51
51
52
52
@bitcoin .command ()
53
53
@click .argument ("tank" , type = str , required = True )
54
- def debug_log (tank : str ):
54
+ @click .option ("--namespace" , default = None , show_default = True )
55
+ def debug_log (tank : str , namespace : Optional [str ]):
55
56
"""
56
57
Fetch the Bitcoin Core debug log from <tank pod name>
57
58
"""
58
- cmd = f"kubectl logs { tank } "
59
+ if not namespace :
60
+ namespace = get_default_namespace ()
61
+ cmd = f"kubectl logs { tank } --namespace { namespace } "
59
62
try :
60
63
print (run_command (cmd ))
61
64
except Exception as e :
@@ -78,8 +81,12 @@ def grep_logs(pattern: str, show_k8s_timestamps: bool, no_sort: bool):
78
81
sys .exit (1 )
79
82
80
83
matching_logs = []
84
+ longest_namespace_len = 0
81
85
82
86
for tank in tanks :
87
+ if len (tank .metadata .namespace ) > longest_namespace_len :
88
+ longest_namespace_len = len (tank .metadata .namespace )
89
+
83
90
pod_name = tank .metadata .name
84
91
# Get container names for this pod
85
92
containers = tank .spec .containers
@@ -92,31 +99,35 @@ def grep_logs(pattern: str, show_k8s_timestamps: bool, no_sort: bool):
92
99
continue
93
100
94
101
# Get logs from the specific container
95
- command = f"kubectl logs { pod_name } -c { container_name } --timestamps"
102
+ command = f"kubectl logs { pod_name } -c { container_name } --timestamps --namespace { tank . metadata . namespace } "
96
103
logs = run_command (command )
97
104
98
105
if logs is not False :
99
106
# Process logs
100
107
for log_entry in logs .splitlines ():
101
108
if re .search (pattern , log_entry ):
102
- matching_logs .append ((log_entry , pod_name ))
109
+ matching_logs .append ((log_entry , tank . metadata . namespace , pod_name ))
103
110
104
111
# Sort logs if needed
105
112
if not no_sort :
106
113
matching_logs .sort (key = lambda x : x [0 ])
107
114
108
115
# Print matching logs
109
- for log_entry , pod_name in matching_logs :
116
+ for log_entry , namespace , pod_name in matching_logs :
110
117
try :
111
118
# Split the log entry into Kubernetes timestamp, Bitcoin timestamp, and the rest of the log
112
119
k8s_timestamp , rest = log_entry .split (" " , 1 )
113
120
bitcoin_timestamp , log_message = rest .split (" " , 1 )
114
121
115
122
# Format the output based on the show_k8s_timestamps option
116
123
if show_k8s_timestamps :
117
- print (f"{ pod_name } : { k8s_timestamp } { bitcoin_timestamp } { log_message } " )
124
+ print (
125
+ f"{ pod_name } { namespace :<{longest_namespace_len }} { k8s_timestamp } { bitcoin_timestamp } { log_message } "
126
+ )
118
127
else :
119
- print (f"{ pod_name } : { bitcoin_timestamp } { log_message } " )
128
+ print (
129
+ f"{ pod_name } { namespace :<{longest_namespace_len }} { bitcoin_timestamp } { log_message } "
130
+ )
120
131
except ValueError :
121
132
# If we can't parse the timestamps, just print the original log entry
122
133
print (f"{ pod_name } : { log_entry } " )
0 commit comments