Skip to content

Commit 78f1bbc

Browse files
committed
Docs: improve get_job_logs docstring for clarity and usage
1 parent d6747e1 commit 78f1bbc

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

kubeflow/trainer/api/trainer_client.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,28 +186,33 @@ def get_job_logs(
186186
step: str = constants.NODE + "-0",
187187
follow: bool | None = False,
188188
) -> Iterator[str]:
189-
"""Get logs from a specific step of a TrainJob.
189+
"""
190+
Retrieve logs from a specific step of a TrainJob.
191+
192+
This method allows you to fetch logs either as a batch or stream them
193+
in real-time using the `follow` parameter.
190194
191-
You can watch for the logs in realtime as follows:
192-
```python
193-
from kubeflow.trainer import TrainerClient
195+
Example:
196+
from kubeflow.trainer import TrainerClient
194197
195-
for logline in TrainerClient().get_job_logs(name="s8d44aa4fb6d", follow=True):
196-
print(logline)
197-
```
198+
client = TrainerClient()
199+
200+
# Stream logs in real-time
201+
for line in client.get_job_logs(name="job-id", follow=True):
202+
print(line)
198203
199204
Args:
200-
name: Name of the TrainJob.
201-
step: Step of the TrainJob to collect logs from, like dataset-initializer or node-0.
202-
follow: Whether to stream logs in realtime as they are produced.
205+
name (str): Name of the TrainJob.
206+
step (str): Step of the TrainJob to collect logs from
207+
(e.g., dataset-initializer or node-0).
208+
follow (bool, optional): If True, streams logs in real-time.
209+
Defaults to False.
203210
204211
Returns:
205-
Iterator of log lines.
212+
Iterator[str]: An iterator over log lines.
206213
207-
208-
Raises:
209-
TimeoutError: Timeout to get a TrainJob.
210-
RuntimeError: Failed to get a TrainJob.
214+
Note:
215+
If no logs are available, an empty iterator may be returned.
211216
"""
212217
return self.backend.get_job_logs(name=name, follow=follow, step=step)
213218

0 commit comments

Comments
 (0)