Write task logs

This document describes how to write task logs and how to create and run a Batch job that has task logs.

When logging is enabled for a job, task logs are generated from messages that the job's runnables print during run time. By configuring your runnables to write task logs, you can surface custom information in Cloud Logging, which can help make your jobs easier to analyze and troubleshoot. To learn more about logs, see Analyze a job using logs.

Before you begin

  1. If you haven't used Batch before, review Get started with Batch and enable Batch by completing the prerequisites for projects and users.
  2. To get the permissions that you need to create a job that writes logs, ask your administrator to grant you the following IAM roles:

    For more information about granting roles, see Manage access to projects, folders, and organizations.

    You might also be able to get the required permissions through custom roles or other predefined roles.

Create and run a job that has task logs

To create and run a job that you want to have task logs, do the following when you are creating the job:

  1. Enable logs for the job. This allows any logs written for the job to be generated.
  2. For each task log that you want the job to have, add a command that writes a task log to a runnable. When the job runs, a task log gets generated whenever a command to write a task log is executed.

    To learn how to write task logs, see Write task logs in this document.

Write task logs