Commit 8361d500 by Sxy

feat: 日志配置

parent 3781bc86
#### 实现功能
* 消息请求失败重试
* 消息请求延时发送
* 全链路日志
#### 启动
......@@ -89,3 +90,9 @@ method : post
}
```
#### filebeat 读取 日志
```
./filebeat -e -c {自定义}/filebeat.yml
```
......@@ -11,7 +11,7 @@ import moment from "moment"
import rabbmitmqUtil from "./utils/rabbitmq"
rabbmitmqUtil.initQueue()
import correlation from './middleware/correlation'
import { createNamespace } from 'cls-hooked'
import { createNamespace, getNamespace } from 'cls-hooked'
const logNameSpace = createNamespace('logger')
......@@ -47,6 +47,8 @@ app.use(correlation(logNameSpace));
app.use(async (ctx, next) => {
const start = new Date()
await next()
const logNameSpace = getNamespace('logger');
ctx.response.body.requestId = logNameSpace.get("requestId")
logger.info({
request: ctx.request,
response: ctx.body,
......
# WARNING! Do not edit this file directly, it was generated by the ECS project,
# based on ECS version 1.9.0.
# Please visit https://github.com/elastic/ecs to suggest changes to ECS fields.
- key: ecs
title: ECS
description: ECS Fields.
fields:
- name: timestamp
level: core
required: true
type: date
description: 'Date/time when the event originated.
This is the date/time extracted from the event, typically representing when
the event was generated by the source.
If the event source has no original timestamp, this value is typically populated
by the first time the event was received by the pipeline.
Required field for all events.'
example: '2016-05-23T08:05:34.853Z'
- name: level
level: core
type: keyword
- name: serverName
level: core
type: keyword
- name: requestId
level: core
type: keyword
- name: message
level: core
type: keyword
\ No newline at end of file
import { getNamespace } from 'cls-hooked';
export const ok = (data) => {
const logNameSpace = getNamespace('logger');
return {
code: 0,
success: true,
message: null,
data,
requestId: logNameSpace.get("requestId"),
}
}
export const error = (msg = "未知错误", code = -1) => {
const logNameSpace = getNamespace('logger');
return {
code,
success: false,
message: msg,
data: null,
requestId: logNameSpace.get("requestId"),
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment