Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
787 views
in Technique[技术] by (71.8m points)

logstash - Logback losghstash appender add own field

I need to send application logs directly to logstash using: Logstash Logback Encoder from multiple microservices. Problem is that when I am sending logs logstash recive logs like this:

{
  "_index": "logstash-2021.01.21-000001",
  "_type": "_doc",
  "_id": "id",
  "_version": 1,
  "_score": 1.6928859,
  "_source": {
    "@timestamp": "2021-01-21T14:13:05.480Z",
    "@version": "1",
    "message": "message",
    "host": "gateway",
    "port": 43892
  },
  "fields": {
    "@timestamp": [
      "2021-01-21T14:13:05.480Z"
    ]
  },
  "highlight": {
    "message": [msg]
  },
  "sort": [ sort ]
}

I need to add a custom field in "fields" section or in general section. Do you have any idea how I can do this?

question from:https://stackoverflow.com/questions/65829842/logback-losghstash-appender-add-own-field

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use mutate filter in your logstash configuration file.

For example, into logstash configuration your file, this looks like this :

filter {
  mutate { add_field => { "field_name" => "field_value" } }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...