使用Makefile执行命令时如何显示完整输出?
问题:Makefile执行
make watch无法输出完整日志 直接执行命令时,能得到完整输出:
[GIN-debug] GET /internal/login --> myproject/app_demo.AppHandler.InternalLogin-fm (7 handlers) [GIN-debug] POST /wp/index --> myproject/wp_demo.indexHandler (6 handlers) [GIN-debug] POST /wp/single --> myproject/wp_demo.singleHandler (6 handlers) [GIN-debug] POST /wp/posts --> myproject/wp_demo.postsHandler (6 handlers) [GIN-debug] POST /wp/counts --> myproject/wp_demo.countsHandler (6 handlers) [GIN-debug] POST /wp/get_options --> myproject/wp_demo.getOptionsHandler (6 handlers) [GIN-debug] POST /cful/index --> myproject/cful_demo.indexHandler (6 handlers) [GIN-debug] POST /cful/single --> myproject/cful_demo.singleHandler (6 handlers) [GIN-debug] POST /cful/posts --> myproject/cful_demo.postsHandler (6 handlers) [GIN-debug] POST /cful/counts --> myproject/cful_demo.countsHandler (6 handlers) [GIN-debug] POST /cms/index --> myproject/cms_demo.CmsHandler.indexHandler-fm (7 handlers) [GIN-debug] POST /cms/single --> myproject/cms_demo.CmsHandler.singleHandler-fm (7 handlers) [GIN-debug] POST /cms/posts --> myproject/cms_demo.CmsHandler.postsHandler-fm (7 handlers) [GIN-debug] POST /cms/counts --> myproject/cms_demo.CmsHandler.countsHandler-fm (7 handlers) 2022/12/29 12:17:54 Http Sever started at http://localhost:2111 [GIN-debug] [WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value. Please check https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-proxies for details. [GIN-debug] Listening and serving HTTP on :2111
但执行make watch时,仅输出:
➜ myproject git:(main) ✗ make watch 2022/12/29 12:18:23 Http Sever started at http://localhost:2111
当前Makefile内容:
hello: @echo "Hello, Mango" watch: @echo `air`
解决方案
问题根源在于@echo \air`的写法:这种方式会执行air`命令,但只捕获它的标准输出(stdout),而Gin的调试日志、警告信息是输出到**标准错误(stderr)**的,这部分内容被直接丢弃,所以只显示了服务启动的一行日志。
修改Makefile的watch目标,直接执行air命令即可:
hello: @echo "Hello, Mango" watch: air
如果不想让Makefile打印出air这个命令本身,可以保留@符号:
watch: @air
修改后,air的标准输出和标准错误都会被正常输出,就能看到完整的Gin调试日志、警告及服务启动信息了。
内容的提问来源于stack exchange,提问作者Khanakia
相关产品推荐
相关产品推荐

