description: >- Concatenate Multiline or Stack trace log messages. Available on Fluent Bit >= v1.8.2.

Multiline

The Multiline Filter helps to concatenate messages that originally belong to one context but were split across multiple records or log lines. Common examples are stack traces or applications that print logs in multiple lines.

As part of the built-in functionality, without major configuration effort, you can enable one of ours built-in parsers with auto detection and multi format support:

  • go
  • python
  • ruby
  • java (Google Cloud Platform Java stacktrace format)

Some comments about this filter:

  • The usage of this filter depends on a previous configuration of a Multiline Parser definition.
  • If you aim to concatenate messages split originally by Docker or CRI container engines, we recommend doing the concatenation on Tail plugin, this same functionality exists there.

Configuration Parameters

The plugin supports the following configuration parameters:

Property Description
multiline.parser Specify one or multiple Multiline Parser definitions to apply to the content. You can specify multiple multiline parsers to detect different formats by separating them with a comma.
multiline.key_content Key name that holds the content to process. Note that a Multiline Parser definition can already specify the key_content to use, but this option allows to overwrite that value for the purpose of the filter.

Configuration Example

The following example aims to parse a log file called test.log that contains some full lines, a custom Java stacktrace and a Go stacktrace.

{% hint style=”info” %} The following example files can be located at:

https://github.com/fluent/fluent-bit/tree/master/documentation/examples/multiline/filter_multiline {% endhint %}

Example files content:

{% tabs %} {% tab title=”fluent-bit.conf” %} This is the primary Fluent Bit configuration file. It includes the parsers_multiline.conf and tails the file test.log by applying the multiline parsers multiline-regex-test and go. Then it sends the processing to the standard output.

  1. [SERVICE]
  2. flush 1
  3. log_level info
  4. parsers_file parsers_multiline.conf
  5. [INPUT]
  6. name tail
  7. path test.log
  8. read_from_head true
  9. [FILTER]
  10. name multiline
  11. match *
  12. multiline.key_content log
  13. multiline.parser go, multiline-regex-test
  14. [OUTPUT]
  15. name stdout
  16. match *

{% endtab %}

{% tab title=”parsers_multiline.conf” %} This second file defines a multiline parser for the example. Note that a second multiline parser called go is used in fluent-bit.conf, but this one is a built-in parser.

  1. [MULTILINE_PARSER]
  2. name multiline-regex-test
  3. type regex
  4. flush_timeout 1000
  5. #
  6. # Regex rules for multiline parsing
  7. # ---------------------------------
  8. #
  9. # configuration hints:
  10. #
  11. # - first state always has the name: start_state
  12. # - every field in the rule must be inside double quotes
  13. #
  14. # rules | state name | regex pattern | next state
  15. # ------|---------------|--------------------------------------------
  16. rule "start_state" "/(Dec \d+ \d+\:\d+\:\d+)(.*)/" "cont"
  17. rule "cont" "/^\s+at.*/" "cont"

{% endtab %}

{% tab title=”test.log” %} An example file with multiline and multiformat content:

  1. single line...
  2. Dec 14 06:41:08 Exception in thread "main" java.lang.RuntimeException: Something has gone wrong, aborting!
  3. at com.myproject.module.MyProject.badMethod(MyProject.java:22)
  4. at com.myproject.module.MyProject.oneMoreMethod(MyProject.java:18)
  5. at com.myproject.module.MyProject.anotherMethod(MyProject.java:14)
  6. at com.myproject.module.MyProject.someMethod(MyProject.java:10)
  7. at com.myproject.module.MyProject.main(MyProject.java:6)
  8. another line...
  9. panic: my panic
  10. goroutine 4 [running]:
  11. panic(0x45cb40, 0x47ad70)
  12. /usr/local/go/src/runtime/panic.go:542 +0x46c fp=0xc42003f7b8 sp=0xc42003f710 pc=0x422f7c
  13. main.main.func1(0xc420024120)
  14. foo.go:6 +0x39 fp=0xc42003f7d8 sp=0xc42003f7b8 pc=0x451339
  15. runtime.goexit()
  16. /usr/local/go/src/runtime/asm_amd64.s:2337 +0x1 fp=0xc42003f7e0 sp=0xc42003f7d8 pc=0x44b4d1
  17. created by main.main
  18. foo.go:5 +0x58
  19. goroutine 1 [chan receive]:
  20. runtime.gopark(0x4739b8, 0xc420024178, 0x46fcd7, 0xc, 0xc420028e17, 0x3)
  21. /usr/local/go/src/runtime/proc.go:280 +0x12c fp=0xc420053e30 sp=0xc420053e00 pc=0x42503c
  22. runtime.goparkunlock(0xc420024178, 0x46fcd7, 0xc, 0x1000f010040c217, 0x3)
  23. /usr/local/go/src/runtime/proc.go:286 +0x5e fp=0xc420053e70 sp=0xc420053e30 pc=0x42512e
  24. runtime.chanrecv(0xc420024120, 0x0, 0xc420053f01, 0x4512d8)
  25. /usr/local/go/src/runtime/chan.go:506 +0x304 fp=0xc420053f20 sp=0xc420053e70 pc=0x4046b4
  26. runtime.chanrecv1(0xc420024120, 0x0)
  27. /usr/local/go/src/runtime/chan.go:388 +0x2b fp=0xc420053f50 sp=0xc420053f20 pc=0x40439b
  28. main.main()
  29. foo.go:9 +0x6f fp=0xc420053f80 sp=0xc420053f50 pc=0x4512ef
  30. runtime.main()
  31. /usr/local/go/src/runtime/proc.go:185 +0x20d fp=0xc420053fe0 sp=0xc420053f80 pc=0x424bad
  32. runtime.goexit()
  33. /usr/local/go/src/runtime/asm_amd64.s:2337 +0x1 fp=0xc420053fe8 sp=0xc420053fe0 pc=0x44b4d1
  34. goroutine 2 [force gc (idle)]:
  35. runtime.gopark(0x4739b8, 0x4ad720, 0x47001e, 0xf, 0x14, 0x1)
  36. /usr/local/go/src/runtime/proc.go:280 +0x12c fp=0xc42003e768 sp=0xc42003e738 pc=0x42503c
  37. runtime.goparkunlock(0x4ad720, 0x47001e, 0xf, 0xc420000114, 0x1)
  38. /usr/local/go/src/runtime/proc.go:286 +0x5e fp=0xc42003e7a8 sp=0xc42003e768 pc=0x42512e
  39. runtime.forcegchelper()
  40. /usr/local/go/src/runtime/proc.go:238 +0xcc fp=0xc42003e7e0 sp=0xc42003e7a8 pc=0x424e5c
  41. runtime.goexit()
  42. /usr/local/go/src/runtime/asm_amd64.s:2337 +0x1 fp=0xc42003e7e8 sp=0xc42003e7e0 pc=0x44b4d1
  43. created by runtime.init.4
  44. /usr/local/go/src/runtime/proc.go:227 +0x35
  45. goroutine 3 [GC sweep wait]:
  46. runtime.gopark(0x4739b8, 0x4ad7e0, 0x46fdd2, 0xd, 0x419914, 0x1)
  47. /usr/local/go/src/runtime/proc.go:280 +0x12c fp=0xc42003ef60 sp=0xc42003ef30 pc=0x42503c
  48. runtime.goparkunlock(0x4ad7e0, 0x46fdd2, 0xd, 0x14, 0x1)
  49. /usr/local/go/src/runtime/proc.go:286 +0x5e fp=0xc42003efa0 sp=0xc42003ef60 pc=0x42512e
  50. runtime.bgsweep(0xc42001e150)
  51. /usr/local/go/src/runtime/mgcsweep.go:52 +0xa3 fp=0xc42003efd8 sp=0xc42003efa0 pc=0x419973
  52. runtime.goexit()
  53. /usr/local/go/src/runtime/asm_amd64.s:2337 +0x1 fp=0xc42003efe0 sp=0xc42003efd8 pc=0x44b4d1
  54. created by runtime.gcenable
  55. /usr/local/go/src/runtime/mgc.go:216 +0x58
  56. one more line, no multiline

{% endtab %} {% endtabs %}

By running Fluent Bit with the given configuration file you will obtain:

  1. $ fluent-bit -c fluent-bit.conf
  2. [0] tail.0: [1626736433.143567481, {"log"=>"single line..."}]
  3. [1] tail.0: [1626736433.143570538, {"log"=>"Dec 14 06:41:08 Exception in thread "main" java.lang.RuntimeException: Something has gone wrong, aborting!
  4. at com.myproject.module.MyProject.badMethod(MyProject.java:22)
  5. at com.myproject.module.MyProject.oneMoreMethod(MyProject.java:18)
  6. at com.myproject.module.MyProject.anotherMethod(MyProject.java:14)
  7. at com.myproject.module.MyProject.someMethod(MyProject.java:10)
  8. at com.myproject.module.MyProject.main(MyProject.java:6)"}]
  9. [2] tail.0: [1626736433.143572538, {"log"=>"another line..."}]
  10. [3] tail.0: [1626736433.143572894, {"log"=>"panic: my panic
  11. goroutine 4 [running]:
  12. panic(0x45cb40, 0x47ad70)
  13. /usr/local/go/src/runtime/panic.go:542 +0x46c fp=0xc42003f7b8 sp=0xc42003f710 pc=0x422f7c
  14. main.main.func1(0xc420024120)
  15. foo.go:6 +0x39 fp=0xc42003f7d8 sp=0xc42003f7b8 pc=0x451339
  16. runtime.goexit()
  17. /usr/local/go/src/runtime/asm_amd64.s:2337 +0x1 fp=0xc42003f7e0 sp=0xc42003f7d8 pc=0x44b4d1
  18. created by main.main
  19. foo.go:5 +0x58
  20. goroutine 1 [chan receive]:
  21. runtime.gopark(0x4739b8, 0xc420024178, 0x46fcd7, 0xc, 0xc420028e17, 0x3)
  22. /usr/local/go/src/runtime/proc.go:280 +0x12c fp=0xc420053e30 sp=0xc420053e00 pc=0x42503c
  23. runtime.goparkunlock(0xc420024178, 0x46fcd7, 0xc, 0x1000f010040c217, 0x3)
  24. /usr/local/go/src/runtime/proc.go:286 +0x5e fp=0xc420053e70 sp=0xc420053e30 pc=0x42512e
  25. runtime.chanrecv(0xc420024120, 0x0, 0xc420053f01, 0x4512d8)
  26. /usr/local/go/src/runtime/chan.go:506 +0x304 fp=0xc420053f20 sp=0xc420053e70 pc=0x4046b4
  27. runtime.chanrecv1(0xc420024120, 0x0)
  28. /usr/local/go/src/runtime/chan.go:388 +0x2b fp=0xc420053f50 sp=0xc420053f20 pc=0x40439b
  29. main.main()
  30. foo.go:9 +0x6f fp=0xc420053f80 sp=0xc420053f50 pc=0x4512ef
  31. runtime.main()
  32. /usr/local/go/src/runtime/proc.go:185 +0x20d fp=0xc420053fe0 sp=0xc420053f80 pc=0x424bad
  33. runtime.goexit()
  34. /usr/local/go/src/runtime/asm_amd64.s:2337 +0x1 fp=0xc420053fe8 sp=0xc420053fe0 pc=0x44b4d1
  35. goroutine 2 [force gc (idle)]:
  36. runtime.gopark(0x4739b8, 0x4ad720, 0x47001e, 0xf, 0x14, 0x1)
  37. /usr/local/go/src/runtime/proc.go:280 +0x12c fp=0xc42003e768 sp=0xc42003e738 pc=0x42503c
  38. runtime.goparkunlock(0x4ad720, 0x47001e, 0xf, 0xc420000114, 0x1)
  39. /usr/local/go/src/runtime/proc.go:286 +0x5e fp=0xc42003e7a8 sp=0xc42003e768 pc=0x42512e
  40. runtime.forcegchelper()
  41. /usr/local/go/src/runtime/proc.go:238 +0xcc fp=0xc42003e7e0 sp=0xc42003e7a8 pc=0x424e5c
  42. runtime.goexit()
  43. /usr/local/go/src/runtime/asm_amd64.s:2337 +0x1 fp=0xc42003e7e8 sp=0xc42003e7e0 pc=0x44b4d1
  44. created by runtime.init.4
  45. /usr/local/go/src/runtime/proc.go:227 +0x35
  46. goroutine 3 [GC sweep wait]:
  47. runtime.gopark(0x4739b8, 0x4ad7e0, 0x46fdd2, 0xd, 0x419914, 0x1)
  48. /usr/local/go/src/runtime/proc.go:280 +0x12c fp=0xc42003ef60 sp=0xc42003ef30 pc=0x42503c
  49. runtime.goparkunlock(0x4ad7e0, 0x46fdd2, 0xd, 0x14, 0x1)
  50. /usr/local/go/src/runtime/proc.go:286 +0x5e fp=0xc42003efa0 sp=0xc42003ef60 pc=0x42512e
  51. runtime.bgsweep(0xc42001e150)
  52. /usr/local/go/src/runtime/mgcsweep.go:52 +0xa3 fp=0xc42003efd8 sp=0xc42003efa0 pc=0x419973
  53. runtime.goexit()
  54. /usr/local/go/src/runtime/asm_amd64.s:2337 +0x1 fp=0xc42003efe0 sp=0xc42003efd8 pc=0x44b4d1
  55. created by runtime.gcenable
  56. /usr/local/go/src/runtime/mgc.go:216 +0x58"}]
  57. [4] tail.0: [1626736433.143585473, {"log"=>"one more line, no multiline"}]

The lines that did not match a pattern are not considered as part of the multiline message, while the ones that matched the rules were concatenated properly.