# Process logs of different formats to JSON

**URL:** https://discuss.elastic.co/t/process-logs-of-different-formats-to-json/339258
**Category:** Logstash
**Created:** [July 26, 2023, 6:45am UTC](https://discuss.elastic.co/t/process-logs-of-different-formats-to-json/339258 "2023-07-26T06:45:42Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Chel\_Db](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chel_db/32/121875_2.png) [@Chel\_Db](https://discuss.elastic.co/u/Chel_Db)
#### Post date: [July 26, 2023, 6:45am UTC](https://discuss.elastic.co/t/process-logs-of-different-formats-to-json/339258/1 "2023-07-26T06:45:43Z")

</div>

I'm pretty new to ELK and I'm trying to push few of our service's logs to ES.

Log funneling flow is --\> `

`Fluentd --> Logstash --> ES --> Kibana.`

`

A thing to note is that, each service has its own log format. Attached four different service's logs for reference.

How can I handle all four format in a generic way ? I'm looking to structure it or convert all the logs into a JSON format while being displayed on Kibana.

Current configuration.

```auto
input {
  http {
    port => 9100
  }
}

filter {
    json {
       source => "message"
       remove_field => ["message"]
    }
    if [kubernetes][labels][id] in ["service1", "service2", "service3", "service4"] {
      json {
        source => "log"
        remove_field => ["log"]
      }
    }
    mutate {
      remove_field => ["_id", "headers", "_type", "character", "@version", "_index", "_score"]
    }
}
output {
     elasticsearch {
       id => "ieo-elk-drp-log-aggregation"
       hosts => ["<%= @ipaddress%>:19200"]
       index => "drp-%{[kubernetes][labels][app]}-%{+YYYY.MM.dd}"
    }
}

```

On the logstash logs, continuously see the below errors and it indicates the logs are of not of proper JSON. Any help here is really appreciated, thank you.

```auto
[2023-07-20T00:06:41,900][WARN][logstash.filters.json] Error parsing json {:source=>"log", :raw=>"INFO |2023-07-20 00:05:09 |1 | manageQueue.py 324 | There is nothing to process on the queue as it is empty. Returning...", :exception=>#<LogStash::Json::ParserError: Unrecognized token 'INFO': was expecting 'null', 'true', 'false' or NaN

[2023-07-20T00:09:30,425][WARN][logstash.filters.json] Error parsing json {:source=>"log", :raw=>"Thu Jul 20 00:09:07 2023 sent heartbeat", :exception=>#<LogStash::Json::ParserError: Unrecognized token 'Thu': was expecting ('true', 'false' or 'null')

[2023-07-20T00:11:55,679][WARN][logstash.filters.json] Error parsing json {:source=>"log", :raw=>"No Jira servers defined at /usr/src/app/value.pm line 70.", :exception=>#<LogStash::Json::ParserError: Unrecognized token 'No': was expecting 'null', 'true', 'false' or NaN
 at [Source: (byte[])"No Jira servers defined at /usr/src/app/value.pm line 70."; line: 1, column: 4]>}
 
 [2023-07-20T02:59:48,393][WARN][logstash.filters.json] Error parsing json {:source=>"log", :raw=>"Thu Jul 20 02:59:23 2023 sent heartbeat", :exception=>#<LogStash::Json::ParserError: Unrecognized token 'Thu': was expecting ('true', 'false' or 'null')
 at [Source: (byte[])"Thu Jul 20 02:59:23 2023 sent heartbeat"; line: 1, column: 5]>}
[2023-07-20T02:59:56,626][WARN][logstash.filters.json] Error parsing json {:source=>"log", :raw=>"malformed JSON string, neither array, object, number, string or atom, at character offset 11 (before \"<html>\\n\\n<head>\\n ...\") at (eval 250) line 1.", :exception=>#<LogStash::Json::ParserError: Unrecognized token 'malformed': was expecting ('true', 'false' or 'null')

[2023-07-20T06:53:05,389][WARN][logstash.filters.json] Error parsing json {:source=>"log", :raw=>"2023/07/20 06:50:48| NETDB state saved; 1 entries, 0 msec", :exception=>#<LogStash::Json::ParserError: Unexpected character ('/' (code 47)): Expected space separating root-level values

```

Also, how can I attach text files to the question ?  
Time being, I'm sharing the text location 🙂

> **[service\_4.txt](https://www.dropbox.com/scl/fi/xopxu7qsua859pxbjxisi/service_4.txt?rlkey=xjbt58lp1tpsxw0qodlmaaayo&dl=0)**
>
> Shared with Dropbox

> **[service\_1.txt](https://www.dropbox.com/scl/fi/kncys59lnch4a30jvycyo/service_1.txt?rlkey=f026rfsr0t6xdcru6635vaxy1&dl=0)**
>
> Shared with Dropbox

> **[service\_2.txt](https://www.dropbox.com/scl/fi/e7apr5jrn4raj10frje2w/service_2.txt?rlkey=u5alj34abb9kqnlm4kflgrhwk&dl=0)**
>
> Shared with Dropbox

> **[service\_3.txt](https://www.dropbox.com/scl/fi/3bngym9egoh9903lj5gbf/service_3.txt?rlkey=xr6tft1tg56ni9dwe8acb4aj4&dl=0)**
>
> Shared with Dropbox

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [August 23, 2023, 6:46am UTC](https://discuss.elastic.co/t/process-logs-of-different-formats-to-json/339258/2 "2023-08-23T06:46:07Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
