aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/doc/src/logger_std_h.xml
blob: a4f2848037e94a61d9d34716f3eaa3364ccf0815 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE erlref SYSTEM "erlref.dtd">

<erlref>
  <header>
    <copyright>
      <year>2017</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_std_h</title>
    <prepared></prepared>
    <responsible></responsible>
    <docno></docno>
    <approved></approved>
    <checked></checked>
    <date></date>
    <rev>A</rev>
    <file>logger_std_h.xml</file>
  </header>
  <module>logger_std_h</module>
  <modulesummary>Default handler for Logger.</modulesummary>

  <description>
    <p>This is the default handler for Logger.
      Multiple instances of this handler can be added to
      Logger, and each instance will print logs to <c>standard_io</c>,
      <c>standard_error</c> or to file. The default instance that starts
      with Kernel is named <c>default</c> - which is the name to be used
      for reconfiguration.</p>
    <p>The handler has an overload protection mechanism that will keep the handler
      process and the Kernel application alive during a high load of log 
      requests. How this feature works, and how to modify the configuration,
      is described in the
      <seealso marker="logger_chapter#overload_protection"><c>User's Guide</c>
      </seealso>.</p>
    <p>To add a new instance of the standard handler, use
      <seealso marker="logger#add_handler-3"><c>logger:add_handler/3</c>
      </seealso>. The handler configuration argument is a map which may contain
       general configuration parameters, as documented in the
       <seealso marker="logger_chapter#handler_configuration"><c>User's Guide</c>
       </seealso>, as well as handler specific parameters. The specific parameters
       are stored in a sub map with the key <c>logger_std_h</c>. The following
       keys and values may be specified:</p>
    <taglist>
      <tag><marker id="type"/><c>type</c></tag>
      <item>
	<p>This will have the value <c>standard_io</c>, <c>standard_error</c>,
	<c>{file,LogFileName}</c>, or <c>{file,LogFileName,LogFileOpts}</c>,
	where <c>standard_io</c> is the default value for type. It's recommended
	to not specify <c>LogFileOpts</c> if not absolutely necessary. The
	default options used by the handler to open a file for logging are:
	<c>raw</c>, <c>append</c> and <c>delayed_write</c>. The standard
	handler does not have support for circular logging. Use the
	<seealso marker="logger_disk_log_h"><c>logger_disk_log_h</c>
	</seealso> handler for this.</p></item>
      <tag><c>filesync_repeat_interval</c></tag>
      <item>
	<p>This value (in milliseconds) specifies how often the handler will
	do a file sync operation in order to make sure that buffered data gets
	written to disk. The handler will repeatedly attempt this
	operation, but only perform it if something has actually been logged
	since the last sync. The default value is <c>5000</c> milliseconds.
	If <c>no_repeat</c> is set as value, the repeated file sync operation
	is disabled, and it will be the operating system settings that determine
	how quickly or slowly data gets written	to disk. The user can also call
	the <seealso marker="logger_std_h#filesync-1"><c>filesync/1</c></seealso>
        function to perform a file sync.</p></item>
    </taglist>
    <p>There are a number of other configuration parameters available, that are
    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
    <seealso marker="logger_chapter#overload_protection"><c>User's Guide</c>
    </seealso>.</p>
    <p>Note that when changing the configuration of the handler in runtime, by
    calling
    <seealso marker="logger#set_handler_config-2"><c>logger:set_handler_config/2</c>
    </seealso>, or
    <seealso marker="logger#set_handler_config-3"><c>logger:set_handler_config/3</c>
    </seealso>,
    the <c>type</c> parameter may not be modified.</p>
    <p>Example of adding a standard handler:</p>
    <code type="none">
logger:add_handler(my_standard_h, logger_std_h,
                   #{level => info,
                     filter_default => log,
                     logger_std_h =>
                              #{type => {file,"./system_info.log"},
                                filesync_repeat_interval => 1000}}).
    </code>
    <p>In order to configure the default handler (that starts initially with
    the Kernel application) to log to file instead of <c>standard_io</c>,
    change the Kernel default logger to use a file. Example:</p>
    <code type="none">
erl -kernel logger '[{handler,default,logger_std_h,
                      #{ logger_std_h => #{ type => {file,"./log.log"}}}}]'
    </code>
    <p>An example of how to replace the standard handler with a disk_log handler
    at startup can be found in the manual of
    <seealso marker="logger_disk_log_h"><c>logger_disk_log_h</c></seealso>.</p>
  </description>

  <funcs>

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

  </funcs>

  <section>
    <title>See Also</title>
    <p><seealso marker="logger"><c>logger(3)</c></seealso></p>
    <p><seealso marker="logger_disk_log_h"><c>logger_disk_log_h(3)</c></seealso></p>
  </section>
</erlref>