Sample command-line programs for retrieving Google Logging API V2 data.
logs_api.py
is a simple command-line program to demonstrate writing to a log,
listing its entries to view it, then deleting it via CLI operations.
export_logs_api.py
demonstrates how to interact with Logging sinks, which can send
logs to Google Cloud Storage, Cloud Pub/Sub, or BigQuery. In this example
we use Google Cloud Storage. It similarly exposes a CLI to run these operations.
- A Google Cloud Project
Go to the Google Cloud Console to create a project. Take note of the project ID, which is sometimes but not always the same as your given name for a project.
To run export.py
, you will also need a Google Cloud Storage Bucket.
gsutil mb gs://[YOUR_PROJECT_ID]
You must add Cloud Logging as an owner to the bucket. To do so, add [email protected] as an owner to the bucket. See the exportings logs docs for complete details.
To install, run the following commands. If you want to use virtualenv (recommended), run the commands within a virtualenv.
Create local credentials by running the following command and following the oauth2 flow:
gcloud beta auth application-default login
To run the list_logs example
python logs_api.py --project_id=<YOUR-PROJECT-ID> write_entry "hello world"
python logs_api.py --project_id=<YOUR-PROJECT-ID> list_entries
python logs_api.py --project_id=<YOUR-PROJECT-ID> delete_logger
The exports_logs_api.py
samples requires a Cloud bucket that has added [email protected]
as an owner. See:
python export_logs_api.py --project_id=YOUR_PROJECT_ID create_sink \
--destination_bucket=YOUR_BUCKET
python export_logs_api.py --project_id=YOUR_PROJECT_ID update_sink\
--destination_bucket=YOUR_BUCKET
python export_logs_api.py --project_id=YOUR_PROJECT_ID list_sinks
python export_logs_api.py --project_id=YOUR_PROJECT_ID delete_sink \
--destination_bucket=YOUR_BUCKET
See our Cloud Platform authentication guide.