1) 使用processors
processors:
- timestamp:
# 格式化时间值 给 时间戳
field: start_time
# 使用我国东八区时间 解析log时间
timezone: Asia/Shanghai
layouts:
- '2006-01-02 15:04:05'
- '2006-01-02 15:04:05.999'
test:
- '2019-06-22 16:33:51'
AI 代码解读
2) 修改fields.xml文件(不推荐,具体看参考文章3)
3) 使用属性覆盖
在input部分配置
json.keys_under_root: true
json.overwrite_keys: true
AI 代码解读
且输入的json的 @timestamp 的值得格式化方式必须为
yyyy-MM-ddTHH:mm:ss.fffZ #其中fff表示毫秒,因为编程语言的不同要进行相应的更换
4) 使用codec.format
output.kafka:
hosts: ["139.224.106.236:9092"]
topic: '%{[fields.kafka_topic]}' #当使用了json.keys_under_root,直接使用指定属性名即可
version: 0.11.0.0
compression: gzip
max_message_bytes: 1000000
# 只输出message
codec.format:
string: '%{[message]}'
AI 代码解读