본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

멀티라인 파싱 (Multiline parsing)

원문 보기 위키 갱신

여러 줄에 걸친 로그를 하나의 메시지로 합치고 싶을 때 쓰는 기능입니다. 함께 살펴보겠습니다.

출처: 문서

본문

이상적인 세계에서 애플리케이션은 메시지를 한 줄로 기록할 수도 있겠지만, 현실에서는 가끔 같은 맥락에 속하는 여러 로그 메시지를 만들어 냅니다. 이런 정보를 처리하는 것은 복잡할 수 있는데, 항상 여러 로그 줄을 갖는 애플리케이션 스택 트레이스 같은 경우가 그렇죠.

멀티라인 파서는 여러 이벤트에 걸쳐 있는 로그를 하나의 일관된 메시지로 결합하는 데 사용됩니다. 스택 트레이스, 오류 로그, 또는 여러 줄의 정보를 담은 모든 로그 항목을 처리할 때 이 파서를 사용하세요.

개념

멀티라인 파서 엔진은 이 기능을 구성하고 사용하는 두 가지 방법을 제공합니다:

  • 내장(Built-in) 멀티라인 파서
  • 구성 가능한 멀티라인 파서

내장 멀티라인 파서

Fluent Bit는 특정 멀티라인 파서 사례를 해결하기 위해 몇 가지 사전 구성된 파서(내장)를 제공합니다. 예를 들어:

Parser Description
cri Process a log entry generated by CRI-O container engine. Like the docker parser, it supports concatenation of log entries.
docker Process a log entry generated by a Docker container engine. This parser supports the concatenation of large log entries split by Docker. If you use this parser, and you also want to concatenate log lines like stack traces, you can add the multiline filter to specify additional parsers.
go Process log entries generated by a Go-based language application and perform concatenation if multiline messages are detected.
java Process log entries generated by a Google Cloud Java language application and perform concatenation if multiline messages are detected.
json Group pretty-printed JSON objects that span multiple lines. The parser concatenates lines only. Use a Parser filter with a JSON parser on the assembled log field to extract structured fields.
python Process log entries generated by a Python-based language application and perform concatenation if multiline messages are detected.
ruby Process log entries generated by a Ruby-based language application and perform concatenation if multiline messages are detected.

Pretty-printed JSON과 JSON Lines

Tail은 한 번에 한 줄씩 읽습니다. 형식화된 JSON 객체는 매 줄마다 유효한 JSON이 아닙니다.

File shape Configuration
JSON Lines (one complete object per line) Set parser: json on the tail input. No multiline parser is required.
Pretty-printed or mixed single-line and multiline objects Set multiline.parser: json on tail, then use the Parser filter with key_name: log and a JSON parser.

{% hint style="warning" %} pretty-printed JSON을 처리하는 데 parser 속성을 사용하지 마세요. 멀티라인 파서가 parser를 설정하면 Fluent Bit는 결합 전에 들어오는 각 줄에 그 파서를 적용합니다. pretty-printed 객체의 개별 줄(예: { 또는 "id": 102,)은 유효한 JSON이 아니므로 파싱에 실패하고 원시 텍스트로 남습니다. 내장 json 멀티라인 파서를 사용해 줄을 그룹으로 묶은 다음 Parser 필터로 조립된 페이로드를 파싱하세요.

parser 속성은 들어오는 각 레코드가 이미 완전한 구조화된 메시지일 때 유효합니다. 내장 docker 파서가 이런 식으로 동작합니다. Docker 로그 파일의 모든 줄은 독립적인 JSON 객체이므로, 파서는 줄마다 JSON 파서를 적용하고 그 규칙을 결과 log 키에 대해 매칭합니다.

역사적인 맥락에서, 멀티라인 JSON 파일에 대한 커뮤니티 해결책은 issue #2418에서 논의됩니다. {% endhint %}

멀티라인 파서 구성

커스텀 멀티라인 파서는 다음 구성 파라미터를 지원합니다.

{% hint style="info" %} 커스텀 멀티라인 파서를 정의하려면 YAML 구성 파일의 multiline_parsers 섹션에 항목을 추가하세요. {% endhint %}

Property Description Default
flush_timeout Timeout in milliseconds to flush a non-terminated multiline buffer. 4s
key_content For an incoming structured message, specify the key that contains the data that should be processed by the regular expression and possibly concatenated. none
key_group For an incoming structured message, specify the key used as a grouping identifier. Lines with different values for this key are treated as separate streams. For example, Docker and CRI logs use the stream field to distinguish stdout from stderr. none
key_pattern For an incoming structured message, specify an alternative key to apply matching rules against, separate from key_content. Use to match against one field while concatenating content from another. none
match_string String to match against for endswith or equal types. Not used for regex type. none
name Specify a unique name for the multiline parser definition. A good practice is to prefix the name with the word multiline_ to avoid confusion with normal parser definitions. none
negate Negate the pattern matching result. When set to true, a non-matching line is treated as matching. false
parser Name of a pre-defined parser that must be applied to the incoming content before applying the regular expression rule. If no parser is defined, it's assumed that's a raw text and not a structured message. When a parser is applied to a raw text, the regular expression is applied against a specific key of the structured message by using the key_content configuration property. none
rule Configure a rule to match a multiline pattern. The rule has a specific format. Multiple rules can be defined. Only used with regex type. none
type Set the multiline mode. Fluent Bit supports regex, endswith, and equal (or eq). To understand which multiline parser type is required for your use case you have to know the conditions in the content that determine the beginning of a multiline message, and the continuation of subsequent lines. Fluent Bit provides a regular expression-based configuration that supports states to handle from the most cases. none

줄과 상태(Lines and states)

파서를 구성하기 전에 다음 질문에 대한 답을 알아야 합니다:

  1. 멀티라인 메시지의 첫 줄과 매칭되는 정규식(regex)은 무엇인가요?
  2. 멀티라인 메시지의 연속 줄과 매칭되는 정규식(regex)은 무엇인가요?

정규식을 매칭할 때는 states를 정의해야 합니다. 일부 상태는 멀티라인 메시지의 시작을 정의하고, 다른 상태는 멀티라인 메시지의 연속을 위한 상태입니다. 복잡한 경우를 해결하기 위해 여러 continuation states 정의를 가질 수 있어요.

멀티라인 메시지의 시작과 매칭되는 첫 번째 정규식을 start_state라고 합니다. 다른 정규식 연속 줄은 서로 다른 상태 이름을 가질 수 있습니다.

규칙 정의 (Rules definition)

규칙은 멀티라인 패턴을 매칭하고 결합을 수행하는 방법을 지정합니다. 규칙은 3가지 특정 구성 요소로 정의됩니다:

  • 상태 이름(state name)
  • 정규식 패턴(regular expression pattern)
  • 다음 상태(next state)

규칙은 해당하는 YAML과 classic 구성 예시에서 다음과 같이 정의될 수 있습니다(정의를 단순화하기 위해 주석 추가):

{% tabs %} {% tab title="parsers_multiline.yaml" %}

# rules |   state name  | regex pattern                  | next state
# ------|---------------|--------------------------------------------
rules:
  - state: start_state
    regex: '/([a-zA-Z]+ \d+ \d+\:\d+\:\d+)(.*)/'
    next_state:  cont
  - state: cont
    regex: '/^\s+at.*/'
    next_state: cont

{% endtab %}

{% tab title="parsers_multiline.conf" %}

# rules   |   state name   | regex pattern                   | next state
# --------|----------------|---------------------------------------------
rule         "start_state"   "/([a-zA-Z]+ \d+ \d+\:\d+\:\d+)(.*)/"   "cont"
rule         "cont"          "/^\s+at.*/"                      "cont"

{% endtab %} {% endtabs %}

이 예시는 두 개의 규칙을 정의합니다. 각 규칙은 자신만의 상태 이름, 정규식 패턴, 그리고 다음 상태 이름을 가집니다. 규칙을 구성하는 모든 필드는 큰따옴표 안에 있어야 합니다.

첫 번째 규칙의 상태 이름은 start_state여야 합니다. 정규식 패턴은 멀티라인 메시지의 첫 줄과 매칭되어야 하며, 가능한 연속 줄이 어떤 모양인지 지정하도록 다음 상태가 설정되어야 합니다.

{% hint style="info" %} 정규식 구성을 단순화하려면 Rubular 웹 사이트를 사용할 수 있어요. 이 링크는 앞의 예시에 설명된 정규식과 그 패턴과 매칭되는 로그 줄을 사용합니다: {% endhint %}

구성 예시

다음 예시는 앞서 설명한 정의를 사용해 멀티라인 파싱을 위한 완전한 Fluent Bit 구성 파일을 제공합니다. 다음 YAML 및 classic 구성 예시로 제공됩니다:

{% tabs %} {% tab title="fluent-bit.yaml" %} 이것은 주 Fluent Bit YAML 구성 파일입니다. parsers_multiline.yaml을 포함하고 multiline-regex-test 멀티라인 파서를 적용해 파일 test.log를 tail합니다. 그런 다음 처리를 표준 출력으로 보냅니다.

service:
  flush: 1
  log_level: info
  # Set the correct value here and ensure it is mounted in to a container
  # parsers_file: /fluent-bit/etc/parsers_multiline.yaml

pipeline:
  inputs:
    - name: tail
      path: test.log
      read_from_head: true
      multiline.parser: multiline-regex-test

  outputs:
    - name: stdout
      match: '*'

{% endtab %}

{% tab title="fluent-bit.conf" %} 이것은 주 Fluent Bit classic 구성 파일입니다. parsers_multiline.conf를 포함하고 multiline-regex-test 멀티라인 파서를 적용해 파일 test.log를 tail합니다. 그런 다음 처리를 표준 출력으로 보냅니다.

[SERVICE]
  Flush        1
  Log_Level    info
  # Parsers_File /fluent-bit/etc/parsers_multiline.conf

[INPUT]
  Name             tail
  Path             test.log
  Read_From_Head   true
  Multiline.Parser multiline-regex-test

[OUTPUT]
  Name             stdout
  Match            *

{% endtab %}

{% tab title="parsers_multiline.yaml" %} 이 파일은 YAML 구성 예시를 위한 멀티라인 파서를 정의합니다.

multiline_parsers:
  - name: multiline-regex-test
    type: regex
    flush_timeout: 1000
    #
    # Regex rules for multiline parsing
    # ---------------------------------
    #
    # configuration hints:
    #
    #  - first state always has the name: start_state
    #  - every field in the rule must be inside double quotes
    #
    # rules |   state name  | regex pattern                  | next state
    # ------|---------------|--------------------------------------------
    rules:
      - state: start_state
        regex: '/([a-zA-Z]+ \d+ \d+\:\d+\:\d+)(.*)/'
        next_state: cont
      - state: cont
        regex: '/^\s+at.*/'
        next_state: cont

{% endtab %}

{% tab title="parsers_multiline.conf" %} 이 두 번째 파일은 classic 구성 예시를 위한 멀티라인 파서를 정의합니다.

[MULTILINE_PARSER]
  Name          multiline-regex-test
  Type          regex
  Flush_Timeout 1000
  #
  # Regex rules for multiline parsing
  # ---------------------------------
  #
  # configuration hints:
  #
  #  - first state always has the name: start_state
  #  - every field in the rule must be inside double quotes
  #
  # rules |   state name  | regex pattern                  | next state
  # ------|---------------|--------------------------------------------
  Rule      "start_state"   "/([a-zA-Z]+ \d+ \d+\:\d+\:\d+)(.*)/"  "cont"
  Rule      "cont"          "/^\s+at.*/"                     "cont"

{% endtab %}

{% tab title="test.log" %} 멀티라인 내용이 있는 예시 로그 파일:

single line...
Dec 14 06:41:08 Exception in thread "main" java.lang.RuntimeException: Something has gone wrong, aborting!
    at com.myproject.module.MyProject.badMethod(MyProject.java:22)
    at com.myproject.module.MyProject.oneMoreMethod(MyProject.java:18)
    at com.myproject.module.MyProject.anotherMethod(MyProject.java:14)
    at com.myproject.module.MyProject.someMethod(MyProject.java:10)
    at com.myproject.module.MyProject.main(MyProject.java:6)
another line...

{% endtab %} {% endtabs %}

해당 구성 파일로 Fluent Bit를 실행하면 다음 출력을 얻습니다:

# For YAML configuration.
$ ./fluent-bit --config fluent-bit.yaml

# For classic configuration.
$ ./fluent-bit --config fluent-bit.conf

...
[0] tail.0: [[1750332967.679671000, {}], {"log"=>"single line...
"}]
[1] tail.0: [[1750332967.679677000, {}], {"log"=>"Dec 14 06:41:08 Exception in thread "main" java.lang.RuntimeException: Something has gone wrong, aborting!
    at com.myproject.module.MyProject.badMethod(MyProject.java:22)
    at com.myproject.module.MyProject.oneMoreMethod(MyProject.java:18)
    at com.myproject.module.MyProject.anotherMethod(MyProject.java:14)
    at com.myproject.module.MyProject.someMethod(MyProject.java:10)
    at com.myproject.module.MyProject.main(MyProject.java:6)
"}]
[2] tail.0: [[1750332967.679677000, {}], {"log"=>"another line...
"}]

패턴과 매칭되지 않은 줄은 멀티라인 메시지의 일부로 간주되지 않았고, 규칙과 매칭된 줄은 제대로 결합되었습니다.

제한 사항

멀티라인 파서는 매우 강력한 기능이지만, 알아두어야 할 몇 가지 제한 사항이 있습니다:

  • 멀티라인 파서는 buffer_max_size 구성 옵션의 영향을 받지 않으므로, 구성된 로그 레코드가 이 크기 이상으로 커질 수 있어요. skip_long_lines 옵션은 멀티라인 메시지에 적용되지 않습니다.
  • 멀티라인 메시지의 본문에서 시간 키를 가져올 수 없습니다. 하지만 필터를 사용해 추출하고 새 키로 설정할 수는 있어요.
  • 내장 json 파서를 사용할 때 pretty-printed 객체는 다음 { 줄이 올 때까지 버퍼링됩니다. 추가 입력이 없으면 종료되지 않은 버퍼는 flush_timeout(기본 4초) 후에 플러시됩니다. 이는 파일의 마지막 객체가 뒤에 닫을 객체가 없는 정적 파일에서 가장 두드러집니다. exit_on_eof를 사용할 때 그 마지막 플러시가 완료될 수 있도록 충분한 grace 시간을 허용하세요.

멀티라인 버퍼 제한의 추가 구성

Fluent Bit는 이제 멀티라인 결합 중 사용되는 메모리를 제한하는 구성 키를 지원합니다.

Property Description Default
multiline_buffer_limit Sets the maximum size of the in-memory buffer used while assembling a multiline message. When the accumulated size exceeds this limit, the message is truncated and a multiline_truncated: true metadata field is attached to the emitted record. A value of 0 disables the limit. Accepts unit suffixes such as KB, MB, GB, KiB, MiB, or GiB (all interpreted as binary units). 2MB
service:
  multiline_buffer_limit: 2MB   # default; limit concatenated multiline message size

한도에 도달하면 Fluent Bit는 OOM(Out-Of-Memory) 조건을 방지하기 위해 multiline_truncated: true 메타데이터와 함께 부분 레코드를 즉시 플러시합니다. 이 옵션은 Kubernetes 또는 다른 제한된 환경에서, 특히 cri나 docker 같은 내장 파서를 사용할 때 예측 가능한 메모리 사용을 보장합니다.

멀티라인 메시지에서 구조화된 데이터 얻기

Fluent-bit는 /pat/m 옵션을 지원합니다. 이는 .가 새 줄과 매칭되게 하며, 멀티라인 로그를 파싱하는 데 사용될 수 있어요.

다음 예시는 결합된 로그에서 date와 message를 가져옵니다.

예시 파일 내용:

{% tabs %} {% tab title="fluent-bit.yaml" %} 이것은 주 Fluent Bit YAML 구성 파일입니다. parsers_multiline.conf를 포함하고 multiline-regex-test 멀티라인 파서를 적용해 파일 test.log를 tail합니다. 또한 named-capture-test 파서를 적용해 결합된 로그를 파싱합니다. 그런 다음 처리를 표준 출력으로 보냅니다.

service:
  flush: 1
  log_level: info
  # parsers_file: /fluent-bit/etc/parsers_multiline.yaml

pipeline:
  inputs:
    - name: tail
      path: test.log
      read_from_head: true
      multiline.parser: multiline-regex-test

  filters:
    - name: parser
      match: '*'
      key_name: log
      parser: named-capture-test

  outputs:
    - name: stdout
      match: '*'

{% endtab %}

{% tab title="fluent-bit.conf" %} 이것은 주 Fluent Bit classic 구성 파일입니다. parsers_multiline.conf를 포함하고 multiline-regex-test 멀티라인 파서를 적용해 파일 test.log를 tail합니다. 또한 named-capture-test 파서를 적용해 결합된 로그를 파싱합니다. 그런 다음 처리를 표준 출력으로 보냅니다.

[SERVICE]
  Flush        1
  Log_Level    info
  # Parsers_File /fluent-bit/etc/parsers_multiline.conf

[INPUT]
  Name             tail
  Path             test.log
  Read_From_Head   true
  Multiline.Parser multiline-regex-test

[FILTER]
  Name             parser
  Match            *
  Key_Name         log
  Parser           named-capture-test

[OUTPUT]
  Name             stdout
  Match            *

{% endtab %}

{% tab title="parsers_multiline.yaml" %} 이 파일은 YAML 예시를 위한 멀티라인 파서를 정의합니다.

multiline_parsers:
  - name: multiline-regex-test
    type: regex
    flush_timeout: 1000
    #
    # Regex rules for multiline parsing
    # ---------------------------------
    #
    # configuration hints:
    #
    #  - first state always has the name: start_state
    #  - every field in the rule must be inside double quotes
    #
    # rules |   state name  | regex pattern                  | next state
    # ------|---------------|--------------------------------------------
    rules:
      - state: start_state
        regex: '/([a-zA-Z]+ \d+ \d+\:\d+\:\d+)(.*)/'
        next_state:  cont

      - state: cont
        regex: '/^\s+at.*/'
        next_state: cont

parsers:
  - name: named-capture-test
    format: regex
    regex: '/^(?<date>[a-zA-Z]+ \d+ \d+\:\d+\:\d+) (?<message>.*)/m'

{% endtab %}

{% tab title="parsers_multiline.conf" %} 이 파일은 classic 예시를 위한 멀티라인 파서를 정의합니다.

[MULTILINE_PARSER]
  Name          multiline-regex-test
  Type          regex
  Flush_Timeout 1000
  #
  # Regex rules for multiline parsing
  # ---------------------------------
  #
  # configuration hints:
  #
  #  - first state always has the name: start_state
  #  - every field in the rule must be inside double quotes
  #
  # rules |   state name  | regex pattern                  | next state
  # ------|---------------|--------------------------------------------
  Rule      "start_state"   "/([a-zA-Z]+ \d+ \d+\:\d+\:\d+)(.*)/"  "cont"
  Rule      "cont"          "/^\s+at.*/"                     "cont"

[PARSER]
  Name named-capture-test
  Format regex
  Regex /^(?<date>[a-zA-Z]+ \d+ \d+\:\d+\:\d+) (?<message>.*)/m

{% endtab %}

{% tab title="test.log" %} 멀티라인 내용이 있는 예시 로그 파일:

single line...
Dec 14 06:41:08 Exception in thread "main" java.lang.RuntimeException: Something has gone wrong, aborting!
    at com.myproject.module.MyProject.badMethod(MyProject.java:22)
    at com.myproject.module.MyProject.oneMoreMethod(MyProject.java:18)
    at com.myproject.module.MyProject.anotherMethod(MyProject.java:14)
    at com.myproject.module.MyProject.someMethod(MyProject.java:10)
    at com.myproject.module.MyProject.main(MyProject.java:6)
another line...

{% endtab %} {% endtabs %}

해당 구성 파일로 Fluent Bit를 실행하면 다음을 얻습니다:

# For YAML configuration.
$ ./fluent-bit --config fluent-bit.yaml

# For classic configuration
$ ./fluent-bit --config fluent-bit.conf

[0] tail.0: [[1750333602.460984000, {}], {"log"=>"single line...
"}]
[1] tail.0: [[1750333602.460998000, {}], {"date"=>"Dec 14 06:41:08", "message"=>"Exception in thread "main" java.lang.RuntimeException: Something has gone wrong, aborting!
    at com.myproject.module.MyProject.badMethod(MyProject.java:22)
    at com.myproject.module.MyProject.oneMoreMethod(MyProject.java:18)
    at com.myproject.module.MyProject.anotherMethod(MyProject.java:14)
    at com.myproject.module.MyProject.someMethod(MyProject.java:10)
    at com.myproject.module.MyProject.main(MyProject.java:6)
"}]
[2] tail.0: [[1750333602.460998000, {}], {"log"=>"another line...
"}]

내장 파서 예시

다음 예시들은 각 내장 멀티라인 파서를 사용하는 방법을 보여줍니다.

CRI

cri 파서는 CRI-O 컨테이너 런타임의 로그를 처리합니다. _p 필드로 한 줄이 완전한(F)지 부분(P)인지 판단합니다.

{% tabs %} {% tab title="fluent-bit.yaml" %}

service:
  flush: 1
  log_level: info

pipeline:
  inputs:
    - name: tail
      path: /var/log/containers/*.log
      read_from_head: true
      multiline.parser: cri

  outputs:
    - name: stdout
      match: '*'

{% endtab %}

{% tab title="fluent-bit.conf" %}

[SERVICE]
  Flush        1
  Log_Level    info

[INPUT]
  Name             tail
  Path             /var/log/containers/*.log
  Read_From_Head   true
  Multiline.Parser cri

[OUTPUT]
  Name             stdout
  Match            *

{% endtab %}

{% tab title="Input log" %}

2024-01-15T10:30:45.123456789Z stdout F Complete log message
2024-01-15T10:30:46.123456789Z stderr P This is a partial
2024-01-15T10:30:46.123456790Z stderr P message that spans
2024-01-15T10:30:46.123456791Z stderr F multiple lines

{% endtab %}

{% tab title="Output" %}

[0] tail.0: {"log"=>"Complete log message", "stream"=>"stdout"}
[1] tail.0: {"log"=>"This is a partial message that spans multiple lines", "stream"=>"stderr"}

{% endtab %} {% endtabs %}

Docker

docker 파서는 Docker JSON 로그를 처리합니다. \n으로 끝나는 줄은 완전한 것이고, 그렇지 않은 줄은 부분적인 것으로 결합됩니다.

{% tabs %} {% tab title="fluent-bit.yaml" %}

service:
  flush: 1
  log_level: info

pipeline:
  inputs:
    - name: tail
      path: /var/lib/docker/containers/*/*.log
      read_from_head: true
      multiline.parser: docker

  outputs:
    - name: stdout
      match: '*'

{% endtab %}

{% tab title="fluent-bit.conf" %}

[SERVICE]
  Flush        1
  Log_Level    info

[INPUT]
  Name             tail
  Path             /var/lib/docker/containers/*/*.log
  Read_From_Head   true
  Multiline.Parser docker

[OUTPUT]
  Name             stdout
  Match            *

{% endtab %}

{% tab title="Input log" %}

{"log":"This is a complete message\n","stream":"stdout","time":"2024-01-15T10:30:45.123456789Z"}
{"log":"This is a partial ","stream":"stdout","time":"2024-01-15T10:30:46.123456789Z"}
{"log":"message that spans ","stream":"stdout","time":"2024-01-15T10:30:46.123456790Z"}
{"log":"multiple lines\n","stream":"stdout","time":"2024-01-15T10:30:46.123456791Z"}

{% endtab %}

{% tab title="Output" %}

[0] tail.0: {"log"=>"This is a complete message\n", "stream"=>"stdout"}
[1] tail.0: {"log"=>"This is a partial message that spans multiple lines\n", "stream"=>"stdout"}

{% endtab %} {% endtabs %}

Go

go 파서는 Go panic 스택 트레이스를 처리합니다. panic: 메시지를 감지하고 전체 goroutine 스택을 캡처합니다.

{% tabs %} {% tab title="fluent-bit.yaml" %}

service:
  flush: 1
  log_level: info

pipeline:
  inputs:
    - name: tail
      path: /var/log/myapp/*.log
      read_from_head: true
      multiline.parser: go

  outputs:
    - name: stdout
      match: '*'

{% endtab %}

{% tab title="fluent-bit.conf" %}

[SERVICE]
  Flush        1
  Log_Level    info

[INPUT]
  Name             tail
  Path             /var/log/myapp/*.log
  Read_From_Head   true
  Multiline.Parser go

[OUTPUT]
  Name             stdout
  Match            *

{% endtab %}

{% tab title="Input log" %}

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x123456]

goroutine 1 [running]:
main.main()
	/app/main.go:15 +0x26

{% endtab %}

{% tab title="Output" %}

[0] tail.0: {"log"=>"panic: runtime error: invalid memory address or nil pointer dereference\n[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x123456]\n\ngoroutine 1 [running]:\nmain.main()\n\t/app/main.go:15 +0x26\n"}

{% endtab %} {% endtabs %}

Java

java 파서는 Java 예외 스택 트레이스를 처리합니다. Exception, Error, Throwable 패턴과 그 스택 프레임을 감지합니다.

{% tabs %} {% tab title="fluent-bit.yaml" %}

service:
  flush: 1
  log_level: info

pipeline:
  inputs:
    - name: tail
      path: /var/log/myapp/*.log
      read_from_head: true
      multiline.parser: java

  outputs:
    - name: stdout
      match: '*'

{% endtab %}

{% tab title="fluent-bit.conf" %}

[SERVICE]
  Flush        1
  Log_Level    info

[INPUT]
  Name             tail
  Path             /var/log/myapp/*.log
  Read_From_Head   true
  Multiline.Parser java

[OUTPUT]
  Name             stdout
  Match            *

{% endtab %}

{% tab title="Input log" %}

java.lang.NullPointerException: Something went wrong
	at com.example.MyClass.myMethod(MyClass.java:42)
	at com.example.MyClass.anotherMethod(MyClass.java:30)
	at com.example.Main.main(Main.java:10)
Caused by: java.lang.IllegalArgumentException: Invalid input
	at com.example.Helper.validate(Helper.java:15)
	... 3 more

{% endtab %}

{% tab title="Output" %}

[0] tail.0: {"log"=>"java.lang.NullPointerException: Something went wrong\n\tat com.example.MyClass.myMethod(MyClass.java:42)\n\tat com.example.MyClass.anotherMethod(MyClass.java:30)\n\tat com.example.Main.main(Main.java:10)\nCaused by: java.lang.IllegalArgumentException: Invalid input\n\tat com.example.Helper.validate(Helper.java:15)\n\t... 3 more\n"}

{% endtab %} {% endtabs %}

JSON

json 파서는 여러 줄로 나뉜 pretty-printed JSON 객체를 그룹으로 묶습니다. Tail은 log 필드에서 논리적 객체마다 하나의 레코드를 생성합니다. Parser 필터를 추가해 각 조립된 문자열을 최상위 필드로 바꾸세요.

이 예시는 Stdout 플러그인이 추가하는 타임스탬프를 읽을 수 있도록 json_date_format을 iso8601로 설정합니다. 없으면 플러그인은 타임스탬프를 분수 epoch 값으로 출력합니다.

Classic 모드는 주 구성 파일의 [PARSER] 섹션을 거부하므로 json_time 파서는 별도의 parsers 파일에 있어야 합니다. Parsers_File에서 주석 마커를 제거하고 parsers.conf의 경로를 가리키게 하세요.

{% tabs %} {% tab title="fluent-bit.yaml" %}

service:
  flush: 1
  grace: 5
  log_level: info

parsers:
  - name: json_time
    format: json
    time_key: time
    time_format: "%Y-%m-%dT%H:%M:%S.%L"
    time_keep: on

pipeline:
  inputs:
    - name: tail
      path: mixed.json
      read_from_head: true
      multiline.parser: json

  filters:
    - name: parser
      match: '*'
      key_name: log
      parser: json_time
      preserve_key: false

  outputs:
    - name: stdout
      match: '*'
      format: json_lines
      json_date_format: iso8601

{% endtab %}

{% tab title="fluent-bit.conf" %}

[SERVICE]
  Flush        1
  Grace        5
  Log_Level    info
  # Parsers_File parsers.conf

[INPUT]
  Name             tail
  Path             mixed.json
  Read_From_Head   true
  Multiline.Parser json

[FILTER]
  Name             parser
  Match            *
  Key_Name         log
  Parser           json_time
  Preserve_Key     Off

[OUTPUT]
  Name             stdout
  Match            *
  Format           json_lines
  Json_Date_Format iso8601

{% endtab %}

{% tab title="parsers.conf" %}

[PARSER]
  Name         json_time
  Format       json
  Time_Key     time
  Time_Format  %Y-%m-%dT%H:%M:%S.%L
  Time_Keep    On

{% endtab %}

{% tab title="Input log" %}

{"id":101,"time":"2026-08-11T11:00:00.000","level":"info","msg":"single-line record A"}
{
  "id": 102,
  "time": "2026-08-11T11:00:01.000",
  "level": "warn",
  "msg": "multiline record B",
  "details": {
    "user": "alice",
    "action": "login"
  }
}
{"id":103,"time":"2026-08-11T11:00:02.000","level":"info","msg":"single-line record C"}
{
  "id": 104,
  "time": "2026-08-11T11:00:03.000",
  "level": "error",
  "msg": "multiline record D",
  "stack": [
    "frame1",
    "frame2"
  ]
}

{% endtab %}

{% tab title="Output" %} 파서는 time에서 레코드 타임스탬프를 설정하며, Stdout 플러그인이 이를 date로 출력합니다. time_keep이 켜져 있으므로 time은 필드로 레코드에 남아 있습니다. preserve_key가 꺼져 있으므로 log 키는 버려집니다.

{"date":"2026-08-11T11:00:00.000000Z","id":101,"time":"2026-08-11T11:00:00.000","level":"info","msg":"single-line record A"}
{"date":"2026-08-11T11:00:01.000000Z","id":102,"time":"2026-08-11T11:00:01.000","level":"warn","msg":"multiline record B","details":{"user":"alice","action":"login"}}
{"date":"2026-08-11T11:00:02.000000Z","id":103,"time":"2026-08-11T11:00:02.000","level":"info","msg":"single-line record C"}
{"date":"2026-08-11T11:00:03.000000Z","id":104,"time":"2026-08-11T11:00:03.000","level":"error","msg":"multiline record D","stack":["frame1","frame2"]}

{% endtab %} {% endtabs %}

Python

python 파서는 Python 스택 트레이스를 처리합니다. Traceback (most recent call last):를 감지하고 전체 스택을 캡처합니다.

{% tabs %} {% tab title="fluent-bit.yaml" %}

service:
  flush: 1
  log_level: info

pipeline:
  inputs:
    - name: tail
      path: /var/log/myapp/*.log
      read_from_head: true
      multiline.parser: python

  outputs:
    - name: stdout
      match: '*'

{% endtab %}

{% tab title="fluent-bit.conf" %}

[SERVICE]
  Flush        1
  Log_Level    info

[INPUT]
  Name             tail
  Path             /var/log/myapp/*.log
  Read_From_Head   true
  Multiline.Parser python

[OUTPUT]
  Name             stdout
  Match            *

{% endtab %}

{% tab title="Input log" %}

Traceback (most recent call last):
  File "/app/main.py", line 10, in <module>
    result = process_data(None)
  File "/app/utils.py", line 25, in process_data
    return data.strip()
AttributeError: 'NoneType' object has no attribute 'strip'

{% endtab %}

{% tab title="Output" %}

[0] tail.0: {"log"=>"Traceback (most recent call last):\n  File \"/app/main.py\", line 10, in <module>\n    result = process_data(None)\n  File \"/app/utils.py\", line 25, in process_data\n    return data.strip()\nAttributeError: 'NoneType' object has no attribute 'strip'\n"}

{% endtab %} {% endtabs %}

Ruby

ruby 파서는 Ruby 예외 백트레이스를 처리합니다. file.rb:line:in 'method' 같은 패턴과 from으로 시작하는 연속 줄을 감지합니다.

{% tabs %} {% tab title="fluent-bit.yaml" %}

service:
  flush: 1
  log_level: info

pipeline:
  inputs:
    - name: tail
      path: /var/log/myapp/*.log
      read_from_head: true
      multiline.parser: ruby

  outputs:
    - name: stdout
      match: '*'

{% endtab %}

{% tab title="fluent-bit.conf" %}

[SERVICE]
  Flush        1
  Log_Level    info

[INPUT]
  Name             tail
  Path             /var/log/myapp/*.log
  Read_From_Head   true
  Multiline.Parser ruby

[OUTPUT]
  Name             stdout
  Match            *

{% endtab %}

{% tab title="Input log" %}

app/models/user.rb:42:in `validate_email'
	from app/models/user.rb:30:in `save'
	from app/controllers/users_controller.rb:15:in `create'
	from config/routes.rb:5:in `block in <main>'

{% endtab %}

{% tab title="Output" %}

[0] tail.0: {"log"=>"app/models/user.rb:42:in `validate_email'\n\tfrom app/models/user.rb:30:in `save'\n\tfrom app/controllers/users_controller.rb:15:in `create'\n\tfrom config/routes.rb:5:in `block in <main>'\n"}

{% endtab %} {% endtabs %}

더 알아보기 (Learn more)