[英]How can I see ChromeLogger output in the Postman console when debugging an API?
I have set up ChromeLogger , the browser extension and the backend library, which works fine. 我已经设置了ChromeLogger ,浏览器扩展程序和后端库,它们工作正常。
However I am developing an API which I test in Postman not in the browser so I want to see the same debug logs in Postman in the console or somewhere in the response previews. 但是,我正在开发一个API,该API在Postman中进行测试,而不是在浏览器中进行测试,因此我想在控制台或响应预览中的某处在Postman中查看相同的调试日志。
Is there any way of installing an extension into Postman, the same as the browser extension? 有什么方法可以将扩展程序安装到Postman中,与浏览器扩展程序相同吗?
After reading this article , which explains how the debug logs are encoded in a header, I thought I could just write a post-response "test" in Postman to unpack the header and log it into the Postman console. 阅读完这篇文章 ,其中解释了调试日志是如何在标头中编码的,我想我可以在Postman中编写一个响应后的“测试”来解压标头并将其记录到Postman控制台中。
This Postman article explains how you can set a "test" globally by editing the test suite itself or folders, so you can make this work pretty much like an extension without having to add it to each request. 这篇邮递员文章解释了如何通过编辑测试套件本身或文件夹来全局设置“测试”,因此您可以使这项工作像扩展一样,而不必将其添加到每个请求中。 Click the '...' ellipsis next to the test suite, click Edit, choose the Tests tab and enter the JavaScript code below.
单击测试套件旁边的“ ...”省略号,单击“编辑”,选择“测试”选项卡,然后在下面输入JavaScript代码。
I tried three ways of outputting the data, each with their strengths and weaknesses, as noted in the comments. 如注释中所述,我尝试了三种输出数据的方法,每种方法都有其优缺点。
// Decode any ChromeLogger data
var chromelogger = postman.getResponseHeader("X-ChromeLogger-Data");
if(chromelogger){
chromelogger = JSON.parse(atob(chromelogger));
if(chromelogger){
// Native objects - well structured, but you have to expand all the rows every time... tedious!
//console.log(chromelogger);
// Raw JSON - always visible but can be hard to read
// console.log(atob(postman.getResponseHeader("X-ChromeLogger-Data")));
// For known structures, you can display it yourself
chromelogger.rows.forEach( row => {
console.log(row[1]); // display source line
row[0].forEach(log => {
console.log(log);
})
})
}
}
Now when you run any test, all the Chromelogger debug is displayed in the Postman Console. 现在,当您运行任何测试时,所有Chromelogger调试都将显示在Postman控制台中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.