Home Explore Blog CI



postgresql

99th chunk of `doc/src/sgml/config.sgml`
6be530e2096a8b19c6983a43f7710be24831c73898d9459e0000000100000fa0
 If <systemitem>csvlog</systemitem> is included in <varname>log_destination</varname>,
        log entries are output in <quote>comma-separated
        value</quote> (<acronym>CSV</acronym>) format, which is convenient for
        loading logs into programs.
        See <xref linkend="runtime-config-logging-csvlog"/> for details.
        <xref linkend="guc-logging-collector"/> must be enabled to generate
        CSV-format log output.
       </para>
       <para>
        If <systemitem>jsonlog</systemitem> is included in
        <varname>log_destination</varname>, log entries are output in
        <acronym>JSON</acronym> format, which is convenient for loading logs
        into programs.
        See <xref linkend="runtime-config-logging-jsonlog"/> for details.
        <xref linkend="guc-logging-collector"/> must be enabled to generate
        JSON-format log output.
       </para>
       <para>
        When either <systemitem>stderr</systemitem>,
        <systemitem>csvlog</systemitem> or <systemitem>jsonlog</systemitem> are
        included, the file <filename>current_logfiles</filename> is created to
        record the location of the log file(s) currently in use by the logging
        collector and the associated logging destination. This provides a
        convenient way to find the logs currently in use by the instance. Here
        is an example of this file's content:
<programlisting>
stderr log/postgresql.log
csvlog log/postgresql.csv
jsonlog log/postgresql.json
</programlisting>

        <filename>current_logfiles</filename> is recreated when a new log file
        is created as an effect of rotation, and
        when <varname>log_destination</varname> is reloaded.  It is removed when
        none of <systemitem>stderr</systemitem>,
        <systemitem>csvlog</systemitem> or <systemitem>jsonlog</systemitem> are
        included in <varname>log_destination</varname>, and when the logging
        collector is disabled.
       </para>

       <note>
        <para>
         On most Unix systems, you will need to alter the configuration of
         your system's <application>syslog</application> daemon in order
         to make use of the <systemitem>syslog</systemitem> option for
         <varname>log_destination</varname>.  <productname>PostgreSQL</productname>
         can log to <application>syslog</application> facilities
         <literal>LOCAL0</literal> through <literal>LOCAL7</literal> (see <xref
         linkend="guc-syslog-facility"/>), but the default
         <application>syslog</application> configuration on most platforms
         will discard all such messages.  You will need to add something like:
<programlisting>
local0.*    /var/log/postgresql
</programlisting>
         to the  <application>syslog</application> daemon's configuration file
         to make it work.
        </para>
        <para>
         On Windows, when you use the <literal>eventlog</literal>
         option for <varname>log_destination</varname>, you should
         register an event source and its library with the operating
         system so that the Windows Event Viewer can display event
         log messages cleanly.
         See <xref linkend="event-log-registration"/> for details.
        </para>
       </note>
      </listitem>
     </varlistentry>

     <varlistentry id="guc-logging-collector" xreflabel="logging_collector">
      <term><varname>logging_collector</varname> (<type>boolean</type>)
      <indexterm>
       <primary><varname>logging_collector</varname> configuration parameter</primary>
      </indexterm>
      </term>
      <listitem>
       <para>
         This parameter enables the <firstterm>logging collector</firstterm>, which
         is a background process that captures log messages
         sent to <systemitem>stderr</systemitem> and redirects them into log files.
         This approach is often more useful than
         logging to <application>syslog</application>, since some types of messages
         might

Title: Log Destinations, CSV/JSON Logging, and the Logging Collector
Summary
This section details how PostgreSQL supports logging to various destinations like stderr, csvlog, jsonlog, and syslog. It describes how csvlog and jsonlog output entries in CSV and JSON formats respectively and require the logging collector to be enabled. The `current_logfiles` file tracks the log files in use when stderr, csvlog, or jsonlog are selected. The section also provides guidance on configuring syslog on Unix and registering an event source on Windows for eventlog usage. Finally, it introduces the logging collector, a background process that captures stderr messages and redirects them to log files.