1logger_std_h(3)            Erlang Module Definition            logger_std_h(3)
2
3
4

NAME

6       logger_std_h - Standard handler for Logger.
7

DESCRIPTION

9       This  is  the  standard  handler for Logger. Multiple instances of this
10       handler can be added to Logger, and each instance prints logs to  stan‐
11       dard_io, standard_error, or to file.
12
13       The handler has an overload protection mechanism that keeps the handler
14       process and the Kernel application  alive  during  high  loads  of  log
15       events.  How overload protection works, and how to configure it, is de‐
16       scribed in the User's Guide.
17
18       To add a new instance of  the  standard  handler,  use  logger:add_han‐
19       dler/3.  The  handler configuration argument is a map which can contain
20       general configuration parameters, as documented in  the  User's  Guide,
21       and  handler  specific parameters. The specific data is stored in a sub
22       map with the key config, and can contain the following parameters:
23
24         type = io:standard_io()  |  io:standard_error()  |  file  |  {device,
25         io:device()}:
26           Specifies the log destination.
27
28           The  value  is  set  when  the  handler  is added, and it cannot be
29           changed in runtime.
30
31           Defaults to standard_io, unless parameter file is given,  in  which
32           case it defaults to file.
33
34         file = file:filename():
35           This specifies the name of the log file when the handler is of type
36           file.
37
38           The value is set when the  handler  is  added,  and  it  cannot  be
39           changed in runtime.
40
41           Defaults  to  the same name as the handler identity, in the current
42           directory.
43
44         modes = [file:mode()]:
45           This specifies the file modes to use when opening the log file, see
46           file:open/2.  If  modes are not specified, the default list used is
47           [raw,append,delayed_write]. If modes are specified,  the  list  re‐
48           places the default modes list with the following adjustments:
49
50           *
51              If raw is not found in the list, it is added.
52
53           *
54              If  none of write, append or exclusive is found in the list, ap‐
55             pend is added.
56
57           * If none of delayed_write or {delayed_write,Size,Delay}  is  found
58             in the list, delayed_write is added.
59
60           Log  files are always UTF-8 encoded. The encoding cannot be changed
61           by setting the mode {encoding,Encoding}.
62
63           The value is set when the  handler  is  added,  and  it  cannot  be
64           changed in runtime.
65
66           Defaults to [raw,append,delayed_write].
67
68         max_no_bytes = pos_integer() | infinity:
69           This  parameter specifies if the log file should be rotated or not.
70           The value infinity means the log file will grow indefinitely, while
71           an  integer  value specifies at which file size (bytes) the file is
72           rotated.
73
74           Defaults to infinity.
75
76         max_no_files = non_neg_integer():
77           This parameter specifies the number of rotated log file archives to
78           keep.  This  has  meaning only if max_no_bytes is set to an integer
79           value.
80
81           The log archives are named FileName.0, FileName.1, ...  FileName.N,
82           where  FileName  is the name of the current log file. FileName.0 is
83           the newest of the archives. The maximum value for N is the value of
84           max_no_files minus 1.
85
86           Notice  that setting this value to 0 does not turn off rotation. It
87           only specifies that no archives are kept.
88
89           Defaults to 0.
90
91         compress_on_rotate = boolean():
92           This parameter specifies if the rotated log file archives shall  be
93           compressed or not. If set to true, all archives are compressed with
94           gzip, and renamed to FileName.N.gz
95
96           compress_on_rotate has no meaning if max_no_bytes has the value in‐
97           finity.
98
99           Defaults to false.
100
101         file_check = non_neg_integer():
102           When  logger_std_h logs to a file, it reads the file information of
103           the log file prior to each write operation. This is  to  make  sure
104           the file still exists and has the same inode as when it was opened.
105           This implies some performance loss, but ensures that no log  events
106           are  lost  in the case when the file has been removed or renamed by
107           an external actor.
108
109           In order to allow minimizing the performance loss,  the  file_check
110           parameter  can  be  set to a positive integer value, N. The handler
111           will then skip reading the file information prior  to  writing,  as
112           long  as  no more than N milliseconds have passed since it was last
113           read.
114
115           Notice that the risk of losing log events grows when the file_check
116           value grows.
117
118           Defaults to 0.
119
120         filesync_repeat_interval = pos_integer() | no_repeat:
121           This value, in milliseconds, specifies how often the handler does a
122           file sync operation to write buffered data to disk. The handler at‐
123           tempts  the  operation  repeatedly, but only performs a new sync if
124           something has actually been logged.
125
126           If no_repeat is set as value, the repeated file sync  operation  is
127           disabled,  and  it  is the operating system settings that determine
128           how quickly or slowly data is written to disk. The  user  can  also
129           call the filesync/1 function to perform a file sync.
130
131           Defaults to 5000 milliseconds.
132
133       Other  configuration  parameters  exist, to be used for customizing the
134       overload protection behaviour. The same parameters are used both in the
135       standard  handler  and  the disk_log handler, and are documented in the
136       User's Guide.
137
138       Notice that if changing the configuration of the  handler  in  runtime,
139       the type, file, or modes parameters must not be modified.
140
141       Example of adding a standard handler:
142
143       logger:add_handler(my_standard_h, logger_std_h,
144                          #{config => #{file => "./system_info.log",
145                                        filesync_repeat_interval => 1000}}).
146
147
148       To  set  the default handler, that starts initially with the Kernel ap‐
149       plication, to log to file instead of standard_io, change the Kernel de‐
150       fault logger configuration. Example:
151
152       erl -kernel logger '[{handler,default,logger_std_h,
153                             #{config => #{file => "./log.log"}}}]'
154
155
156       An  example of how to replace the standard handler with a disk_log han‐
157       dler at startup is found in the logger_disk_log_h manual.
158

EXPORTS

160       filesync(Name) -> ok | {error, Reason}
161
162              Types:
163
164                 Name = atom()
165                 Reason = handler_busy | {badarg, term()}
166
167              Write buffered data to disk.
168

SEE ALSO

170       logger(3), logger_disk_log_h(3)
171
172
173
174Ericsson AB                       kernel 9.1                   logger_std_h(3)
Impressum