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