<p>I am new to fluentd. I have configured the basic fluentd setup I need and deployed this to my kubernetes cluster as a daemon set. I'm seeing logs shipped to my 3rd party logging solution. However I now want to deal with some logs that are coming in as multiple entries when they really should be one. The logs from the node look like they are json and are formatted like</p>

<pre><code>{"log":"2019-09-23 18:54:42,102 [INFO] some message \n","stream":"stderr","time":"2019-09-23T18:54:42.102Z"}
{"log": "another message \n","stream":"stderr","time":"2019-09-23T18:54:42.102Z"}
</code></pre>

<p>I have a config map that looks like </p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: fluent-config-map
  namespace: logging
  labels:
    k8s-app: fluentd-logzio
data:
  fluent.conf: |-
@include "#{ENV['FLUENTD_SYSTEMD_CONF'] || 'systemd'}.conf"
@include kubernetes.conf
@include conf.d/*.conf

&lt;match fluent.**&gt;
    # this tells fluentd to not output its log on stdout
    @type null
&lt;/match&gt;

# here we read the logs from Docker's containers and parse them
&lt;source&gt;
  @id fluentd-containers.log
  @type tail
  path /var/log/containers/*.log
  pos_file /var/log/es-containers.log.pos
  time_format %Y-%m-%dT%H:%M:%S.%NZ
  tag raw.kubernetes.*
  format json
  read_from_head true

&lt;/source&gt;

# Detect exceptions in the log output and forward them as one log entry.
&lt;match raw.kubernetes.**&gt;
  @id raw.kubernetes
  @type detect_exceptions
  remove_tag_prefix raw
  message log
  stream stream
  multiline_flush_interval 5
  max_bytes 500000
  max_lines 1000
&lt;/match&gt;

# Enriches records with Kubernetes metadata
&lt;filter kubernetes.**&gt;
  @id filter_kubernetes_metadata
  @type kubernetes_metadata
&lt;/filter&gt;

&lt;match kubernetes.**&gt;
  @type logzio_buffered
  @id out_logzio
  endpoint_url "https://listener-ca.logz.io?token=####"
  output_include_time true
  output_include_tags true
  &lt;buffer&gt;
    # Set the buffer type to file to improve the reliability and reduce the memory consumption
    @type file
    path /var/log/fluentd-buffers/stackdriver.buffer
    # Set queue_full action to block because we want to pause gracefully
    # in case of the off-the-limits load instead of throwing an exception
    overflow_action block
    # Set the chunk limit conservatively to avoid exceeding the GCL limit
    # of 10MiB per write request.
    chunk_limit_size 2M
    # Cap the combined memory usage of this buffer and the one below to
    # 2MiB/chunk * (6 + 2) chunks = 16 MiB
    queue_limit_length 6
    # Never wait more than 5 seconds before flushing logs in the non-error case.
    flush_interval 5s
    # Never wait longer than 30 seconds between retries.
    retry_max_interval 30
    # Disable the limit on the number of retries (retry forever).
    retry_forever true
    # Use multiple threads for processing.
    flush_thread_count 2
  &lt;/buffer&gt;
&lt;/match&gt;
</code></pre>

<p>My question is how do I get these log messages shipped as one single entry instead of multiple?</p>

Matthew The Terrible
<p>There are at least two ways:</p>
<h1><code>multiline</code> plugin</h1>
<p>Thanks to <a href="https://stackoverflow.com/users/9150934/rickerp">@rickerp</a>, he suggested <a href="https://docs.fluentd.org/parser/multiline" rel="nofollow noreferrer"><code>multiline</code></a> plugin.</p>
<blockquote>
<p>The multiline parser plugin parses multiline logs. This plugin is the multiline version of regexp parser.</p>
<p>The multiline parser parses log with formatN and format_firstline parameters. format_firstline is for detecting the start line of the multiline log. formatN, where N's range is [1..20], is the list of Regexp format for multiline log.</p>
<p>Unlike other parser plugins, this plugin needs special code in input plugin e.g. handle format_firstline. So, currently, in_tail plugin works with multiline but other input plugins do not work with it.</p>
</blockquote>
<h1><code>fluent-plugin-concat</code> plugin</h1>
<p>As per <a href="https://docs.fluentd.org/container-deployment/docker-logging-driver#additional-step-2-concatenate-multiple-lines-log-messages" rel="nofollow noreferrer"><code>fluentd</code> documentation</a>,  <a href="https://github.com/fluent-plugins-nursery/fluent-plugin-concat" rel="nofollow noreferrer"><code>fluent-plugin-concat</code></a> solves this:</p>
<blockquote>
<h3>Concatenate multiple lines log messages</h3>
<p>Application log is stored into <code>&quot;log&quot;</code> field in the records. You can concatenate these logs by using <a href="https://github.com/fluent-plugins-nursery/fluent-plugin-concat" rel="nofollow noreferrer">fluent-plugin-concat</a> filter before send to destinations.</p>
<pre><code>&lt;filter docker.**&gt;
@type concat
key log
stream_identity_key container_id
multiline_start_regexp /^-e:2:in `\/'/
multiline_end_regexp /^-e:4:in/
&lt;/filter&gt;
</code></pre>
<p>Original events:</p>
<pre><code>2016-04-13 14:45:55 +0900 docker.28cf38e21204: {&quot;container_id&quot;:&quot;28cf38e212042225f5f80a56fac08f34c8f0b235e738900c4e0abcf39253a702&quot;,&quot;container_name&quot;:&quot;/romantic_dubinsky&quot;,&quot;source&quot;:&quot;stdout&quot;,&quot;log&quot;:&quot;-e:2:in `/'&quot;}
2016-04-13 14:45:55 +0900 docker.28cf38e21204: {&quot;source&quot;:&quot;stdout&quot;,&quot;log&quot;:&quot;-e:2:in `do_division_by_zero'&quot;,&quot;container_id&quot;:&quot;28cf38e212042225f5f80a56fac08f34c8f0b235e738900c4e0abcf39253a702&quot;,&quot;container_name&quot;:&quot;/romantic_dubinsky&quot;}
2016-04-13 14:45:55 +0900 docker.28cf38e21204: {&quot;source&quot;:&quot;stdout&quot;,&quot;log&quot;:&quot;-e:4:in `&lt;main&gt;'&quot;,&quot;container_id&quot;:&quot;28cf38e212042225f5f80a56fac08f34c8f0b235e738900c4e0abcf39253a702&quot;,&quot;container_name&quot;:&quot;/romantic_dubinsky&quot;}
</code></pre>
<p>Filtered events:</p>
<pre><code>2016-04-13 14:45:55 +0900 docker.28cf38e21204: {&quot;container_id&quot;:&quot;28cf38e212042225f5f80a56fac08f34c8f0b235e738900c4e0abcf39253a702&quot;,&quot;container_name&quot;:&quot;/romantic_dubinsky&quot;,&quot;source&quot;:&quot;stdout&quot;,&quot;log&quot;:&quot;-e:2:in `/'\n-e:2:in `do_division_by_zero'\n-e:4:in `&lt;main&gt;'&quot;}
</code></pre>
</blockquote>
<p>With the plugin, you'll want to fix some regexes.</p>
