关于用log提高排查问题的设置

213 阅读1分钟

今天在了解项目业务的时候,想搞清楚执行顺序,加了很多打印,类似console.log(1111,xxxx) console.log(2222,xxxx),有时候断点没开sourcemap不是源码所以我更喜欢打印,然后就导致打印比较紊乱,而且前面的1111  2222标识多了就不够清晰,就写了 一个这个配置很方便,输入log直接出现文件名和第多少行

QQ_1722326175527.png

具体配置如下:
打开 VSCode。
按 Ctrl+Shift+P(Windows/Linux)或 Cmd+Shift+P(macOS)打开命令面板。
输入 Preferences: Configure User Snippets  
选择对应文件代码片段 我选的是全局

{  
        // Place your snippets for javascript here. Each snippet is defined under a snippet name and has a prefix, body and  
        // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:  
        // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the  
        // same ids are connected.  
        // Example:  
        "Print to console": {  
                "prefix": ["console.log""console""log"],  
                "body": [  
                        "console.log('log输出--:[$TM_FILENAME:$TM_LINE_NUMBER]行:', $1);"  
                ],  
                "description""Log output to console"  
        }  
}

 
输入一下格式 保存即可,body里面可以自定义。

也有同事推荐了urbo Console Log 这个拓展,小火箭打印,但是我觉得扩展插件的注入应该增加了体积,我就自己写了一个,大家可以按需使用。

EDN