<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE erlref SYSTEM "erlref.dtd">

<erlref>
  <header>
    <copyright>
      <year>2017</year><year>2020</year>
      <holder>Ericsson AB. All Rights Reserved.</holder>
    </copyright>
    <legalnotice>
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.

    </legalnotice>

    <title>logger_disk_log_h</title>
    <prepared></prepared>
    <responsible></responsible>
    <docno></docno>
    <approved></approved>
    <checked></checked>
    <date></date>
    <rev>A</rev>
    <file>logger_disk_log_h.xml</file>
  </header>
  <module since="OTP 21.0">logger_disk_log_h</module>
  <modulesummary>A disk_log based handler for Logger</modulesummary>

  <description>
    <p>This is a handler for Logger that offers circular
    (wrapped) logs by using <seeerl marker="disk_log"><c>disk_log</c></seeerl>. 
    Multiple instances of this handler can be added to Logger, and each instance
    prints to its own disk log file, created with the name and settings specified
    in the handler configuration.</p>
    <p>The default standard handler,
    <seeerl marker="logger_std_h"><c>logger_std_h</c></seeerl>, can be
    replaced by a disk_log handler at startup of the Kernel application.
    See an example of this below.</p>
    <p>The handler has an overload protection mechanism that keeps the handler
    process and the Kernel application alive during  high loads of log 
    events. How overload protection works, and how to configure it, is
    described in the
    <seeguide marker="logger_chapter#overload_protection"><c>User's Guide</c>
    </seeguide>.</p>
    <p>To add a new instance of the disk_log handler, use
    <seemfa marker="logger#add_handler/3"><c>logger:add_handler/3</c>
    </seemfa>. The handler configuration argument is a map which can contain
    general configuration parameters, as documented in the
    <seeguide marker="logger_chapter#handler_configuration"><c>User's Guide</c>
    </seeguide>, and handler specific parameters. The specific data
    is stored in a sub map with the key <c>config</c>, and can contain the
    following parameters:</p>
    <taglist>
      <tag><c>file</c></tag>
      <item>
	<p>This is the full name of the disk log file. The option
	corresponds to the <c>name</c> property in the
	<seemfa marker="disk_log#open/1"><c>dlog_option()</c></seemfa>
	datatype.</p>
	<p>The value is set when the handler is added, and it cannot
	  be changed in runtime.</p>
	<p>Defaults to the same name as the handler identity, in the
	  current directory.</p>
      </item>
      <tag><c>type</c></tag>
      <item>
	<p>This is the disk log type, <c>wrap</c> or <c>halt</c>. The option
	corresponds to the <c>type</c> property in the
	<seemfa marker="disk_log#open/1"><c>dlog_option()</c></seemfa>
	datatype.</p>
	<p>The value is set when the handler is added, and it cannot
	  be changed in runtime.</p>
	<p>Defaults to <c>wrap</c>.</p>
      </item>
      <tag><c>max_no_files</c></tag>
      <item>
	<p>This is the maximum number of files that disk_log uses
	for its circular logging. The option
	corresponds to the <c>MaxNoFiles</c> element in the <c>size</c> property in the
	<seemfa marker="disk_log#open/1"><c>dlog_option()</c></seemfa>
	datatype.</p>
	<p>The value is set when the handler is added, and it cannot
	  be changed in runtime.</p>
	<p>Defaults to <c>10</c>.</p>
	<p>The setting has no effect on a halt log.</p>
      </item>
      <tag><c>max_no_bytes</c></tag>
      <item>
	<p>This is the maximum number of bytes that is written to
	a log file before disk_log proceeds with the next file in order, or
	generates an error in case of a full halt log. The option
	corresponds to the <c>MaxNoBytes</c> element in the <c>size</c> property in the
	<seemfa marker="disk_log#open/1"><c>dlog_option()</c></seemfa>
	datatype.</p>
	<p>The value is set when the handler is added, and it cannot
	  be changed in runtime.</p>
	<p>Defaults to <c>1048576</c> bytes for a wrap log, and
	<c>infinity</c> for a halt log.</p>
      </item>
      <tag><c>filesync_repeat_interval</c></tag>
      <item>
	<p>This value, in milliseconds, specifies how often the handler does
	a disk_log sync operation to write buffered data to disk. The handler attempts
	the operation repeatedly, but only performs a new sync if something has
	actually been logged.</p>
	<p>Defaults to <c>5000</c> milliseconds.</p>
	<p>If <c>no_repeat</c> is set as value, the repeated sync operation
	is disabled. The user can also call the
	<seemfa marker="logger_disk_log_h#filesync/1"><c>filesync/1</c>
	</seemfa> function to perform a disk_log sync.</p>
      </item>
    </taglist>
    <p>Other configuration parameters exist, to be used for customizing
    the overload protection behaviour. The same parameters are used both in the
    standard handler and the disk_log handler, and are documented in the
    <seeguide marker="logger_chapter#overload_protection"><c>User's Guide</c>
    </seeguide>.</p>
    <p>Notice that when changing the configuration of the handler in runtime, the
    disk_log options (<c>file</c>, <c>type</c>, <c>max_no_files</c>,
    <c>max_no_bytes</c>) must not be modified.</p>
    <p>Example of adding a disk_log handler:</p>
    <code type="none">
logger:add_handler(my_disk_log_h, logger_disk_log_h,
                   #{config => #{file => "./my_disk_log",
                                 type => wrap,
                                 max_no_files => 4,
                                 max_no_bytes => 10000,
                                 filesync_repeat_interval => 1000}}).
    </code>
    <p>To use the disk_log handler instead of the default standard
    handler when starting an Erlang node, change the Kernel default logger to
    use <c>logger_disk_log_h</c>. Example:</p>
    <code type="none">
erl -kernel logger '[{handler,default,logger_disk_log_h,
                      #{config => #{file => "./system_disk_log"}}}]'
    </code>
  </description>

  <funcs>

    <func>
      <name name="filesync" arity="1" clause_i="1" since="OTP 21.0"/>
      <fsummary>Writes buffered data to disk.</fsummary>
      <desc>
        <p>Write buffered data to disk.</p>
      </desc>
    </func>

  </funcs>

  <section>
    <title>See Also</title>
    <p><seeerl marker="logger"><c>logger(3)</c></seeerl>,
      <seeerl marker="logger_std_h"><c>logger_std_h(3)</c></seeerl>,
      <seeerl marker="disk_log"><c>disk_log(3)</c></seeerl></p>
  </section>
</erlref>


