前言
内置的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,"