How to export previous logs in Stackdriver

孤人 提交于 2020-01-12 14:07:49

问题


I have a log in Stackdriver that logs every request goes into my api and failed, and I want to write a script to count on the number of times each error message appears. The problem is, the export feature in Stackdriver V2 only allow me to sink upcoming error messages, but I only care about the logs entries that already lives in the log. Is there a way to download the complete log from Stackdriver?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/45944704/how-to-export-previous-logs-in-stackdriver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!