问题
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