NestJS 7.x 折腾记: (3) 采用nestjs-pino作为Nest logger

前言

内置的logger不是很满足个人的需求,
所以找了下社区主流的日志实现,
log4js,winston, 到选型pino .


是另外两个不好么,那倒不是.
萝卜青菜各有所爱吧,
pino够轻量,自定义还算丰富,性能还很高!!

效果图

开发模式

INFO     [2020-11-09 08:45:12.336 +0000] (56588 on crper-MBP.local): AppController {
   /api/v1}:
    context: "RoutesResolver"
INFO     [2020-11-09 08:45:12.340 +0000] (56588 on crper-MBP.local): Mapped {
   /api/v1, GET} route
    context: "RouterExplorer"
INFO     [2020-11-09 08:45:12.341 +0000] (56588 on crper-MBP.local): Mapped {
   /api/v1/post, POST} route
    context: "RouterExplorer"
INFO     [2020-11-09 08:45:12.341 +0000] (56588 on crper-MBP.local): Mapped {
   /api/v1/user, GET} route
    context: "RouterExplorer"
INFO     [2020-11-09 08:45:12.342 +0000] (56588 on crper-MBP.local): Mapped {
   /api/v1/netease-news/:id, GET} route
    context: "RouterExplorer"
INFO     [2020-11-09 08:45:12.344 +0000] (56588 on crper-MBP.local): Nest application successfully started
    context: "NestApplication"
    Swagger文档链接: http://localhost:3000/api-docs
    Restful接口链接: http://localhost:3000/api/v1
AppController newDz Before...
AppController newDz  After... +1761ms
INFO     [2020-11-09 08:45:52.082 +0000] (56588 on crper-MBP.local): request completed
    响应信息: {
   
      "statusCode": 200,
      "headers": {
   
        "content-security-policy": "default-src 'self';base-uri 'self';block-all-mixed-content;font-src 'self' https: data:;frame-ancestors 'self';img-src 'self' data:;object-src 'none';script-src 'self';script-src-attr 'none';style-src 'self' https: 'unsafe-inline';upgrade-insecure-requests",
        "x-dns-prefetch-control": "off",
        "expect-ct": "max-age=0",
        "x-frame-options": "SAMEORIGIN",
        "strict-transport-security": "max-age=15552000; includeSubDomains",
        "x-download-options": "noopen",
        "x-content-type-options": "nosniff",
        "x-permitted-cross-domain-policies": "none",
        "referrer-policy": "no-referrer",
        "x-xss-protection": "0",
        "content-type": "application/json; charset=utf-8",
        "content-length": "853",
        "etag": "W/\"355-KpR/5mF8Y34126QG9UV2LArJxBw\"",
        "vary": "Accept-Encoding"
      }
    }
    响应时间(ms): 1772
    请求信息: {
   
      "id": 1,
      "method": "GET",
      "url": "/api/v1/netease-news/11",
      "headers": {
   
        "host": "localhost:3000",
        "user-agent": "insomnia/2020.4.2",
        "content-type": "application/json",
        "accept": "*/*",
        "content-length": "23"
      },
      "remoteAddress": "::ffff:127.0.0.1",
      "remotePort": 61069,
      "httpVersion": "1.1",
      "params": {
   
        "0": "/netease-news/11"
      },
      "query": {
   },
      "body": {
   
        "asdfs": "12321"
      }
    }

生产模式

2020-11-09 16:46 +08:00: /Users/linqunhe/Code/aozhe/h3yun-frontend-bff/h3yun-bff-core/config/env/dev.local.env
2020-11-09 16:46 +08:00: /Users/linqunhe/Code/aozhe/h3yun-frontend-bff/h3yun-bff-core/config/env/http.env
2020-11-09 16:46 +08:00: /Users/linqunhe/Code/aozhe/h3yun-frontend-bff/h3yun-bff-core/config/env/report.env
2020-11-09 16:46 +08:00: {
   "level":30,"time":1604911609493,"pid":57279,"hostname":"crper-MBP.local","context":"RoutesResolver","msg":"AppController {/api/v1}:"}
2020-11-09 16:46 +08:00: {
   "level":30,"time":1604911609494,"pid":57279,"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

crper

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值