Apigee JavaScript 资源输出 运行 Cloud Code 模拟器?
Apigee JavaScript resource output running Cloud Code emulator?
我正在使用 VS Code Cloud Code 插件编写 Apigee JavaScript 策略资源,但无法找到 print
语句输出 - 运行 Apigee ( Docker) 模拟器?
TIA。
print
输出在 Apigee 本地开发模拟器中不可用,只能在实际 Apigee 产品中使用 Debug 或 Trace。
为了解决这个问题,我编写了几个辅助函数,它们记录到 context
,然后将日志转储到响应 header:
function logMsg(msg) {
var index = context.getVariable("logger.index");
if (index == null) {
index = 1;
}
context.setVariable("logger.logMsg-" + index, msg);
index = index + 1;
context.setVariable("logger.index", index);
}
// Call this function during Response processing
function logsToResponseHeader() {
var index = context.getVariable("logger.index");
if (index == null) {
context.proxyResponse.headers['Z-Log-0'] = 'logger.index == null';
return
}
context.proxyResponse.headers['Z-Log-0'] = 'logger.index == ' + index + ' type: ' + typeof (index);
for (var i = 1; i < index; i++) {
var msg = context.getVariable("logger.logMsg-" + i);
if (msg == null) {
context.proxyResponse.headers['Z-Log-' + i] = 'Null msg';
} else {
context.proxyResponse.headers['Z-Log-' + i] = msg;
}
}
}
来自 curl -v
的示例输出:
< Z-Log-0: logger.index == 11 type: number
< Z-Log-1: Trace-Context-Request: enter
< Z-Log-2: Trace-Context-Request: exit
< Z-Log-3: Trace-Context-Response: enter
< Z-Log-4: WARN: null value for TraceEndTimestamp:
< Z-Log-5: RequestParentID:
< Z-Log-6: ParentID: 769db5b4
< Z-Log-7: TraceID: 9b5c3406fdd0d275
< Z-Log-8: TraceFlags: 01
< Z-Log-9: parentStartTime: 1640441735345
< Z-Log-10: Trace-Context-Response: exit
我正在使用 VS Code Cloud Code 插件编写 Apigee JavaScript 策略资源,但无法找到 print
语句输出 - 运行 Apigee ( Docker) 模拟器?
TIA。
print
输出在 Apigee 本地开发模拟器中不可用,只能在实际 Apigee 产品中使用 Debug 或 Trace。
为了解决这个问题,我编写了几个辅助函数,它们记录到 context
,然后将日志转储到响应 header:
function logMsg(msg) {
var index = context.getVariable("logger.index");
if (index == null) {
index = 1;
}
context.setVariable("logger.logMsg-" + index, msg);
index = index + 1;
context.setVariable("logger.index", index);
}
// Call this function during Response processing
function logsToResponseHeader() {
var index = context.getVariable("logger.index");
if (index == null) {
context.proxyResponse.headers['Z-Log-0'] = 'logger.index == null';
return
}
context.proxyResponse.headers['Z-Log-0'] = 'logger.index == ' + index + ' type: ' + typeof (index);
for (var i = 1; i < index; i++) {
var msg = context.getVariable("logger.logMsg-" + i);
if (msg == null) {
context.proxyResponse.headers['Z-Log-' + i] = 'Null msg';
} else {
context.proxyResponse.headers['Z-Log-' + i] = msg;
}
}
}
来自 curl -v
的示例输出:
< Z-Log-0: logger.index == 11 type: number
< Z-Log-1: Trace-Context-Request: enter
< Z-Log-2: Trace-Context-Request: exit
< Z-Log-3: Trace-Context-Response: enter
< Z-Log-4: WARN: null value for TraceEndTimestamp:
< Z-Log-5: RequestParentID:
< Z-Log-6: ParentID: 769db5b4
< Z-Log-7: TraceID: 9b5c3406fdd0d275
< Z-Log-8: TraceFlags: 01
< Z-Log-9: parentStartTime: 1640441735345
< Z-Log-10: Trace-Context-Response: exit