如何像日志浏览器一样获取Gcloud日志信息?
我正在使用 @google-cloud/logging
包从 gcloud 获取日志,它工作得很好,您可以获取日志、事件(并在需要时查询它们)。但是我如何才能获得与日志资源管理器相同的信息呢?我的意思是可以查询的不同类型的字段等:
在这张图片上,您可以看到日志字段,例如函数名称
,它可能是值列表。似乎 @google-cloud/logging
无法获取此元(或字段信息)?那么是否可以使用其他一些API来获取它呢?
I am using @google-cloud/logging
package to get logs from gcloud, and it works nicely, you can get logs, event (and query them if needed). But how I can get the same info as Logs Explorer? I mean different type of fields which can be queried and etc:
On this picture you see Log fields like, FUNCTION NAME
which may be a list of values. And it seems that @google-cloud/logging
can't get this meta (or fields info)? So is it possible to obtain it using some other APIs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解您的问题,您正在询问Logs Viewer如何确定允许其向您展示各种日志字段的值,以过滤|完善您的日志查询。
我怀疑(不知道)观看者正在从属性解析日志时从属性中构建这些列表。这表明,列表是不完美的,例如
function_name
的s仅在解析函数名称(函数的名称)后才出现。有一种方法可以列举确定的GCP资源列表。这是使用
list
或使用服务特定库(SDK)的等效方法完成的,例如=“ nofollow noreferrer”>@google-cloud/functions
。理解给定的Google服务提供的功能的最简单方法是使用Google的 apis Explorer < /a>。这是云记录api v2 and https ://cloud.google.com/functions/docs/reference/rest“ rel =“ nofollow noreferrer”> cloud functions api 。
您可以向自己证明,云记录中没有任何方法可以列举所有项目的云功能。但是云函数中有一种方法 projects.locations.functions.list 。后者返回一个响应主体,其中包含
函数
的列表,该是cloudFunction
具有name
。了解这些API(“库”)是如何使用
-log-http
中的另一种方法命令。If I understand your question correctly, you're asking how Logs Viewer is determining the values that allows it to present you with the various log fields to filter|refine your log queries.
I suspect (don't know) that the viewer is building these lists from the properties as it parses the logs. This would suggest that, the lists are imperfect and that e.g.
FUNCTION_NAME
's would only appear once a log including the Function's name were parsed.There is a way to enumerate definitive lists of GCP resources. This is done using
list
or equivalent methods available using service-specific libraries (SDKs) e.g.@google-cloud/functions
.The easiest way to understand what functionality is provided by a given Google service is to browse the service using Google's APIs Explorer. Here's Cloud Logging API v2 and here's Cloud Functions API.
You can prove to yourself that there's no method under Cloud Logging that allows enumeration of all a project's Cloud Functions. But there is a method in Cloud Functions
projects.locations.functions.list
. The latter returns a response body that includes a list offunctions
that are a typeCloudFunction
that have aname
.Another way to understand how these APIs ("libraries") are used is to add
--log-http
to anygcloud
command to see what API calls are being made by the command.