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