1<?xml version="1.0" encoding="utf-8" ?>
2<!DOCTYPE erlref SYSTEM "erlref.dtd">
3
4<erlref>
5  <header>
6    <copyright>
7      <year>2017</year><year>2020</year>
8      <holder>Ericsson AB. All Rights Reserved.</holder>
9    </copyright>
10    <legalnotice>
11      Licensed under the Apache License, Version 2.0 (the "License");
12      you may not use this file except in compliance with the License.
13      You may obtain a copy of the License at
14
15          http://www.apache.org/licenses/LICENSE-2.0
16
17      Unless required by applicable law or agreed to in writing, software
18      distributed under the License is distributed on an "AS IS" BASIS,
19      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20      See the License for the specific language governing permissions and
21      limitations under the License.
22
23    </legalnotice>
24
25    <title>logger</title>
26    <prepared></prepared>
27    <responsible></responsible>
28    <docno></docno>
29    <approved></approved>
30    <checked></checked>
31    <date></date>
32    <rev>A</rev>
33    <file>logger.xml</file>
34  </header>
35  <module since="OTP 21.0">logger</module>
36  <modulesummary>API module for Logger, the standard logging facility
37    in Erlang/OTP.</modulesummary>
38
39  <description>
40    <p>This module implements the main API for logging in
41      Erlang/OTP. To create a log event, use the
42      <seealso marker="#logging_API">API functions</seealso> or the
43      log
44      <seealso marker="#macros">macros</seealso>, for example:</p>
45    <code>
46?LOG_ERROR("error happened because: ~p", [Reason]).   % With macro
47logger:error("error happened because: ~p", [Reason]). % Without macro
48    </code>
49    <p>To configure the Logger backend,
50      use <seealso marker="kernel_app#logger">Kernel configuration
51      parameters</seealso>
52      or <seealso marker="#configuration_API">configuration
53      functions</seealso> in the Logger API.</p>
54
55    <p>By default, the Kernel application installs one log handler at
56      system start. This handler is named <c>default</c>. It receives
57      and processes standard log events produced by the Erlang runtime
58      system, standard behaviours and different Erlang/OTP
59      applications. The log events are by default printed to the
60      terminal.</p>
61    <p>If you want your systems logs to be printed to a file instead,
62      you must configure the default handler to do so. The simplest
63      way is to include the following in
64      your <seealso marker="config"><c>sys.config</c></seealso>:</p>
65      <code>
66[{kernel,
67  [{logger,
68    [{handler, default, logger_std_h,
69      #{config => #{file => "path/to/file.log"}}}]}]}].
70      </code>
71    <p>
72      For more information about:
73    </p>
74    <list type="bulleted">
75      <item>the Logger facility in general, see
76        the <seealso marker="logger_chapter">User's
77        Guide</seealso>.</item>
78      <item>how to configure Logger, see
79        the <seealso marker="logger_chapter#configuration">Configuration</seealso>
80        section in the User's Guide.</item>
81      <item>the built-in handlers,
82        see <seealso marker="logger_std_h">logger_std_h</seealso> and
83        <seealso marker="logger_disk_log_h">logger_disk_log_h</seealso>.</item>
84      <item>the built-in formatter,
85        see <seealso marker="logger_formatter">logger_formatter</seealso>.</item>
86      <item>built-in filters,
87      see <seealso marker="logger_filters">logger_filters</seealso>.</item>
88    </list>
89
90    <note>
91      <p>Since Logger is new in Erlang/OTP 21.0, we do reserve the right
92	to introduce changes to the Logger API and functionality in
93	patches following this release. These changes might or might not
94	be backwards compatible with the initial version.</p>
95    </note>
96
97  </description>
98
99  <datatypes>
100    <datatype>
101      <name name="filter"/>
102      <desc>
103	<p>A filter which can be installed as a handler filter, or as
104	  a primary filter in Logger.</p>
105      </desc>
106    </datatype>
107    <datatype>
108      <name name="filter_arg"/>
109      <desc>
110	<p>The second argument to the filter fun.</p>
111      </desc>
112    </datatype>
113    <datatype>
114      <name name="filter_id"/>
115      <desc>
116	<p>A unique identifier for a filter.</p>
117      </desc>
118    </datatype>
119    <datatype>
120      <name name="filter_return"/>
121      <desc>
122	<p>The return value from the filter fun.</p>
123      </desc>
124    </datatype>
125    <datatype>
126      <name name="formatter_config"/>
127      <desc>
128	<p>Configuration data for the
129	formatter. See <seealso marker="logger_formatter">
130	    <c>logger_formatter(3)</c></seealso>
131	  for an example of a formatter implementation.</p>
132      </desc>
133    </datatype>
134    <datatype>
135      <name name="handler_config"/>
136      <desc>
137	<p>Handler configuration data for Logger. The following
138	  default values apply:</p>
139	<list>
140	  <item><c>level => all</c></item>
141	  <item><c>filter_default => log</c></item>
142	  <item><c>filters => []</c></item>
143	  <item><c>formatter => {logger_formatter, DefaultFormatterConfig</c>}</item>
144	</list>
145	<p>In addition to these, the following fields are
146	  automatically inserted by Logger, values taken from the
147	  two first parameters
148	  to <seealso marker="#add_handler-3"><c>add_handler/3</c></seealso>:</p>
149	<list>
150	  <item><c>id => HandlerId</c></item>
151	  <item><c>module => Module</c></item>
152	</list>
153	<p>These are read-only and cannot be changed in runtime.</p>
154	<p>Handler specific configuration data is inserted by the
155	  handler callback itself, in a sub structure associated with
156	  the field named <c>config</c>. See
157	  the <seealso marker="logger_std_h"><c>logger_std_h(3)</c></seealso>
158	  and <seealso marker="logger_disk_log_h"><c>logger_disk_log_h(3)</c></seealso>
159	  manual pages for information about the specifc configuration
160	  for these handlers.</p>
161	<p>See the <seealso marker="logger_formatter#type-config">
162	    <c>logger_formatter(3)</c></seealso> manual page for
163	  information about the default configuration for this
164	  formatter.</p>
165      </desc>
166    </datatype>
167    <datatype>
168      <name name="handler_id"/>
169      <desc>
170	<p>A unique identifier for a handler instance.</p>
171      </desc>
172    </datatype>
173    <datatype>
174      <name name="level"/>
175      <desc>
176	<p>The severity level for the message to be logged.</p>
177      </desc>
178    </datatype>
179    <datatype>
180      <name name="log_event"/>
181      <desc>
182	<p></p>
183      </desc>
184    </datatype>
185    <datatype>
186      <name name="metadata"/>
187      <desc>
188	<p>Metadata for the log event.</p>
189	<p>Logger adds the following metadata to each log event:</p>
190	<list>
191	  <item><c>pid  => self()</c></item>
192	  <item><c>gl   => group_leader()</c></item>
193	  <item><c>time => logger:timestamp()</c></item>
194	</list>
195	<p>When a log macro is used, Logger also inserts location
196	  information:</p>
197	<list>
198	  <item><c>mfa  => {?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY}</c></item>
199	  <item><c>file => ?FILE</c></item>
200	  <item><c>line => ?LINE</c></item>
201	</list>
202	<p>You can add custom metadata, either by specifying a map as
203	  the last parameter to any of the log macros or the API
204	  functions, or by setting process metadata
205	  with <seealso marker="#set_process_metadata-1">
206	    <c>set_process_metadata/1</c></seealso>
207	  or <seealso marker="#update_process_metadata-1">
208	    <c>update_process_metadata/1</c></seealso>.</p>
209	<p>Logger merges all the metadata maps before forwarding the
210	  log event to the handlers. If the same keys occur, values
211	  from the log call overwrite process metadata, which in turn
212	  overwrite values set by Logger.</p>
213	<p>The following custom metadata keys have special meaning:</p>
214	<taglist>
215	  <tag><c>domain</c></tag>
216	  <item>
217	    <p>The value associated with this key is used by filters
218	      for grouping log events originating from, for example,
219	      specific functional
220	      areas. See <seealso marker="logger_filters#domain-2">
221		<c>logger_filters:domain/2</c></seealso>
222	      for a description of how this field can be used.</p>
223	  </item>
224	  <tag><c>report_cb</c></tag>
225	  <item>
226	    <p>If the log message is specified as
227	      a <seealso marker="#type-report"><c>report()</c></seealso>,
228	      the <c>report_cb</c> key can be associated with a fun
229	      (report callback) that converts the report to a format
230	      string and arguments, or directly to a string. See the
231	      type definition
232	      of <seealso marker="#type-report_cb"><c>report_cb()</c></seealso>,
233	      and
234	      section <seealso marker="logger_chapter#log_message">Log
235	      Message</seealso> in the User's Guide for more
236	      information about report callbacks.</p>
237	  </item>
238	</taglist>
239      </desc>
240    </datatype>
241    <datatype>
242      <name name="msg_fun"/>
243      <desc>
244	<p></p>
245      </desc>
246    </datatype>
247    <datatype>
248      <name name="olp_config"/>
249      <desc>
250	<p></p>
251      </desc>
252    </datatype>
253    <datatype>
254      <name name="primary_config"/>
255      <desc>
256	<p>Primary configuration data for Logger. The following
257	  default values apply:</p>
258	<list>
259	  <item><c>level => info</c></item>
260	  <item><c>filter_default => log</c></item>
261	  <item><c>filters => []</c></item>
262	</list>
263      </desc>
264    </datatype>
265    <datatype>
266      <name name="report"/>
267      <desc>
268	<p></p>
269      </desc>
270    </datatype>
271    <datatype>
272      <name name="report_cb"/>
273      <desc>
274	<p>A fun which converts a <seealso marker="#type-report"><c>report()</c>
275	  </seealso> to a format string and arguments, or directly to a string.
276	  See section <seealso marker="logger_chapter#log_message">Log
277	    Message</seealso> in the User's Guide for more
278	  information.</p>
279      </desc>
280    </datatype>
281    <datatype>
282      <name name="report_cb_config"/>
283      <desc>
284	<p></p>
285      </desc>
286    </datatype>
287    <datatype>
288      <name name="timestamp"/>
289      <desc>
290	<p>A timestamp produced
291	  with <seealso marker="#timestamp-0">
292	    <c>logger:timestamp()</c></seealso>.</p>
293      </desc>
294    </datatype>
295  </datatypes>
296
297  <section>
298    <title>Macros</title>
299    <p>The following macros are defined in <c>logger.hrl</c>, which
300      is included in a module with the directive</p>
301    <code>
302    -include_lib("kernel/include/logger.hrl").</code>
303
304    <list>
305      <item><c>?LOG_EMERGENCY(StringOrReport[,Metadata])</c></item>
306      <item><c>?LOG_EMERGENCY(FunOrFormat,Args[,Metadata])</c></item>
307      <item><c>?LOG_ALERT(StringOrReport[,Metadata])</c></item>
308      <item><c>?LOG_ALERT(FunOrFormat,Args[,Metadata])</c></item>
309      <item><c>?LOG_CRITICAL(StringOrReport[,Metadata])</c></item>
310      <item><c>?LOG_CRITICAL(FunOrFormat,Args[,Metadata])</c></item>
311      <item><c>?LOG_ERROR(StringOrReport[,Metadata])</c></item>
312      <item><c>?LOG_ERROR(FunOrFormat,Args[,Metadata])</c></item>
313      <item><c>?LOG_WARNING(StringOrReport[,Metadata])</c></item>
314      <item><c>?LOG_WARNING(FunOrFormat,Args[,Metadata])</c></item>
315      <item><c>?LOG_NOTICE(StringOrReport[,Metadata])</c></item>
316      <item><c>?LOG_NOTICE(FunOrFormat,Args[,Metadata])</c></item>
317      <item><c>?LOG_INFO(StringOrReport[,Metadata])</c></item>
318      <item><c>?LOG_INFO(FunOrFormat,Args[,Metadata])</c></item>
319      <item><c>?LOG_DEBUG(StringOrReport[,Metadata])</c></item>
320      <item><c>?LOG_DEBUG(FunOrFormat,Args[,Metadata])</c></item>
321      <item><c>?LOG(Level,StringOrReport[,Metadata])</c></item>
322      <item><c>?LOG(Level,FunOrFormat,Args[,Metadata])</c></item>
323    </list>
324
325    <p>All macros expand to a call to Logger, where <c>Level</c> is
326      taken from the macro name, or from the first argument in the
327      case of the <c>?LOG</c> macro. Location data is added to the
328      metadata as described under
329      the <seealso marker="#type-metadata"><c>metadata()</c></seealso>
330      type definition.</p>
331
332    <p>The call is wrapped in a case statement and will be evaluated
333      only if <c>Level</c> is equal to or below the configured log
334      level.</p>
335  </section>
336
337  <section>
338    <marker id="logging_API"/>
339    <title>Logging API functions</title>
340  </section>
341  <funcs>
342    <func>
343      <name since="OTP 21.0">emergency(StringOrReport[,Metadata])</name>
344      <name since="OTP 21.0">emergency(Format,Args[,Metadata])</name>
345      <name since="OTP 21.0">emergency(Fun,FunArgs[,Metadata])</name>
346      <fsummary>Logs the given message as level <c>emergency</c>.</fsummary>
347      <desc>
348        <p>Equivalent to
349	<seealso marker="#log-2"><c>log(emergency,...)</c></seealso>.</p>
350      </desc>
351    </func>
352
353    <func>
354      <name since="OTP 21.0">alert(StringOrReport[,Metadata])</name>
355      <name since="OTP 21.0">alert(Format,Args[,Metadata])</name>
356      <name since="OTP 21.0">alert(Fun,FunArgs[,Metadata])</name>
357      <fsummary>Logs the given message as level <c>alert</c>.</fsummary>
358      <desc>
359        <p>Equivalent to
360	<seealso marker="#log-2"><c>log(alert,...)</c></seealso>.</p>
361      </desc>
362    </func>
363
364    <func>
365      <name since="OTP 21.0">critical(StringOrReport[,Metadata])</name>
366      <name since="OTP 21.0">critical(Format,Args[,Metadata])</name>
367      <name since="OTP 21.0">critical(Fun,FunArgs[,Metadata])</name>
368      <fsummary>Logs the given message as level <c>critical</c>.</fsummary>
369      <desc>
370        <p>Equivalent to
371	<seealso marker="#log-2"><c>log(critical,...)</c></seealso>.</p>
372      </desc>
373    </func>
374
375    <func>
376      <name since="OTP 21.0">error(StringOrReport[,Metadata])</name>
377      <name since="OTP 21.0">error(Format,Args[,Metadata])</name>
378      <name since="OTP 21.0">error(Fun,FunArgs[,Metadata])</name>
379      <fsummary>Logs the given message as level <c>error</c>.</fsummary>
380      <desc>
381        <p>Equivalent to
382	<seealso marker="#log-2"><c>log(error,...)</c></seealso>.</p>
383      </desc>
384    </func>
385
386    <func>
387      <name since="OTP 21.0">warning(StringOrReport[,Metadata])</name>
388      <name since="OTP 21.0">warning(Format,Args[,Metadata])</name>
389      <name since="OTP 21.0">warning(Fun,FunArgs[,Metadata])</name>
390      <fsummary>Logs the given message as level <c>warning</c>.</fsummary>
391      <desc>
392        <p>Equivalent to
393	<seealso marker="#log-2"><c>log(warning,...)</c></seealso>.</p>
394      </desc>
395    </func>
396
397    <func>
398      <name since="OTP 21.0">notice(StringOrReport[,Metadata])</name>
399      <name since="OTP 21.0">notice(Format,Args[,Metadata])</name>
400     <name since="OTP 21.0">notice(Fun,FunArgs[,Metadata])</name>
401      <fsummary>Logs the given message as level <c>notice</c>.</fsummary>
402      <desc>
403        <p>Equivalent to
404	<seealso marker="#log-2"><c>log(notice,...)</c></seealso>.</p>
405      </desc>
406    </func>
407
408    <func>
409      <name since="OTP 21.0">info(StringOrReport[,Metadata])</name>
410      <name since="OTP 21.0">info(Format,Args[,Metadata])</name>
411      <name since="OTP 21.0">info(Fun,FunArgs[,Metadata])</name>
412      <fsummary>Logs the given message as level <c>info</c>.</fsummary>
413      <desc>
414        <p>Equivalent to
415	<seealso marker="#log-2"><c>log(info,...)</c></seealso>.</p>
416      </desc>
417    </func>
418
419    <func>
420      <name since="OTP 21.0">debug(StringOrReport[,Metadata])</name>
421      <name since="OTP 21.0">debug(Format,Args[,Metadata])</name>
422      <name since="OTP 21.0">debug(Fun,FunArgs[,Metadata])</name>
423      <fsummary>Logs the given message as level <c>debug</c>.</fsummary>
424      <desc>
425        <p>Equivalent to
426	<seealso marker="#log-2"><c>log(debug,...)</c></seealso>.</p>
427      </desc>
428    </func>
429
430    <func>
431      <name name="log" arity="2" since="OTP 21.0"/>
432      <name name="log" arity="3" clause_i="1" since="OTP 21.0"/>
433      <name name="log" arity="3" clause_i="2" since="OTP 21.0"/>
434      <name name="log" arity="3" clause_i="3" since="OTP 21.0"/>
435      <name name="log" arity="4" clause_i="1" since="OTP 21.0"/>
436      <name name="log" arity="4" clause_i="2" since="OTP 21.0"/>
437      <fsummary>Logs the given message.</fsummary>
438      <type variable="Level"/>
439      <type variable="StringOrReport" name_i="1"/>
440      <type variable="Format" name_i="3"/>
441      <type variable="Args" name_i="3"/>
442      <type variable="Fun" name_i="4"/>
443      <type variable="FunArgs" name_i="4"/>
444      <type variable="Metadata"/>
445      <desc>
446        <p>Log the given message.</p>
447      </desc>
448    </func>
449  </funcs>
450
451  <section>
452    <marker id="configuration_API"/>
453    <title>Configuration API functions</title>
454  </section>
455  <funcs>
456    <func>
457      <name name="add_handler" arity="3" since="OTP 21.0"/>
458      <fsummary>Add a handler with the given configuration.</fsummary>
459      <desc>
460        <p>Add a handler with the given configuration.</p>
461	<p><c><anno>HandlerId</anno></c> is a unique identifier which
462	  must be used in all subsequent calls referring to this
463	  handler.</p>
464      </desc>
465    </func>
466
467    <func>
468      <name name="add_handler_filter" arity="3" since="OTP 21.0"/>
469      <fsummary>Add a filter to the specified handler.</fsummary>
470      <desc>
471        <p>Add a filter to the specified handler.</p>
472	<p>The filter fun is called with the log event as the first
473	  parameter, and the specified <c>filter_args()</c> as the
474	  second parameter.</p>
475	<p>The return value of the fun specifies if a log event is to
476	  be discarded or forwarded to the handler callback:</p>
477	<taglist>
478	  <tag><c>log_event()</c></tag>
479	  <item>
480	    <p>The filter <em>passed</em>. The next handler filter, if
481	      any, is applied. If no more filters exist for this
482	      handler, the log event is forwarded to the handler
483	      callback.</p>
484	  </item>
485	  <tag><c>stop</c></tag>
486	  <item>
487	    <p>The filter <em>did not pass</em>, and the log event is
488	      immediately discarded.</p>
489	  </item>
490	  <tag><c>ignore</c></tag>
491	  <item>
492	    <p>The filter has no knowledge of the log event. The next
493	      handler filter, if any, is applied. If no more filters
494	      exist for this handler, the value of
495	      the <c>filter_default</c> configuration parameter for
496	      the handler specifies if the log event shall be
497	      discarded or forwarded to the handler callback.</p>
498	  </item>
499	</taglist>
500	<p>See
501	  section <seealso marker="logger_chapter#filters">Filters</seealso>
502	  in the User's Guide for more information about filters.</p>
503	<p>Some built-in filters exist. These are defined in
504	  <seealso marker="logger_filters"><c>logger_filters(3)</c></seealso>.</p>
505      </desc>
506    </func>
507
508    <func>
509      <name name="add_handlers" arity="1" clause_i="1" since="OTP 21.0"/>
510      <fsummary>Set up log handlers from the application's
511	configuration parameters.</fsummary>
512      <desc>
513        <p>Reads the application configuration parameter <c>logger</c> and
514          calls <c>add_handlers/1</c> with its contents.</p>
515      </desc>
516    </func>
517
518    <func>
519      <name name="add_handlers" arity="1" clause_i="2" since="OTP 21.0"/>
520      <fsummary>Setup logger handlers.</fsummary>
521      <type name="config_handler"/>
522      <desc>
523        <p>This function should be used by custom Logger handlers to make
524        configuration consistent no matter which handler the system uses.
525        Normal usage is to add a call to <c>logger:add_handlers/1</c>
526        just after the processes that the handler needs are started,
527        and pass the application's <c>logger</c> configuration as the argument.
528	For example:</p>
529        <code>
530-behaviour(application).
531start(_, []) ->
532    case supervisor:start_link({local, my_sup}, my_sup, []) of
533        {ok, Pid} ->
534            ok = logger:add_handlers(my_app),
535            {ok, Pid, []};
536        Error -> Error
537     end.</code>
538       <p>This reads the <c>logger</c> configuration parameter from
539         the <c>my_app</c> application and starts the configured
540         handlers. The contents of the configuration use the same
541         rules as the
542         <seealso marker="logger_chapter#handler-configuration">logger handler configuration</seealso>.
543       </p>
544       <p>If the handler is meant to replace the default handler, the Kernel's
545         default handler have to be disabled before the new handler is added.
546         A <c>sys.config</c> file that disables the Kernel handler and adds
547         a custom handler could look like this:</p>
548         <code>
549[{kernel,
550  [{logger,
551    %% Disable the default Kernel handler
552    [{handler, default, undefined}]}]},
553 {my_app,
554  [{logger,
555    %% Enable this handler as the default
556    [{handler, default, my_handler, #{}}]}]}].
557         </code>
558      </desc>
559    </func>
560
561    <func>
562      <name name="add_primary_filter" arity="2" since="OTP 21.0"/>
563      <fsummary>Add a primary filter to Logger.</fsummary>
564      <desc>
565        <p>Add a primary filter to Logger.</p>
566	<p>The filter fun is called with the log event as the first
567	  parameter, and the specified <c>filter_args()</c> as the
568	  second parameter.</p>
569	<p>The return value of the fun specifies if a log event is to
570	  be discarded or forwarded to the handlers:</p>
571	<taglist>
572	  <tag><c>log_event()</c></tag>
573	  <item>
574	    <p>The filter <em>passed</em>. The next primary filter, if
575	      any, is applied. If no more primary filters exist, the
576	      log event is forwarded to the handler part of Logger,
577	      where handler filters are applied.</p>
578	  </item>
579	  <tag><c>stop</c></tag>
580	  <item>
581	    <p>The filter <em>did not pass</em>, and the log event is
582	      immediately discarded.</p>
583	  </item>
584	  <tag><c>ignore</c></tag>
585	  <item>
586	    <p>The filter has no knowledge of the log event. The next
587	      primary filter, if any, is applied. If no more primary
588	      filters exist, the value of the
589	      primary <c>filter_default</c> configuration parameter
590	      specifies if the log event shall be discarded or
591	      forwarded to the handler part.</p>
592	  </item>
593	</taglist>
594	<p>See section <seealso marker="logger_chapter#filters">
595	    Filters</seealso> in the User's Guide for more information
596	    about filters.</p>
597	<p>Some built-in filters exist. These are defined
598	  in <seealso marker="logger_filters"><c>logger_filters(3)</c></seealso>.</p>
599      </desc>
600    </func>
601
602    <func>
603      <name name="get_config" arity="0" since="OTP 21.0"/>
604      <fsummary>Look up the current Logger configuration</fsummary>
605      <desc>
606        <p>Look up all current Logger configuration, including primary,
607          handler, and proxy configuration, and module level settings.</p>
608      </desc>
609    </func>
610
611    <func>
612      <name name="get_handler_config" arity="0" since="OTP 21.0"/>
613      <fsummary>Look up the current configuration for all handlers.</fsummary>
614      <desc>
615        <p>Look up the current configuration for all handlers.</p>
616      </desc>
617    </func>
618
619    <func>
620      <name name="get_handler_config" arity="1" since="OTP 21.0"/>
621      <fsummary>Look up the current configuration for the given
622	handler.</fsummary>
623      <desc>
624        <p>Look up the current configuration for the given handler.</p>
625      </desc>
626    </func>
627
628    <func>
629      <name name="get_handler_ids" arity="0" since="OTP 21.0"/>
630      <fsummary>Look up the identities for all installed handlers.</fsummary>
631      <desc>
632        <p>Look up the identities for all installed handlers.</p>
633      </desc>
634    </func>
635
636    <func>
637      <name name="get_primary_config" arity="0" since="OTP 21.0"/>
638      <fsummary>Look up the current primary configuration for Logger.</fsummary>
639      <desc>
640        <p>Look up the current primary configuration for Logger.</p>
641      </desc>
642    </func>
643
644    <func>
645      <name name="get_proxy_config" arity="0" since="OTP 21.3"/>
646      <fsummary>Look up the current configuration for the Logger proxy.</fsummary>
647      <desc>
648        <p>Look up the current configuration for the Logger proxy.</p>
649	<p>For more information about the proxy, see
650	  section <seealso marker="logger_chapter#proxy">Logger
651	  Proxy</seealso> in the Kernel User's Guide.</p>
652      </desc>
653    </func>
654
655    <func>
656      <name name="get_module_level" arity="0" since="OTP 21.0"/>
657      <fsummary>Look up all current module levels.</fsummary>
658      <desc>
659        <p>Look up all current module levels. Returns a list
660          containing one <c>{Module,Level}</c> element for each module
661          for which the module level was previously set
662          with <seealso marker="#set_module_level-2">
663	    <c>set_module_level/2</c></seealso>.</p>
664      </desc>
665    </func>
666
667    <func>
668      <name name="get_module_level" arity="1" since="OTP 21.0"/>
669      <fsummary>Look up the current level for the given modules.</fsummary>
670      <desc>
671        <p>Look up the current level for the given modules. Returns a
672          list containing one <c>{Module,Level}</c> element for each
673          of the given modules for which the module level was
674          previously set with <seealso marker="#set_module_level-2">
675	    <c>set_module_level/2</c></seealso>.</p>
676      </desc>
677    </func>
678
679    <func>
680      <name name="get_process_metadata" arity="0" since="OTP 21.0"/>
681      <fsummary>Retrieve data set with set_process_metadata/1.</fsummary>
682      <desc>
683        <p>Retrieve data set
684          with <seealso marker="#set_process_metadata-1">
685	    <c>set_process_metadata/1</c></seealso> or
686	  <seealso marker="#update_process_metadata-1">
687	    <c>update_process_metadata/1</c></seealso>.</p>
688      </desc>
689    </func>
690
691    <func>
692      <name name="i" arity="0" since="OTP 21.3"/>
693      <name name="i" arity="1" since="OTP 21.3"/>
694      <fsummary>Pretty print the Logger configuration.</fsummary>
695      <desc>
696        <p>Pretty print the Logger configuration.</p>
697      </desc>
698    </func>
699
700    <func>
701      <name name="remove_handler" arity="1" since="OTP 21.0"/>
702      <fsummary>Remove the handler with the specified identity.</fsummary>
703      <desc>
704        <p>Remove the handler identified by <c><anno>HandlerId</anno></c>.</p>
705      </desc>
706    </func>
707
708    <func>
709      <name name="remove_handler_filter" arity="2" since="OTP 21.0"/>
710      <fsummary>Remove a filter from the specified handler.</fsummary>
711      <desc>
712        <p>Remove the filter identified
713          by <c><anno>FilterId</anno></c> from the handler identified
714          by <c><anno>HandlerId</anno></c>.</p>
715      </desc>
716    </func>
717
718    <func>
719      <name name="remove_primary_filter" arity="1" since="OTP 21.0"/>
720      <fsummary>Remove a primary filter from Logger.</fsummary>
721      <desc>
722        <p>Remove the primary filter identified
723          by <c><anno>FilterId</anno></c> from Logger.</p>
724      </desc>
725    </func>
726
727    <func>
728      <name name="set_application_level" arity="2" since="OTP 21.1"/>
729      <fsummary>Set the log level for all modules in the specified application.</fsummary>
730      <desc>
731        <p>Set the log level for all the modules of the specified application.</p>
732        <p>This function is a convenience function that calls
733          <seealso marker="#set_module_level/2">logger:set_module_level/2</seealso>
734          for each module associated with an application.</p>
735      </desc>
736    </func>
737
738    <func>
739      <name name="set_handler_config" arity="2" since="OTP 21.0"/>
740      <fsummary>Set configuration data for the specified handler.</fsummary>
741      <desc>
742        <p>Set configuration data for the specified handler. This
743          overwrites the current handler configuration.</p>
744	<p>To modify the existing configuration,
745	  use <seealso marker="#update_handler_config-2">
746	    <c>update_handler_config/2</c></seealso>, or, if a more
747	  complex merge is needed, read the current configuration
748	  with <seealso marker="#get_handler_config-1"><c>get_handler_config/1</c>
749	  </seealso>, then do the merge before writing the new
750	  configuration back with this function.</p>
751	<p>If a key is removed compared to the current configuration,
752	  and the key is known by Logger, the default value is used. If
753	  it is a custom key, then it is up to the handler
754	  implementation if the value is removed or a default value is
755	  inserted.</p>
756      </desc>
757    </func>
758
759    <func>
760      <name name="set_handler_config" arity="3" clause_i="1" since="OTP 21.0"/>
761      <name name="set_handler_config" arity="3" clause_i="2" since="OTP 21.0"/>
762      <name name="set_handler_config" arity="3" clause_i="3" since="OTP 21.0"/>
763      <name name="set_handler_config" arity="3" clause_i="4" since="OTP 21.0"/>
764      <name name="set_handler_config" arity="3" clause_i="5" since="OTP 21.0"/>
765      <fsummary>Add or update configuration data for the specified
766        handler.</fsummary>
767      <type variable="HandlerId"/>
768      <type variable="Level" name_i="1"/>
769      <type variable="FilterDefault" name_i="2"/>
770      <type variable="Filters" name_i="3"/>
771      <type variable="Formatter" name_i="4"/>
772      <type variable="Config" name_i="5"/>
773      <type variable="Return"/>
774      <desc>
775        <p>Add or update configuration data for the specified
776          handler. If the given <c><anno>Key</anno></c> already
777          exists, its associated value will be changed
778          to the given value. If it does not exist, it will
779          be added.</p>
780	<p>If the value is incomplete, which for example can be the
781	  case for the <c>config</c> key, it is up to the handler
782	  implementation how the unspecified parts are set. For all
783	  handlers in the Kernel application, unspecified data for
784	  the <c>config</c> key is set to default values. To update
785	  only specified data, and keep the existing configuration for
786	  the rest, use <seealso marker="#update_handler_config-3">
787	    <c>update_handler_config/3</c></seealso>.</p>
788	<p>See the definition of
789	  the <seealso marker="#type-handler_config">
790	    <c>handler_config()</c></seealso> type for more
791	  information about the different parameters.</p>
792      </desc>
793    </func>
794
795    <func>
796      <name name="set_primary_config" arity="1" since="OTP 21.0"/>
797      <fsummary>Set primary configuration data for Logger.</fsummary>
798      <desc>
799        <p>Set primary configuration data for Logger. This
800          overwrites the current configuration.</p>
801	<p>To modify the existing configuration,
802	  use <seealso marker="#update_primary_config-1">
803	    <c>update_primary_config/1</c></seealso>, or, if a more
804	  complex merge is needed, read the current configuration
805	  with <seealso marker="#get_primary_config-0"><c>get_primary_config/0</c>
806	  </seealso>, then do the merge before writing the new
807	  configuration back with this function.</p>
808	<p>If a key is removed compared to the current configuration,
809	  the default value is used.</p>
810      </desc>
811    </func>
812
813    <func>
814      <name name="set_primary_config" arity="2" clause_i="1" since="OTP 21.0"/>
815      <name name="set_primary_config" arity="2" clause_i="2" since="OTP 21.0"/>
816      <name name="set_primary_config" arity="2" clause_i="3" since="OTP 21.0"/>
817      <fsummary>Add or update primary configuration data for Logger.</fsummary>
818      <type variable="Level" name_i="1"/>
819      <type variable="FilterDefault" name_i="2"/>
820      <type variable="Filters" name_i="3"/>
821      <desc>
822        <p>Add or update primary configuration data for Logger. If the
823          given <c><anno>Key</anno></c> already exists, its associated
824          value will be changed to the given value. If it does not
825          exist, it will be added.</p>
826      </desc>
827    </func>
828
829    <func>
830      <name name="set_proxy_config" arity="1" since="OTP 21.3"/>
831      <fsummary>Set configuration data for the Logger proxy.</fsummary>
832      <desc>
833        <p>Set configuration data for the Logger proxy. This
834          overwrites the current proxy configuration. Keys that are not
835          specified in the <c><anno>Config</anno></c> map gets default
836          values.</p>
837	<p>To modify the existing configuration,
838	  use <seealso marker="#update_proxy_config-1">
839	    <c>update_proxy_config/1</c></seealso>, or, if a more
840	  complex merge is needed, read the current configuration
841	  with <seealso marker="#get_proxy_config-0"><c>get_proxy_config/0</c>
842	  </seealso>, then do the merge before writing the new
843	  configuration back with this function.</p>
844	<p>For more information about the proxy, see
845	  section <seealso marker="logger_chapter#proxy">Logger
846	  Proxy</seealso> in the Kernel User's Guide.</p>
847      </desc>
848    </func>
849
850    <func>
851      <name name="set_module_level" arity="2" since="OTP 21.0"/>
852      <fsummary>Set the log level for the specified modules.</fsummary>
853      <desc>
854        <p>Set the log level for the specified modules.</p>
855	<p>The log level for a module overrides the primary log level
856	  of Logger for log events originating from the module in
857	  question. Notice, however, that it does not override the
858	  level configuration for any handler.</p>
859	<p>For example: Assume that the primary log level for Logger
860	  is <c>info</c>, and there is one handler, <c>h1</c>, with
861	  level <c>info</c> and one handler, <c>h2</c>, with
862	  level <c>debug</c>.</p>
863	<p>With this configuration, no debug messages will be logged,
864	  since they are all stopped by the primary log level.</p>
865	<p>If the level for <c>mymodule</c> is now set
866	  to <c>debug</c>, then debug events from this module will be
867	  logged by the handler <c>h2</c>, but not by
868	  handler <c>h1</c>.</p>
869	<p>Debug events from other modules are still not logged.</p>
870        <p>To change the primary log level for Logger, use
871          <seealso marker="#set_primary_config/2">
872	    <c>set_primary_config(level, Level)</c></seealso>.</p>
873        <p>To change the log level for a handler, use
874          <seealso marker="#set_handler_config/3">
875	    <c>set_handler_config(HandlerId, level, Level)</c>
876	  </seealso>.</p>
877	<note>
878	  <p>The originating module for a log event is only detected
879	    if the key <c>mfa</c> exists in the metadata, and is
880	    associated with <c>{Module, Function, Arity}</c>. When log
881	    macros are used, this association is automatically added
882	    to all log events. If an API function is called directly,
883	    without using a macro, the logging client must explicitly
884	    add this information if module levels shall have any
885	    effect.</p>
886	</note>
887      </desc>
888    </func>
889
890    <func>
891      <name name="set_process_metadata" arity="1" since="OTP 21.0"/>
892      <fsummary>Set metadata to use when logging from current process.</fsummary>
893      <desc>
894        <p>Set metadata which Logger shall automatically insert in
895          all log events produced on the current process.</p>
896	<p>Location data produced by the log macros, and/or metadata
897	  given as argument to the log call (API function or macro),
898	  are merged with the process metadata. If the same keys
899	  occur, values from the metadata argument to the log call
900	  overwrite values from the process metadata, which in turn
901	  overwrite values from the location data.</p>
902	<p>Subsequent calls to this function overwrites previous data
903          set. To update existing data instead of overwriting it,
904          see <seealso marker="#update_process_metadata-1">
905	    <c>update_process_metadata/1</c></seealso>.</p>
906      </desc>
907    </func>
908
909    <func>
910      <name name="unset_application_level" arity="1" since="OTP 21.1"/>
911      <fsummary>Unset the log level for all modules in the specified application.</fsummary>
912      <desc>
913        <p>Unset the log level for all the modules of the specified application.</p>
914        <p>This function is a convinience function that calls
915          <seealso marker="#unset_module_level/1">logger:unset_module_level/2</seealso>
916          for each module associated with an application.</p>
917      </desc>
918    </func>
919
920    <func>
921      <name name="unset_module_level" arity="0" since="OTP 21.0"/>
922      <fsummary>Remove module specific log settings for all modules.</fsummary>
923      <desc>
924        <p>Remove module specific log settings. After this, the
925          primary log level is used for all modules.</p>
926      </desc>
927    </func>
928
929    <func>
930      <name name="unset_module_level" arity="1" since="OTP 21.0"/>
931      <fsummary>Remove module specific log settings for the given
932	modules.</fsummary>
933      <desc>
934        <p>Remove module specific log settings. After this, the
935          primary log level is used for the specified modules.</p>
936      </desc>
937    </func>
938
939    <func>
940      <name name="unset_process_metadata" arity="0" since="OTP 21.0"/>
941      <fsummary>Delete data set with set_process_metadata/1.</fsummary>
942      <desc>
943        <p>Delete data set
944          with <seealso marker="#set_process_metadata-1">
945	    <c>set_process_metadata/1</c></seealso> or
946	  <seealso marker="#update_process_metadata-1">
947	    <c>update_process_metadata/1</c></seealso>.</p>
948      </desc>
949    </func>
950
951    <func>
952      <name name="update_formatter_config" arity="2" since="OTP 21.0"/>
953      <fsummary>Update the formatter configuration for the specified handler.</fsummary>
954      <desc>
955        <p>Update the formatter configuration for the specified handler.</p>
956	<p>The new configuration is merged with the existing formatter
957	  configuration.</p>
958	<p>To overwrite the existing configuration without any merge,
959	  use</p>
960	<pre>
961<seealso marker="#set_handler_config-3">set_handler_config(HandlerId, formatter,
962	      {FormatterModule, FormatterConfig})</seealso>.</pre>
963      </desc>
964    </func>
965
966    <func>
967      <name name="update_formatter_config" arity="3" since="OTP 21.0"/>
968      <fsummary>Update the formatter configuration for the specified handler.</fsummary>
969      <desc>
970        <p>Update the formatter configuration for the specified handler.</p>
971	<p>This is equivalent to</p>
972	<pre>
973<seealso marker="#update_formatter_config-2">update_formatter_config(<anno>HandlerId</anno>, #{<anno>Key</anno> => <anno>Value</anno>})</seealso></pre>
974      </desc>
975    </func>
976
977    <func>
978      <name name="update_handler_config" arity="2" since="OTP 21.0"/>
979      <fsummary>Update configuration data for the specified handler.</fsummary>
980      <desc>
981        <p>Update configuration data for the specified handler. This function
982          behaves as if it was implemented as follows:</p>
983	<code type="erl">
984{ok, {_, Old}} = logger:get_handler_config(HandlerId),
985logger:set_handler_config(HandlerId, maps:merge(Old, Config)).
986	</code>
987	<p>To overwrite the existing configuration without any merge,
988	  use <seealso marker="#set_handler_config-2"><c>set_handler_config/2</c>
989	  </seealso>.</p>
990      </desc>
991    </func>
992
993    <func>
994      <name name="update_handler_config" arity="3" clause_i="1" since="OTP 21.2"/>
995      <name name="update_handler_config" arity="3" clause_i="2" since="OTP 21.2"/>
996      <name name="update_handler_config" arity="3" clause_i="3" since="OTP 21.2"/>
997      <name name="update_handler_config" arity="3" clause_i="4" since="OTP 21.2"/>
998      <name name="update_handler_config" arity="3" clause_i="5" since="OTP 21.2"/>
999      <fsummary>Add or update configuration data for the specified
1000        handler.</fsummary>
1001      <type variable="HandlerId"/>
1002      <type variable="Level" name_i="1"/>
1003      <type variable="FilterDefault" name_i="2"/>
1004      <type variable="Filters" name_i="3"/>
1005      <type variable="Formatter" name_i="4"/>
1006      <type variable="Config" name_i="5"/>
1007      <type variable="Return"/>
1008      <desc>
1009        <p>Add or update configuration data for the specified
1010          handler. If the given <c><anno>Key</anno></c> already
1011          exists, its associated value will be changed
1012          to the given value. If it does not exist, it will
1013          be added.</p>
1014	<p>If the value is incomplete, which for example can be the
1015	  case for the <c>config</c> key, it is up to the handler
1016	  implementation how the unspecified parts are set. For all
1017	  handlers in the Kernel application, unspecified data for
1018	  the <c>config</c> key is not changed. To reset unspecified
1019	  data to default values,
1020	  use <seealso marker="#set_handler_config-3">
1021	    <c>set_handler_config/3</c></seealso>.</p>
1022	<p>See the definition of
1023	  the <seealso marker="#type-handler_config">
1024	    <c>handler_config()</c></seealso> type for more
1025	  information about the different parameters.</p>
1026      </desc>
1027    </func>
1028
1029    <func>
1030      <name name="update_primary_config" arity="1" since="OTP 21.0"/>
1031      <fsummary>Update primary configuration data for Logger.</fsummary>
1032      <desc>
1033        <p>Update primary configuration data for Logger. This function
1034          behaves as if it was implemented as follows:</p>
1035	<code type="erl">
1036Old = logger:get_primary_config(),
1037logger:set_primary_config(maps:merge(Old, Config)).
1038	</code>
1039	<p>To overwrite the existing configuration without any merge,
1040	  use <seealso marker="#set_primary_config-1"><c>set_primary_config/1</c>
1041	  </seealso>.</p>
1042      </desc>
1043    </func>
1044
1045    <func>
1046      <name name="update_process_metadata" arity="1" since="OTP 21.0"/>
1047      <fsummary>Set or update metadata to use when logging from
1048	current process.</fsummary>
1049      <desc>
1050	<p>Set or update metadata to use when logging from current
1051	  process</p>
1052	<p>If process metadata exists for the current process, this
1053	  function behaves as if it was implemented as follows:</p>
1054	<code type="erl">
1055logger:set_process_metadata(maps:merge(logger:get_process_metadata(), Meta)).
1056	</code>
1057	<p>If no process metadata exists, the function behaves as
1058	  <seealso marker="#set_process_metadata-1">
1059	    <c>set_process_metadata/1</c>
1060	  </seealso>.</p>
1061      </desc>
1062    </func>
1063
1064    <func>
1065      <name name="update_proxy_config" arity="1" since="OTP 21.3"/>
1066      <fsummary>Update configuration data for the Logger proxy.</fsummary>
1067      <desc>
1068        <p>Update configuration data for the Logger proxy. This function
1069          behaves as if it was implemented as follows:</p>
1070	<code type="erl">
1071Old = logger:get_proxy_config(),
1072logger:set_proxy_config(maps:merge(Old, Config)).
1073	</code>
1074	<p>To overwrite the existing configuration without any merge,
1075	  use <seealso marker="#set_proxy_config-1"><c>set_proxy_config/1</c>
1076	  </seealso>.</p>
1077	<p>For more information about the proxy, see
1078	  section <seealso marker="logger_chapter#proxy">Logger
1079	  Proxy</seealso> in the Kernel User's Guide.</p>
1080      </desc>
1081    </func>
1082  </funcs>
1083
1084  <section>
1085    <marker id="misc_API"/>
1086    <title>Miscellaneous API functions</title>
1087  </section>
1088  <funcs>
1089    <func>
1090      <name name="compare_levels" arity="2" since="OTP 21.0"/>
1091      <fsummary>Compare the severity of two log levels.</fsummary>
1092      <desc>
1093        <p>Compare the severity of two log levels. Returns <c>gt</c>
1094          if <c>Level1</c> is more severe than
1095          <c>Level2</c>, <c>lt</c> if <c>Level1</c> is less severe,
1096          and <c>eq</c> if the levels are equal.</p>
1097      </desc>
1098    </func>
1099
1100    <func>
1101      <name name="format_report" arity="1" since="OTP 21.0"/>
1102      <fsummary>Convert a log message on report form to {Format, Args}.</fsummary>
1103      <desc>
1104        <p>Convert a log message on report form to <c>{Format,
1105	  Args}</c>. This is the default report callback used
1106	  by <seealso marker="logger_formatter">
1107	    <c>logger_formatter(3)</c></seealso> when no custom report
1108	  callback is found. See
1109	  section <seealso marker="logger_chapter#log_message">Log
1110	    Message</seealso> in the Kernel User's Guide for
1111	  information about report callbacks and valid forms of log
1112	  messages.</p>
1113	<p>The function produces lines of <c>Key: Value</c> from
1114	  key-value lists. Strings are printed with <c>~ts</c> and
1115	  other terms with <c>~tp</c>.</p>
1116	<p>If <c><anno>Report</anno></c> is a map, it is converted to
1117	  a key-value list before formatting as such.</p>
1118      </desc>
1119    </func>
1120
1121    <func>
1122      <name name="timestamp" arity="0" since="OTP 21.3"/>
1123      <fsummary>Return a timestamp to insert in meta data for a log
1124	event.</fsummary>
1125      <desc>
1126        <p>Return a timestamp that can be inserted as the <c>time</c>
1127          field in the meta data for a log event. It is produced with
1128	  <seealso marker="kernel:os#system_time-1">
1129            <c>os:system_time(microsecond)</c></seealso>.</p>
1130	<p>Notice that Logger automatically inserts a timestamp in the
1131	  meta data unless it already exists. This function is
1132	  exported for the rare case when the timestamp must be taken
1133	  at a different point in time than when the log event is
1134	  issued.</p>
1135      </desc>
1136    </func>
1137
1138  </funcs>
1139
1140  <section>
1141    <marker id="handler_callback_functions"/>
1142    <title>Handler Callback Functions</title>
1143    <p>The following functions are to be exported from a handler
1144      callback module.</p>
1145  </section>
1146
1147  <funcs>
1148    <func>
1149      <name since="OTP 21.0">HModule:adding_handler(Config1) -> {ok, Config2} | {error,
1150	Reason}</name>
1151      <fsummary>An instance of this handler is about to be added.</fsummary>
1152      <type>
1153	<v>Config1 = Config2 =
1154	  <seealso marker="#type-handler_config">handler_config()</seealso></v>
1155	<v>Reason = term()</v>
1156      </type>
1157      <desc>
1158	<p>This callback function is optional.</p>
1159	<p>The function is called on a temporary process when an new
1160	  handler is about to be added. The purpose is to verify the
1161	  configuration and initiate all resources needed by the
1162	  handler.</p>
1163	<p>The handler identity is associated with the <c>id</c> key
1164	  in <c>Config1</c>.</p>
1165	<p>If everything succeeds, the callback function can add
1166	  possible default values or internal state values to the
1167	  configuration, and return the adjusted map
1168	  in <c>{ok,Config2}</c>.</p>
1169	<p>If the configuration is faulty, or if the initiation fails,
1170	  the callback function must return <c>{error,Reason}</c>.</p>
1171      </desc>
1172    </func>
1173
1174    <func>
1175      <name since="OTP 21.2">HModule:changing_config(SetOrUpdate, OldConfig, NewConfig) -> {ok, Config} | {error, Reason}</name>
1176      <fsummary>The configuration for this handler is about to change.</fsummary>
1177      <type>
1178	<v>SetOrUpdate = set | update</v>
1179	<v>OldConfig = NewConfig = Config =
1180	  <seealso marker="#type-handler_config">handler_config()</seealso></v>
1181	<v>Reason = term()</v>
1182      </type>
1183      <desc>
1184	<p>This callback function is optional.</p>
1185	<p>The function is called on a temporary process when the
1186	  configuration for a handler is about to change. The purpose
1187	  is to verify and act on the new configuration.</p>
1188	<p><c>OldConfig</c> is the existing configuration
1189	  and <c>NewConfig</c> is the new configuration.</p>
1190	<p>The handler identity is associated with the <c>id</c> key
1191	  in <c>OldConfig</c>.</p>
1192	<p><c>SetOrUpdate</c> has the value <c>set</c> if the
1193	  configuration change originates from a call to
1194	  <seealso marker="#set_handler_config-2">
1195	    <c>set_handler_config/2,3</c></seealso>, and <c>update</c>
1196	  if it originates from <seealso marker="#update_handler_config-2">
1197	    <c>update_handler_config/2,3</c></seealso>. The handler can
1198	  use this parameteter to decide how to update the value of
1199	  the <c>config</c> field, that is, the handler specific
1200	  configuration data. Typically, if <c>SetOrUpdate</c>
1201	  equals <c>set</c>, values that are not specified must be
1202	  given their default values. If <c>SetOrUpdate</c>
1203	  equals <c>update</c>, the values found in <c>OldConfig</c>
1204	  must be used instead.</p>
1205	<p>If everything succeeds, the callback function must return a
1206	  possibly adjusted configuration in <c>{ok,Config}</c>.</p>
1207	<p>If the configuration is faulty, the callback function must
1208	  return <c>{error,Reason}</c>.</p>
1209      </desc>
1210    </func>
1211
1212    <func>
1213      <name since="OTP 21.2">HModule:filter_config(Config) -> FilteredConfig</name>
1214      <fsummary>Remove internal data from configuration.</fsummary>
1215      <type>
1216	<v>Config = FilteredConfig =
1217	  <seealso marker="#type-handler_config">handler_config()</seealso></v>
1218      </type>
1219      <desc>
1220	<p>This callback function is optional.</p>
1221	<p>The function is called when one of the Logger API functions
1222	  for fetching the handler configuration is called, for
1223	  example
1224	  <seealso marker="#get_handler_config-1">
1225	    <c>logger:get_handler_config/1</c></seealso>.</p>
1226	<p>It allows the handler to remove internal data fields from
1227	  its configuration data before it is returned to the
1228	  caller.</p>
1229      </desc>
1230    </func>
1231
1232    <func>
1233      <name since="OTP 21.0">HModule:log(LogEvent, Config) -> void()</name>
1234      <fsummary>Log the given log event.</fsummary>
1235      <type>
1236	<v>LogEvent =
1237	  <seealso marker="#type-log_event">log_event()</seealso></v>
1238	<v>Config =
1239	  <seealso marker="#type-handler_config">handler_config()</seealso></v>
1240      </type>
1241      <desc>
1242	<p>This callback function is mandatory.</p>
1243	<p>The function is called when all primary filters and all
1244	  handler filters for the handler in question have passed for
1245	  the given log event. It is called on the client process, that
1246	  is, the process that issued the log event.</p>
1247	<p>The handler identity is associated with the <c>id</c> key
1248	  in <c>Config</c>.</p>
1249	<p>The handler must log the event.</p>
1250	<p>The return value from this function is ignored by
1251	  Logger.</p>
1252      </desc>
1253    </func>
1254
1255    <func>
1256      <name since="OTP 21.0">HModule:removing_handler(Config) -> ok</name>
1257      <fsummary>The given handler is about to be removed.</fsummary>
1258      <type>
1259	<v>Config =
1260	  <seealso marker="#type-handler_config">handler_config()</seealso></v>
1261      </type>
1262      <desc>
1263	<p>This callback function is optional.</p>
1264	<p>The function is called on a temporary process when a
1265	  handler is about to be removed. The purpose is to release
1266	  all resources used by the handler.</p>
1267	<p>The handler identity is associated with the <c>id</c> key
1268	  in <c>Config</c>.</p>
1269	<p>The return value is ignored by Logger.</p>
1270      </desc>
1271    </func>
1272
1273  </funcs>
1274
1275  <section>
1276    <marker id="formatter_callback_functions"/>
1277    <title>Formatter Callback Functions</title>
1278    <p>The following functions are to be exported from a formatter
1279      callback module.</p>
1280  </section>
1281
1282  <funcs>
1283    <func>
1284      <name since="OTP 21.0">FModule:check_config(FConfig) -> ok | {error, Reason}</name>
1285      <fsummary>Validate the given formatter configuration.</fsummary>
1286      <type>
1287	<v>FConfig =
1288	  <seealso marker="#type-formatter_config">formatter_config()</seealso></v>
1289	<v>Reason = term()</v>
1290      </type>
1291      <desc>
1292	<p>This callback function is optional.</p>
1293	<p>The function is called by a Logger when formatter
1294	  configuration is set or modified. The formatter must
1295	  validate the given configuration and return <c>ok</c> if it
1296	  is correct, and <c>{error,Reason}</c> if it is faulty.</p>
1297	<p>The following Logger API functions can trigger this callback:</p>
1298	<list>
1299	  <item><seealso marker="logger#add_handler-3">
1300	      <c>logger:add_handler/3</c></seealso></item>
1301	  <item><seealso marker="logger#set_handler_config-2">
1302	      <c>logger:set_handler_config/2,3</c></seealso></item>
1303	  <item><seealso marker="logger#update_handler_config-2">
1304	      <c>logger:update_handler_config/2,3</c></seealso></item>
1305	  <item><seealso marker="logger#update_formatter_config-2">
1306	      <c>logger:update_formatter_config/2</c></seealso></item>
1307	</list>
1308	<p>See <seealso marker="logger_formatter">
1309	    <c>logger_formatter(3)</c></seealso>
1310	  for an example implementation. <c>logger_formatter</c> is the
1311	  default formatter used by Logger.</p>
1312      </desc>
1313    </func>
1314    <func>
1315      <name since="OTP 21.0">FModule:format(LogEvent, FConfig) -> FormattedLogEntry</name>
1316      <fsummary>Format the given log event.</fsummary>
1317      <type>
1318	<v>LogEvent =
1319	  <seealso marker="#type-log_event">log_event()</seealso></v>
1320	<v>FConfig =
1321	  <seealso marker="#type-formatter_config">formatter_config()</seealso></v>
1322	<v>FormattedLogEntry =
1323	  <seealso marker="unicode#type-chardata">unicode:chardata()</seealso></v>
1324      </type>
1325      <desc>
1326	<p>This callback function is mandatory.</p>
1327	<p>The function can be called by a log handler to convert a
1328	  log event term to a printable string. The returned value
1329	  can, for example, be printed as a log entry to the console
1330	  or a file using <seealso marker="stdlib:io#put_chars-1">
1331	    <c>io:put_chars/1,2</c></seealso>.</p>
1332	<p>See <seealso marker="logger_formatter">
1333	    <c>logger_formatter(3)</c></seealso>
1334	  for an example implementation. <c>logger_formatter</c> is the
1335	  default formatter used by Logger.</p>
1336      </desc>
1337    </func>
1338  </funcs>
1339
1340  <section>
1341    <title>See Also</title>
1342    <p>
1343      <seealso marker="config"><c>config(4)</c></seealso>,
1344      <seealso marker="erts:erlang"><c>erlang(3)</c></seealso>,
1345      <seealso marker="stdlib:io"><c>io(3)</c></seealso>,
1346      <seealso marker="logger_disk_log_h"><c>logger_disk_log_h(3)</c></seealso>,
1347      <seealso marker="logger_filters"><c>logger_filters(3)</c></seealso>,
1348      <seealso marker="logger_formatter"><c>logger_formatter(3)</c></seealso>,
1349      <seealso marker="logger_std_h"><c>logger_std_h(3)</c></seealso>,
1350      <seealso marker="stdlib:unicode"><c>unicode(3)</c></seealso>
1351    </p>
1352  </section>
1353</erlref>
1354