Skip to content

Commit 9a16aa4

Browse files
authored
Merge pull request #2119 from FedML-AI/alaydshah/run/logs
Fix run logs cli command
2 parents a34535b + 3f40511 commit 9a16aa4

3 files changed

Lines changed: 16 additions & 16 deletions

File tree

python/fedml/api/modules/run.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def start(platform: str, create_run_result: FedMLRunStartedModel, device_server:
5151

5252
run_start_result = FedMLRunManager.get_instance().start_run(platform=platform, create_run_result=create_run_result,
5353
device_server=device_server, device_edges=device_edges,
54-
api_key=api_key,
54+
api_key=get_api_key(),
5555
feature_entry_point=feature_entry_point)
5656

5757
return run_start_result
@@ -79,7 +79,7 @@ def status(run_name: Optional[str], run_id: str, platform: str, api_key: str) ->
7979
_authenticate_and_validate_platform(api_key, platform)
8080

8181
run_status = None
82-
run_list_obj = list_run(run_name=run_name, run_id=run_id, platform=platform, api_key=api_key)
82+
run_list_obj = list_run(run_name=run_name, run_id=run_id, platform=platform, api_key=get_api_key())
8383

8484
if run_list_obj is not None:
8585
if len(run_list_obj.run_list) > 1:
@@ -93,12 +93,13 @@ def status(run_name: Optional[str], run_id: str, platform: str, api_key: str) ->
9393
# input: run_id, page_num, page_size, need_all_logs, platform, api_key
9494
# return RunLogResult(run_status, total_log_lines, total_log_pages, log_line_list, run_logs)
9595
def logs(run_id: str, page_num: int, page_size: int, need_all_logs: bool, platform: str, api_key: str) -> RunLogResult:
96-
_authenticate_and_validate_platform(api_key, platform)
96+
api_key = authenticate(api_key)
97+
validate_platform(platform)
9798

9899
if run_id is None:
99100
raise Exception("Please specify run id.")
100101

101-
_, run_status = status(run_name=None, run_id=run_id, platform=platform, api_key=get_api_key())
102+
_, run_status = status(run_name=None, run_id=run_id, platform=platform, api_key=api_key)
102103

103104
total_log_nums, total_log_pages, log_line_list, run_logs = 0, 0, list(), None
104105

@@ -110,7 +111,7 @@ def logs(run_id: str, page_num: int, page_size: int, need_all_logs: bool, platfo
110111
user_api_key=api_key)
111112

112113
if run_logs is not None:
113-
total_log_pages, total_log_nums = run_logs.total_num, run_logs.total_pages
114+
total_log_pages, total_log_nums = run_logs.total_pages, run_logs.total_num
114115
_parse_logs(log_line_list, run_logs)
115116

116117
return RunLogResult(run_status=run_status, total_log_lines=total_log_nums, total_log_pages=total_log_pages,

python/fedml/cli/modules/run.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,21 +184,21 @@ def status(platform, run_name, run_id, api_key, version):
184184
"--page_num",
185185
"-pn",
186186
type=int,
187-
default=0,
187+
default=1,
188188
help="request page num for logs. --need_all_logs should be set to False if you want to use this option.",
189189
)
190190
@click.option(
191191
"--page_size",
192192
"-ps",
193193
type=int,
194-
default=0,
194+
default=10,
195195
help="request page size for logs, --need_all_logs should be set to False if you want to use this option.",
196196
)
197197
@click.option(
198198
"--need_all_logs",
199199
"-a",
200200
type=bool,
201-
default=True,
201+
default=False,
202202
help="boolean value representing if all logs are needed. Default to True",
203203
)
204204
def logs(platform, run_id, api_key, version, page_num, page_size, need_all_logs):
@@ -217,8 +217,8 @@ def logs(platform, run_id, api_key, version, page_num, page_size, need_all_logs)
217217
return
218218

219219
# Show run log summary info
220-
log_head_table = PrettyTable(['Run ID', 'Total Log Lines', 'Log URL'])
221-
log_head_table.add_row([run_id, run_log_result.total_log_lines, run_logs.log_full_url])
220+
log_head_table = PrettyTable(['Run ID', 'Printed Log Lines', 'Total Log Lines', 'Log URL'])
221+
log_head_table.add_row([run_id, len(run_log_result.log_line_list), run_logs.total_num, run_logs.log_full_url])
222222
click.echo("\nLogs summary info is as follows.")
223223
print(log_head_table)
224224

@@ -234,7 +234,7 @@ def logs(platform, run_id, api_key, version, page_num, page_size, need_all_logs)
234234
if len(run_log_result.log_line_list) > 0:
235235
click.echo("\nAll logs is as follows.")
236236
for log_line in run_log_result.log_line_list:
237-
click.echo(log_line.rstrip('\n'))
237+
click.echo(log_line)
238238

239239

240240
def _print_run_table(run_list_obj):

python/fedml/computing/scheduler/scheduler_entry/run_manager.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ def __init__(self, run_log_list_json):
162162
self.log_devices = list()
163163
for log_dev in log_devices_json:
164164
self.log_devices.append(FedMLRunLogDeviceModel(log_dev))
165-
self.total_num = run_log_list_json.get("total_num", 0)
166-
self.total_pages = run_log_list_json.get("total_pages", 0)
167-
self.current_page = run_log_list_json.get("current_page", 0)
168-
self.log_lines = run_log_list_json.get("logs", [])
165+
self.total_num = run_log_list_json.get("totalSize", 0)
166+
self.total_pages = run_log_list_json.get("totalPages", 0)
167+
self.current_page = run_log_list_json.get("pageNum", 0)
168+
self.log_lines = run_log_list_json.get("logList", [])
169169

170170

171171
class FedMLRunLogDeviceModel(object):
@@ -277,7 +277,6 @@ def get_run_logs(self, run_id: str, page_num: int, page_size: int, user_api_key:
277277
run_log_list_result = None
278278
run_logs_json = {
279279
"apiKey": user_api_key,
280-
"edgeId": "-1",
281280
"pageNum": page_num,
282281
"pageSize": page_size,
283282
"runId": run_id,

0 commit comments

Comments
 (0)