Commit 030e2adb by Sxy

fix: filebeat 日志打印

parent 01310dcc
...@@ -9,6 +9,10 @@ filebeat.inputs: ...@@ -9,6 +9,10 @@ filebeat.inputs:
paths: paths:
- /Users/shaoxingye/Documents/WORK/ownerproject/message-call-service/logs/*.log - /Users/shaoxingye/Documents/WORK/ownerproject/message-call-service/logs/*.log
json.keys_under_root: true
json.overwrite_keys: true
# ============================== Filebeat modules ============================== # ============================== Filebeat modules ==============================
...@@ -40,12 +44,8 @@ setup.kibana: ...@@ -40,12 +44,8 @@ setup.kibana:
# ================================= Processors ================================= # ================================= Processors =================================
processors: processors:
- decode_json_fields: - drop_fields:
fields: ['message'] #要进行解析的字段 fields: ["ecs","input","agent"]
target: "" #json内容解析到指定的字段,如果为空(“”),则解析到顶级结构下
overwrite_keys: false #如果解析出的json结构中某个字段在原始的event(在filebeat中传输的一条数据为一个event)中也存在,是否覆盖event中该字段的值,默认值:false
process_array: false #数组是否解码,默认值:false
max_depth: 1 #解码深度,默认值:1
......
...@@ -2,8 +2,11 @@ import { createLogger, format, transports } from 'winston'; ...@@ -2,8 +2,11 @@ import { createLogger, format, transports } from 'winston';
import 'winston-daily-rotate-file'; import 'winston-daily-rotate-file';
import { getNamespace } from 'cls-hooked'; import { getNamespace } from 'cls-hooked';
import os from 'os' import os from 'os'
import moment from 'moment';
import path from "path"
const myFormat = format.printf(({ level, message, timestamp, requestId }) => { const myFormat = format.printf(({ level, message, timestamp, requestId }) => {
return `[${timestamp}] [${level}] ${requestId ? ("[" + requestId + "] :") : ''} ${message}`; return `[${moment(timestamp).format("YYYY-MM-DD hh:mm:ss.SSS")}] [${level}] ${requestId ? ("[" + requestId + "] :") : ''} ${message}`;
}); });
const requestId = format((info) => { const requestId = format((info) => {
...@@ -13,11 +16,12 @@ const requestId = format((info) => { ...@@ -13,11 +16,12 @@ const requestId = format((info) => {
if (!requestId && Object.prototype.toString.call(message) === "[object Object]" && message.requestId) { if (!requestId && Object.prototype.toString.call(message) === "[object Object]" && message.requestId) {
requestId = message.requestId requestId = message.requestId
} }
info.requestId = requestId || '-' if (Object.prototype.toString.call(message) === "[object Object]") {
info.message = JSON.stringify(message) info.message = JSON.stringify(message)
}
info.requestId = requestId || '-'
return info return info
}) })
import path from "path"
const logger = createLogger({ const logger = createLogger({
level: 'info', level: 'info',
......
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