DocumentDB Stored Procs: what does the EnableScriptLogging option do?

孤人 提交于 2019-12-11 05:28:32

问题


The DocumentDB APIs for working with stored procedures take an optional RequestOptions argument that has, among others, the property EnableScriptLogging.

The help page for it is useless. The description for it is:

EnableScriptLogging is used to enable/disable logging in JavaScript stored procedures.

Mkay... so how do I log something? (assuming that's console.log(...)) And more importantly, how do I read the logs generated by stored procedures?

I was expecting the response of requests to stored procedures would somehow contain the logs, but can't find anything.


回答1:


Yes, this is for console.log from script. Must be enabled by client (turned off by default, so that console.log in script is ignored), essentially this set http-header on request.
In script you can do something like this:

function myScript() { 
  console.log("This is trace log");
}

The log will be in response header (x-ms-documentdb-script-log-results), as well as can be accessible in SDK.

If you use C# SDK, you can use it like this:

var options = new RequestOptions { EnableScriptLogging = true };
var response = await client.ExecuteStoredProcedureAsync<string>(sprocUri, options);
Console.WriteLine(response.ScriptLog);

If you use 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]);
}

Current limitations:

  • only enabled for stored procedures
  • \n is not supported (should be fixed soon)
  • not supported when script throws unhandled exception (should be fixed soon)


来源:https://stackoverflow.com/questions/44610233/documentdb-stored-procs-what-does-the-enablescriptlogging-option-do

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