我正在尝试从我的 Google Apps 脚本 - Data Studio 社区连接器代码记录 JSON 对象到 Stackdriver Logging,如官方文档中所述
使用
console.log(jsonObject)
将jsonObject转换为字符串。没用。
使用
Logger.log(jsonObject)
代替,在日志条目的 jsonPayload 属性内解析 jsonObject 。好。
但是 所有日志条目都以 INFO 严重级别插入。
如果我在 jsonObject 中包含严重性属性,严重性不会按预期进行解析。
我尝试了一些选项,包括将严重性设置为字符串“ERROR”或数字 500,但它不起作用。
我从社区连接器代码中尝试过的一些示例:
Logger.log({
message: 'This is the message / title for the log entry. Works fine',
severity: 'ERROR',
otherData: {
userId: '459',
connectorType: 'blahblah',
includeFilters: true
}
});
或
Logger.log({
message: 'This is the message / title for the log entry. Works fine',
severity: 500,
otherData: {
userId: '459',
connectorType: 'blahblah',
includeFilters: true
}
});
Logger
其实还有更多可用的方法:'warning', 'config', 'severe', 'info', 'fine', 'finer', 'finest'
它们仍然没有证件,但工作得很好。