简体   繁体   English

调试API时,如何在Postman控制台中看到ChromeLogger输出?

[英]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.

相关问题 调试时如何从 WCF 服务内部查看控制台 output? - How can I see console output from inside WCF service while debugging? 使用Xcode 5调试时如何查看输出控制台(IE stdout)? - How to see the output console (I.E. stdout) when debugging with Xcode 5? 如何从独立的qml应用程序中查看控制台输出? - How can I see console output from standalone qml application? 调试Javascript时如何在PHPStorm中输出到控制台? - How to output to console in PHPStorm when debugging Javascript? 在 Eclipse 中调试 C/C++ 代码时如何查看全局变量? - How can I see global variables when debugging C/C++ code in Eclipse? 在Android上调试javascript时如何查看断点(并查看错误行号)? - How can I hit breakpoints (and see error line numbers) when debugging javascript on Android? 我如何将 output 转到网站而不是控制台以在 Rails 中进行调试? - How do I output to website instead of console for debugging in Rails? 如何在Salesforce中查看所有调试信息? - How can I see all debugging information in Salesforce? 如何在程序中启动 python 控制台(以便于调试)? - How can I start the python console within a program (for easy debugging)? 设备连接到另一台硬件设备时如何获得实时控制台输出? - How can I get live console output when device is connected to another hardware device?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM