# Parsing composite log format only with text

**URL:** <https://discuss.elastic.co/t/parsing-composite-log-format-only-with-text/182148>\
**Category:** Logstash\
**Created:** [May 22, 2019, 6:57am UTC](https://discuss.elastic.co/t/parsing-composite-log-format-only-with-text/182148 "2019-05-22T06:57:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abhilash\_B](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abhilash_b/32/40270_2.png) [@Abhilash\_B](https://discuss.elastic.co/u/Abhilash_B)\
**Post date:** [May 22, 2019, 6:57am UTC](https://discuss.elastic.co/t/parsing-composite-log-format-only-with-text/182148/1 "2019-05-22T06:57:53Z")

</div>

Hi All,

I have a log file which looks [like this](https://pastebin.com/5WjWBZW5). My filter config looks like this:

```
filter{
   if [message] =~ /(.*): (.*) - (.*)/ {
  mutate { strip => ["message"] }
  ruby {
        code => '
            msg = event.get("message")
            path = event.get("[log][file][path]")
            path = path.split("/")
            puts path
            site_id = path[-2]
            source_id = path[-3]
            matches = msg.scan(/(.*): (.*) - (.*)/)
            m = matches[0]
            event.set("test", m[1])
	        event.set("value", m[2])
            event.set("site_id", site_id)
            event.set("source_id", source_id)
            event.set("metadata",@@metadata)
        '
    }
}
  else if [message] =~ /^([0]\d|[1][0-2])\/([0-2]\d|[3][0-1])\/([2][01]|[1][6-9])\d{2}(\s([0-1]\d|[2][0-3])(\:[0-5]\d){1,2})(\s([AM|PM|]{2,2}))?$/ {
  mutate { strip => ["message"] }
  ruby {
     init => '
        @@metadata = {}
     '
     code => '
        msg = event.get("message")
        @@metadata["datetime"] = msg
     '
  }
}
else{
  drop {}
}

```

}

---

<div class="post-metadata">

**Author:** ![Abhilash\_B](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abhilash_b/32/40270_2.png) [@Abhilash\_B](https://discuss.elastic.co/u/Abhilash_B)\
**Post date:** [May 22, 2019, 6:58am UTC](https://discuss.elastic.co/t/parsing-composite-log-format-only-with-text/182148/2 "2019-05-22T06:58:37Z")

</div>

Kindly Ignore this. This has been solved

---

<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:** [June 19, 2019, 6:58am UTC](https://discuss.elastic.co/t/parsing-composite-log-format-only-with-text/182148/3 "2019-06-19T06:58:41Z")

</div>

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