docs(samples): Adding code samples for log reading#56
Conversation
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
| def get_job_logs(project_id: str, job: batch_v1.Job) -> Generator[logging.TextEntry, None, None]: | ||
| log_client = logging.Client(project=project_id) | ||
| logger = log_client.logger("batch_task_logs") | ||
|
|
||
| yield from logger.list_entries(filter_=f"labels.job_uid={job.uid}") |
There was a problem hiding this comment.
Does this really need to be a seperate function? Can we not just iterate over logger.list_entries directly?
If not, can we provide some context why, and maybe use an inline function so the client and log can be part of the main function?
There was a problem hiding this comment.
I put it in separate function for easier testing. I use this in test, while the printing function can be untested.
I can change it to read the stdout and see if it works that way if you prefer.
There was a problem hiding this comment.
It's an explicit goal of the samples style guide to test the output of the function itself and not use return types: https://googlecloudplatform.github.io/samples-style-guide/#result
There was a problem hiding this comment.
@kurtisvg I made the sample fit in one function and just print the logs.
|
@kurtisvg I applied some of your comments and suggestions. I kept the log retrieving as 2 separate function for easy testing and so that people can easily copy the log retrieving part for their code. Please let me know if you can accept this division. |
Preparing code samples for this page.