node服务新增web业务日志及查看日志需要绝对地址

node服务新增web业务日志及查看日志需要绝对地址

node服务在linux服务器上面的目录如下:

root@VM-1-225-centos:/usr/local/auto-node-mytestGw-pro-20009 $ ll
total 412
drwxr-xr-x 7 root root   4096 Sep  1 15:57 app
-rw-r--r-- 1 root root    241 Sep  1 15:57 appveyor.yml
-rw-r--r-- 1 root root   2185 Sep  1 15:57 CHANGELOG.md
drwxr-xr-x 2 root root   4096 Sep  1 15:57 config
-rw-r--r-- 1 root root    480 Sep  1 15:57 docker-compose.yml
-rw-r--r-- 1 root root  19588 Sep  1 15:57 generator-doc.js
-rw-r--r-- 1 root root   6794 Sep  1 15:57 generator-doc.ts
-rw-r--r-- 1 root root   1352 Sep  1 15:57 jenkins.js
lrwxrwxrwx 1 root root     62 Sep  1 15:57 node_modules -> /data/tmp/deploy/auto-node-mytestGw-pro-20009/node_modules
-rw-r--r-- 1 root root   2428 Sep  1 15:57 package.json
-rw-r--r-- 1 root root   1453 Sep  1 15:57 precommit.sh
-rw-r--r-- 1 root root    157 Sep  1 15:57 preload.js
-rw-r--r-- 1 root root    551 Sep  1 15:57 README.md
drwxr-xr-x 2 root root   4096 Sep  1 15:57 run
drwxr-xr-x 4 root root   4096 Sep  1 15:57 test
-rw-r--r-- 1 root root    717 Sep  1 15:57 tsconfig.json
drwxr-xr-x 4 root root   4096 Sep  1 15:57 typings
-rw-r--r-- 1 root root 328794 Sep  1 15:57 yarn.lock

config.prod.js    日志的配置文件

config.logger = {
        level: 'INFO',
        outputJSON: true,
		dir: '/usr/local/auto-node-mytestGw-pro-20009/logs',	// ⭐ 明确路径   新增
    };

1.发布jenkins没有日志输出,查下来是jenkins里面的git仓库地址配置老的地址,而不是最新的地址,导致新修改的代码和分支都没有生效。

2.在logs文件夹里面没有找到,通过命令搜索
grep code2token /usr/local/auto-node-mytestGw-pro-20009/logs/mytestGw-web.json.log | tail -n 50 -- 关键入口 --

sz /usr/local/auto-node-mytestGw-pro-20009/logs/mytestGw-web.json.log 下载的日志文件中有接口请求日志,
但是 cd /usr/local/auto-node-mytestGw-pro-20009/logs 然后再 sz mytestGw-web.json.log 居然下载的日志文件中就没有接口请求日志,通过测试下来就是存在该情况。。

# 1) 确认 cd 是否真的成功,以及当前所在目录
cd /usr/local/auto-node-mytestGw-pro-20009/logs
pwd
ls -la mytestGw-web.json.log

# 2) 看这个文件本身是不是软链接,以及大小/修改时间
ls -la /usr/local/auto-node-mytestGw-pro-20009/logs/mytestGw-web.json.log

# 3) 直接比较两次"下载源"是否同一文件:用绝对路径再 sz 一次
# 这次先在 logs 目录里,对比 inode(绝对路径 vs 相对路径是否同一文件)
ls -li /usr/local/auto-node-mytestGw-pro-20009/logs/mytestGw-web.json.log mytestGw-web.json.log

-- 果然文件大小有区别啊 --

root@VM-1-225-centos:/usr/local/auto-node-mytestGw-pro-20009/logs $ pwd
/usr/local/auto-node-mytestGw-pro-20009/logs
root@VM-1-225-centos:/usr/local/auto-node-mytestGw-pro-20009/logs $ ls -la mytestGw-web.json.log
-rw-r--r-- 1 root root 76080 Sep  1 17:29 mytestGw-web.json.log
root@VM-1-225-centos:/usr/local/auto-node-mytestGw-pro-20009/logs $ ls -la /usr/local/auto-node-mytestGw-pro-20009/logs/mytestGw-web.json.log
-rw-r--r-- 1 root root 102876 Sep  1 18:00 /usr/local/auto-node-mytestGw-pro-20009/logs/mytestGw-web.json.log
root@VM-1-225-centos:/usr/local/auto-node-mytestGw-pro-20009/logs $ ls -li /usr/local/auto-node-mytestGw-pro-20009/logs/mytestGw-web.json.log mytestGw-web.json.log
3301125 -rw-r--r-- 1 root root  76080 Sep  1 17:29 mytestGw-web.json.log
3822112 -rw-r--r-- 1 root root 104461 Sep  1 18:00 /usr/local/auto-node-mytestGw-pro-20009/logs/mytestGw-web.json.log

查看日志也是绝对地址:
tail -f /usr/local/auto-node-mytestGw-pro-20009/logs/mytestGw-web.json.log

业务日志分析:

{"paddingMessage":"[-/172.16.1.247/-/9ms POST /public/miniprograms/code2token]","level":"INFO","date":"2026-09-01 18:07:46,485","pid":31431,"hostname":"VM-1-225-centos","message":"[code2token] matched service. traceId= type=wechat-mini appId=wx8ad7489f7f948e38"}
{"paddingMessage":"[-/172.16.1.247/-/9ms POST /public/miniprograms/code2token]","level":"INFO","date":"2026-09-01 18:07:46,485","pid":31431,"hostname":"VM-1-225-centos","message":"[wechat.requestToApiHost] request out. url=/sns/jscode2session method=GET apiHost=https://api.weixin.qq.com appid=wx8a****8e38 secret=e5cb****54fc js_code=081abcTESTdef123 grant_type=authorization_code"}
{"paddingMessage":"[-/172.16.1.247/-/170ms POST /public/miniprograms/code2token]","level":"INFO","date":"2026-09-01 18:07:46,646","pid":31431,"hostname":"VM-1-225-centos","message":"[wechat.requestToApiHost] url=/sns/jscode2session appid=wx8ad7489f7f948e38 resp={\"errcode\":40029,\"errmsg\":\"invalid code, rid: 6a96a3f2-0c83385f-09af965f\"}"}
{"paddingMessage":"[-/172.16.1.247/-/176ms POST /public/miniprograms/code2token]","level":"ERROR","date":"2026-09-01 18:07:46,652","pid":31431,"hostname":"VM-1-225-centos","message":"[code2token] error. traceId= type=wechat-mini code=081abcTESTdef123 errName=BadRequestError errMsg=invalid code, rid: 6a96a3f2-0c83385f-09af965f resCode=40029 stack=BadRequestError: invalid code, rid: 6a96a3f2-0c83385f-09af965f |     at Object.exports.passServerError (/data/tmp/deploy/auto-node-mytestGw-pro-20009/20260901_180719/auto-node-mytestGw-pro-20009/app/lib/http-error.ts:18:15) |     at ctx.curl.then.result (/data/tmp/deploy/auto-node-mytestGw-pro-20009/20260901_180719/auto-node-mytestGw-pro-20009/app/service/wechat.ts:115:21) |     at process._tickCallback (internal/process/next_tick.js:68:7)"}
{"paddingMessage":"[-/172.16.1.247/-/177ms POST /public/miniprograms/code2token]","level":"WARN","date":"2026-09-01 18:07:46,653","pid":31431,"hostname":"VM-1-225-centos","message":"{\"message\":\"invalid code, rid: 6a96a3f2-0c83385f-09af965f\",\"resCode\":40029,\"raw\":{\"errcode\":40029,\"errmsg\":\"invalid code, rid: 6a96a3f2-0c83385f-09af965f\"},\"requestInfo\":{\"method\":\"POST\",\"url\":\"/public/miniprograms/code2token\",\"header\":{\"user-agent\":\"curl/7.29.0\",\"host\":\"172.16.1.225:20009\",\"accept\":\"*/*\",\"content-type\":\"application/json\",\"content-length\":\"48\"},\"rawBody\":{\"code\":\"081abcTESTdef123\",\"type\":\"wechat-mini\"},\"query\":\"\",\"spendingTime\":176},\"path\":\"/public/miniprograms/code2token\",\"status\":400,\"name\":\"BadRequestError\",\"stack\":\"BadRequestError: invalid code, rid: 6a96a3f2-0c83385f-09af965f\\n    at Object.exports.passServerError (/data/tmp/deploy/auto-node-mytestGw-pro-20009/20260901_180719/auto-node-mytestGw-pro-20009/app/lib/http-error.ts:18:15)\\n    at ctx.curl.then.result (/data/tmp/deploy/auto-node-mytestGw-pro-20009/20260901_180719/auto-node-mytestGw-pro-20009/app/service/wechat.ts:115:21)\\n    at process._tickCallback (internal/process/next_tick.js:68:7)\"}"}
{"paddingMessage":"[-/172.16.1.181/-/0ms HEAD /health]","level":"INFO","date":"2026-09-01 18:07:48,186","pid":31424,"hostname":"VM-1-225-centos","message":"{\"path\":\"/health\",\"status\":200,\"requestInfo\":{\"method\":\"HEAD\",\"url\":\"/health\",\"header\":{},\"rawBody\":{},\"query\":\"\",\"spendingTime\":0}}"}

分析推测如下:
接口这个code参数是从哪里获取的?我对比看了下其他的参数(appid和secret)是对的,唯一可能不对的是code的这个参数
上面的日志是我单独curl请求的模拟参数, curl -X POST 'http://测试地址IP:20009/public/miniprograms/code2token' -H 'Content-Type: application/json' -d '{"code":"081abcTESTdef123","type":"wechat-mini"}';
返回
{"name":"BadRequestError","message":"invalid code, rid: 6a96a3f2-0c83385f-09af965f"}
而从测试的微信小程序上面点击,没有日志打印出来。推测请求没有过来

还有一个方法,测试的微信小程序,将请求按Ip来调用试试
http://测试地址IP:20009/public/miniprograms/code2token
可以排除一下问题

猜测是运维配置的nginx转发到老的微信服务上去了,必然会报错,微信appid这些都不一样
https://m.mytesttest.com/apigateway/thirdpartyauth/public/miniprograms/code2token
请求400
{"name":"BadRequestError","message":"invalid code, rid: 6a968508-03651f6c-0f47dabb"}

比如老的地址是(域名上少一个test): https://m.mytest.com/apigateway/thirdpartyauth/public/miniprograms/code2token

posted on 2026-09-02 11:07  oktokeep  阅读(11)  评论(0)    收藏  举报