gcp cli 错误 =(gcloud.logging.write) 无法识别的参数
gcp cli error =(gcloud.logging.write) unrecognized arguments
我正在使用以下命令在 gcp 日志中写入日志:
gcloud logging write my-test-log '{ "ServiceName": "$Service1", "SubsystemName": "$subsystem1") --payload-type=json
出现以下错误:
(gcloud.logging.write) unrecognized arguments.
请推荐
您收到该错误是因为您有一些语法错误。
正如 LundinCast 所说,正确的命令应该是:
gcloud logging write my-test-log '{ "ServiceName": "$Service1", "SubsystemName": "$subsystem1"}' --payload-type=json
您只会收到以下输出:
Created log entry.
请查看以下文档以获取更多信息:gcloud logging write
您可以验证它是否可以列出您的 project's logs:
gcloud logging logs list
NAME
projects/<<PROJECT-ID>>/logs/my-test-log
gcloud logging read my-test-log
---
insertId: 1abcd235657fghi
jsonPayload:
ServiceName: $Service1
SubsystemName: $subsystem1
logName: projects/<<PROJECT-ID>>/logs/my-test-log
receiveTimestamp: '2020-11-26T21:10:25.757859880Z'
resource:
labels:
project_id: <<PROJECT-ID>>
type: global
timestamp: '2020-11-26T21:10:25.757859880Z'
编辑 1
我在原来的答案中发现了问题。
要以 json 格式获取变量的值,必须添加 "'"
因此命令应类似于:
gcloud logging write --payload-type=json my-test-log '{ "message": "'"$variable"'" , "weather": "partly cloudy"}'
其中$variable的内容为my-variable-content
insertId: 1y7abcdefghijk
jsonPayload:
message: my-variable-content
weather: partly cloudy
logName: projects/<<PROJECT-ID>>/logs/my-test-log
receiveTimestamp: '2020-12-04T14:03:45.850928566Z'
resource:
labels:
project_id: <<PROJECT-ID>>
type: global
timestamp: '2020-12-04T14:03:45.850928566Z'
我正在使用以下命令在 gcp 日志中写入日志:
gcloud logging write my-test-log '{ "ServiceName": "$Service1", "SubsystemName": "$subsystem1") --payload-type=json
出现以下错误:
(gcloud.logging.write) unrecognized arguments.
请推荐
您收到该错误是因为您有一些语法错误。
正如 LundinCast 所说,正确的命令应该是:
gcloud logging write my-test-log '{ "ServiceName": "$Service1", "SubsystemName": "$subsystem1"}' --payload-type=json
您只会收到以下输出:
Created log entry.
请查看以下文档以获取更多信息:gcloud logging write
您可以验证它是否可以列出您的 project's logs:
gcloud logging logs list
NAME
projects/<<PROJECT-ID>>/logs/my-test-log
gcloud logging read my-test-log
---
insertId: 1abcd235657fghi
jsonPayload:
ServiceName: $Service1
SubsystemName: $subsystem1
logName: projects/<<PROJECT-ID>>/logs/my-test-log
receiveTimestamp: '2020-11-26T21:10:25.757859880Z'
resource:
labels:
project_id: <<PROJECT-ID>>
type: global
timestamp: '2020-11-26T21:10:25.757859880Z'
编辑 1
我在原来的答案中发现了问题。
要以 json 格式获取变量的值,必须添加 "'"
因此命令应类似于:
gcloud logging write --payload-type=json my-test-log '{ "message": "'"$variable"'" , "weather": "partly cloudy"}'
其中$variable的内容为my-variable-content
insertId: 1y7abcdefghijk
jsonPayload:
message: my-variable-content
weather: partly cloudy
logName: projects/<<PROJECT-ID>>/logs/my-test-log
receiveTimestamp: '2020-12-04T14:03:45.850928566Z'
resource:
labels:
project_id: <<PROJECT-ID>>
type: global
timestamp: '2020-12-04T14:03:45.850928566Z'