DocumentDB 存储过程:EnableScriptLogging 选项有什么作用?
DocumentDB Stored Procs: what does the EnableScriptLogging option do?
用于处理存储过程的 DocumentDB API 采用可选的 RequestOptions
参数,其中包含 属性 EnableScriptLogging
。
help page对它没用。它的描述是:
EnableScriptLogging is used to enable/disable logging in JavaScript stored procedures.
Mkay...所以我如何记录一些东西? (假设是 console.log(...)
)
更重要的是,如何读取 存储过程生成的日志?
我原以为对存储过程的 response
请求会以某种方式包含日志,但找不到任何内容。
是的,这是来自脚本的 console.log。必须由客户端启用(默认情况下关闭,以便忽略脚本中的 console.log),本质上是根据请求设置 http-header。
在脚本中你可以这样做:
function myScript() {
console.log("This is trace log");
}
日志将响应 header (x-ms-documentdb-script-log-results),并且可以在 SDK 中访问。
如果你使用C# SDK,你可以这样使用:
var options = new RequestOptions { EnableScriptLogging = true };
var response = await client.ExecuteStoredProcedureAsync<string>(sprocUri, options);
Console.WriteLine(response.ScriptLog);
如果您使用 node.js SDK:
var lib = require("documentdb");
var Client = lib.DocumentClient;
var client = new Client("https://xxxxxxx.documents.azure.com:443/", { masterKey: "xxxxxxxxxxxx" });
var sprocLink = ...;
client.executeStoredProcedure(sprocLink, "input params", { partitionKey: {}, enableScriptLogging: true }, function(err, res, responseHeaders) {
console.log(responseHeaders[lib.Constants.HttpHeaders.ScriptLogResults]);
}
当前限制:
- 仅对存储过程启用
- \n 不受支持(应尽快修复)
- 当脚本抛出未处理的异常时不支持(应尽快修复)
用于处理存储过程的 DocumentDB API 采用可选的 RequestOptions
参数,其中包含 属性 EnableScriptLogging
。
help page对它没用。它的描述是:
EnableScriptLogging is used to enable/disable logging in JavaScript stored procedures.
Mkay...所以我如何记录一些东西? (假设是 console.log(...)
)
更重要的是,如何读取 存储过程生成的日志?
我原以为对存储过程的 response
请求会以某种方式包含日志,但找不到任何内容。
是的,这是来自脚本的 console.log。必须由客户端启用(默认情况下关闭,以便忽略脚本中的 console.log),本质上是根据请求设置 http-header。
在脚本中你可以这样做:
function myScript() {
console.log("This is trace log");
}
日志将响应 header (x-ms-documentdb-script-log-results),并且可以在 SDK 中访问。
如果你使用C# SDK,你可以这样使用:
var options = new RequestOptions { EnableScriptLogging = true };
var response = await client.ExecuteStoredProcedureAsync<string>(sprocUri, options);
Console.WriteLine(response.ScriptLog);
如果您使用 node.js SDK:
var lib = require("documentdb");
var Client = lib.DocumentClient;
var client = new Client("https://xxxxxxx.documents.azure.com:443/", { masterKey: "xxxxxxxxxxxx" });
var sprocLink = ...;
client.executeStoredProcedure(sprocLink, "input params", { partitionKey: {}, enableScriptLogging: true }, function(err, res, responseHeaders) {
console.log(responseHeaders[lib.Constants.HttpHeaders.ScriptLogResults]);
}
当前限制:
- 仅对存储过程启用
- \n 不受支持(应尽快修复)
- 当脚本抛出未处理的异常时不支持(应尽快修复)