How to export previous logs in Stackdriver

If you want to pull existing log data, you'll need to use the API to list entries: https://cloud.google.com/logging/docs/reference/v2/rest/v2/entries/list

You can do this directly from the API documentation page if you only need a one time solution.


You can now do this from the gcloud CLI tool, with gcloud logging read: https://cloud.google.com/logging/docs/reference/tools/gcloud-logging#reading_log_entries

Though in the scenario described, creating a log sink is the only way to capture events that are older than the stackdriver logging window, which is only 30 days even in the paid version.


Note that the filter is same as when you choose advanced filter in the Logging gui.

gcloud beta logging read "resource.type=\"gae_app\" resource.labels.module_id=\"api\" \"Ronald Reagan\"" --format=json --freshness=6d > x.txt