# How to write multiline codec for python stacktrace

**URL:** <https://discuss.elastic.co/t/how-to-write-multiline-codec-for-python-stacktrace/284936>\
**Category:** Logstash\
**Created:** [September 22, 2021, 7:42pm UTC](https://discuss.elastic.co/t/how-to-write-multiline-codec-for-python-stacktrace/284936 "2021-09-22T19:42:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chandrakant\_Naik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chandrakant_naik/32/79430_2.png) [@Chandrakant\_Naik](https://discuss.elastic.co/u/Chandrakant_Naik)\
**Post date:** [September 22, 2021, 7:42pm UTC](https://discuss.elastic.co/t/how-to-write-multiline-codec-for-python-stacktrace/284936/1 "2021-09-22T19:42:23Z")

</div>

below is how my log is captured

```auto
[2021-09-17 14:24:16,527] [ERROR] [app][MainThread] [5d9b63a9-dc4d-4756-af87-eba4fb275584] [log_exception:1440] : Exception on /download_request_data [GET]
Traceback (most recent call last):
  File "xxxxladjfalkjdlakjdflkajf\alkajdjlkajflka\venv\lib\site-packages\flask\app.py", line 2051, in wsgi_app
    response = self.full_dispatch_request()
  File "xxxxladjfalkjdlakjdflkajf\alkajdjlkajflka\venv\lib\site-packages\flask\app.py", line 1501, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "xxxxladjfalkjdlakjdflkajf\alkajdjlkajflka\venv\lib\site-packages\flask\app.py", line 1499, in full_dispatch_request
    rv = self.dispatch_request()
  File "xxxxladjfalkjdlakjdflkajf\alkajdjlkajflka\venv\lib\site-packages\flask\app.py", line 1485, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "xxxxladjfalkjdlakjdflkajf\alkajdjlkajflka\.\app.py", line 351, in download_request_data
    zip_file.writestr(file)
TypeError: writestr() missing 1 required positional argument: 'data'

```

i want the first line and rest of the lines have trace info - part of one message or event.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [September 22, 2021, 8:25pm UTC](https://discuss.elastic.co/t/how-to-write-multiline-codec-for-python-stacktrace/284936/2 "2021-09-22T20:25:25Z")

</div>

If your multiline messages always start with a square bracket and a date then you could try

```
codec => multiline { pattern => "^\[\d{4}" negate => true what => previous auto_flush_interval => 1 }
```

---

<div class="post-metadata">

**Author:** ![Chandrakant\_Naik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chandrakant_naik/32/79430_2.png) [@Chandrakant\_Naik](https://discuss.elastic.co/u/Chandrakant_Naik)\
**Post date:** [September 22, 2021, 8:47pm UTC](https://discuss.elastic.co/t/how-to-write-multiline-codec-for-python-stacktrace/284936/3 "2021-09-22T20:47:35Z")

</div>

It worked ..thanks a ton for the quick response.. One last thing. I'm new to this elk stack. Any good resources/books - to understand to write grok patterns/regex.. if you can provide me the resources that will be really helpfulll..

---

<div class="post-metadata">

**Author:** ![Chandrakant\_Naik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chandrakant_naik/32/79430_2.png) [@Chandrakant\_Naik](https://discuss.elastic.co/u/Chandrakant_Naik)\
**Post date:** [September 22, 2021, 8:50pm UTC](https://discuss.elastic.co/t/how-to-write-multiline-codec-for-python-stacktrace/284936/4 "2021-09-22T20:50:11Z")

</div>

Currently i'm going through a lot of blogs/articles. One Book/video tutorial that can help me get my fundamentals right, that will be really great.

---

<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:** [October 20, 2021, 8:50pm UTC](https://discuss.elastic.co/t/how-to-write-multiline-codec-for-python-stacktrace/284936/5 "2021-10-20T20:50:11Z")

</div>

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