<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="error-log-json">
      </a>
      7.4.2.7 Error Logging in JSON Format
     </h4>
    </div>
   </div>
  </div>
  <p>
   This section describes how to configure error logging using the
        built-in filter,
   <code class="literal">
    log_filter_internal
   </code>
   , and the
        JSON sink,
   <code class="literal">
    log_sink_json
   </code>
   , to take effect
        immediately and for subsequent server startups. For general
        information about configuring error logging, see
   <a class="xref" href="error-log-configuration.html" title="7.4.2.1 Error Log Configuration">
    Section 7.4.2.1, “Error Log Configuration”
   </a>
   .
  </p>
  <p>
   To enable the JSON sink, first load the sink component, then
        modify the
   <a class="link" href="server-system-variables.html#sysvar_log_error_services">
    <code class="literal">
     log_error_services
    </code>
   </a>
   value:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa63246492"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">INSTALL</span> <span class="token keyword">COMPONENT</span> <span class="token string">'file://component_log_sink_json'</span><span class="token punctuation">;</span>
<span class="token keyword">SET</span> <span class="token keyword">PERSIST</span> log_error_services <span class="token operator">=</span> <span class="token string">'log_filter_internal; log_sink_json'</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   To set
   <a class="link" href="server-system-variables.html#sysvar_log_error_services">
    <code class="literal">
     log_error_services
    </code>
   </a>
   to
        take effect at server startup, use the instructions at
   <a class="xref" href="error-log-configuration.html" title="7.4.2.1 Error Log Configuration">
    Section 7.4.2.1, “Error Log Configuration”
   </a>
   . Those instructions
        apply to other error-logging system variables as well.
  </p>
  <p>
   It is permitted to name
   <code class="literal">
    log_sink_json
   </code>
   multiple times in the
   <a class="link" href="server-system-variables.html#sysvar_log_error_services">
    <code class="literal">
     log_error_services
    </code>
   </a>
   value. For
        example, to write unfiltered events with one instance and
        filtered events with another instance, you could set
   <a class="link" href="server-system-variables.html#sysvar_log_error_services">
    <code class="literal">
     log_error_services
    </code>
   </a>
   like this:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa97604783"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">SET</span> <span class="token keyword">PERSIST</span> log_error_services <span class="token operator">=</span> <span class="token string">'log_sink_json; log_filter_internal; log_sink_json'</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   The JSON sink determines its output destination based on the
        default error log destination, which is given by the
   <a class="link" href="server-system-variables.html#sysvar_log_error">
    <code class="literal">
     log_error
    </code>
   </a>
   system variable. If
   <a class="link" href="server-system-variables.html#sysvar_log_error">
    <code class="literal">
     log_error
    </code>
   </a>
   names a file, the
        JSON sink bases output file naming on that file name, plus a
        numbered
   <code class="filename">
    .
    <em class="replaceable">
     <code>
      NN
     </code>
    </em>
    .json
   </code>
   suffix,
        with
   <em class="replaceable">
    <code>
     NN
    </code>
   </em>
   starting at 00. For example,
        if
   <a class="link" href="server-system-variables.html#sysvar_log_error">
    <code class="literal">
     log_error
    </code>
   </a>
   is
   <em class="replaceable">
    <code>
     file_name
    </code>
   </em>
   , successive instances of
   <code class="literal">
    log_sink_json
   </code>
   named in the
   <a class="link" href="server-system-variables.html#sysvar_log_error_services">
    <code class="literal">
     log_error_services
    </code>
   </a>
   value write
        to
   <code class="filename">
    <em class="replaceable">
     <code>
      file_name
     </code>
    </em>
    .00.json
   </code>
   ,
   <code class="filename">
    <em class="replaceable">
     <code>
      file_name
     </code>
    </em>
    .01.json
   </code>
   ,
        and so forth.
  </p>
  <p>
   If
   <a class="link" href="server-system-variables.html#sysvar_log_error">
    <code class="literal">
     log_error
    </code>
   </a>
   is
   <code class="literal">
    stderr
   </code>
   , the JSON sink writes to the console.
        If
   <code class="literal">
    log_sink_json
   </code>
   is named multiple times in
        the
   <a class="link" href="server-system-variables.html#sysvar_log_error_services">
    <code class="literal">
     log_error_services
    </code>
   </a>
   value,
        they all write to the console, which is likely not useful.
  </p>
 </div>
 <br/>
</div>
