DoiT Wins Google Cloud Global Sales Partner of the Year Award – Learn more

Increase Log Retention Using Google Cloud Logging CLI

1 nibtkmwntw8etm3gi3a la

Sometimes you might need some “quick-and-dirty” metrics from your cloud infrastructure. What can you do? Perhaps you need to count monthly API requests, but have not installed an application performance monitoring solution and added agents to your app(s).

Unfortunately the default log retention period is 30 days on Google Cloud Platform (GCP), but you’re now in luck; you can override the logging defaults.

1 nibtkmwntw8etm3gi3a la

Customize Log Retention

  • Stackdriver logs (default: 30 days)
  • Audit logs (default: 400 days)
  • Metrics (default: 6 weeks)

In the past you would have to create a log sink and ship your logs to cloud storage buckets, PubSub, BigQuery, or another outlet to retain logs for later analysis. This is still advised for long-term storage and analysis, but you have a little more flexibility now with the gcloud CLI beta feature shown below.

  1. View your current default configuration

gcloud beta logging buckets list

1 be7iwu8yqvwv3dtlwa9quw

2. Increase your default retention period (between 1 and 3650 days)

gcloud beta logging buckets update _Default --location=global --retention-days=90

3. Confirm your new retention policy is in effect

gcloud beta logging buckets describe _Default --location=global

1 2aot fdd0ft3eaofz4gs9w

Build the filters and metrics you want

Once your log retention is as desired (be mindful of storage costs), you can then create filters and metrics as your heart desires.

The Google Cloud Console (web admin) also allows you to filter and download logs, but they are limited. If you want to retrieve logs for a certain period of time or range, consider using the gcloud beta logging read command.

Subscribe to updates, news and more.