1 .\" Copyright 2002 walter harms (walter.harms@informatik.uni-oldenburg.de)
3 .\" %%%LICENSE_START(GPL_NOVERSION_ONELINE)
4 .\" Distributed under GPL
7 .\" adapted glibc info page
9 .\" This should run as 'Guru Meditation' (amiga joke :)
10 .\" The function is quite complex and deserves an example
12 .\" Polished, aeb, 2003-11-01
13 .TH FMTMSG 3 2021-03-22 "" "Linux Programmer's Manual"
15 fmtmsg \- print formatted error messages
18 .B #include <fmtmsg.h>
20 .BI "int fmtmsg(long " classification ", const char *" label ,
21 .BI " int " severity ", const char *" text ,
22 .BI " const char *" action ", const char *" tag );
25 This function displays a message described by its arguments on the device(s)
29 For messages written to
31 the format depends on the
37 argument identifies the source of the message.
38 The string must consist
39 of two colon separated parts where the first part has not more
40 than 10 and the second part not more than 14 characters.
44 argument describes the condition of the error.
48 argument describes possible steps to recover from the error.
49 If it is printed, it is prefixed by "TO FIX: ".
53 argument is a reference to the online documentation where more
54 information can be found.
57 value and a unique identification number.
59 Each of the arguments can have a dummy value.
60 The dummy classification value
62 (0L) does not specify any output, so nothing is printed.
63 The dummy severity value
65 (0) says that no severity is supplied.
72 .IR "((char\ *)\ 0)" ,
77 .SS The classification argument
80 argument is the sum of values describing 4 types of information.
82 The first value defines the output channel.
89 Output to the system console.
91 .B "MM_PRINT | MM_CONSOLE"
94 The second value is the source of the error:
97 A hardware error occurred.
100 A firmware error occurred.
103 A software error occurred.
105 The third value encodes the detector of the problem:
108 It is detected by an application.
111 It is detected by a utility.
114 It is detected by the operating system.
116 The fourth value shows the severity of the incident:
119 It is a recoverable error.
122 It is a nonrecoverable error.
123 .SS The severity argument
126 argument can take one of the following values:
129 No severity is printed.
132 This value is printed as HALT.
135 This value is printed as ERROR.
138 This value is printed as WARNING.
141 This value is printed as INFO.
143 The numeric values are between 0 and 4.
146 or the environment variable
148 you can add more levels and strings to print.
150 The function can return 4 values:
153 Everything went smooth.
163 Error writing to the console.
165 The environment variable
167 ("message verbosity") can be used to suppress parts of
170 (It does not influence output to the console.)
171 When this variable is defined, is non-NULL, and is a colon-separated
172 list of valid keywords, then only the parts of the message corresponding
173 to these keywords is printed.
174 Valid keywords are "label", "severity", "text", "action", and "tag".
176 The environment variable
178 can be used to introduce new severity levels.
179 By default, only the five severity levels described
181 Any other numeric value would make
189 SEV_LEVEL=[description[:description[:...]]]
192 in the environment of the process before the first call to
194 where each description is of the form
197 severity-keyword,level,printstring
202 will also accept the indicated values for the level (in addition to
203 the standard levels 0\(en4), and use the indicated printstring when
206 The severity-keyword part is not used by
208 but it has to be present.
209 The level part is a string representation of a number.
210 The numeric value must be a number greater than 4.
211 This value must be used in the severity argument of
213 to select this class.
214 It is not possible to overwrite
215 any of the predefined classes.
217 is the string printed when a message of this class is processed by
221 is provided in glibc since version 2.1.
223 For an explanation of the terms used in this section, see
231 Interface Attribute Value
235 glibc\ >=\ 2.16: MT-Safe;
236 glibc\ <\ 2.16: MT-Unsafe
243 Before glibc 2.16, the
245 function uses a static variable that is not protected,
246 so it is not thread-safe.
249 .\" Modified in commit 7724defcf8873116fe4efab256596861eef21a94
252 function uses a lock to protect the static variable, so it is thread-safe.
258 and environment variables
266 and the environment variable
268 are described in POSIX.1-2001 and POSIX.1-2008.
270 System V and UnixWare man pages tell us that these functions
271 have been replaced by "pfmt() and addsev()" or by "pfmt(),
272 vpfmt(), lfmt(), and vlfmt()", and will be removed later.
282 long class = MM_PRINT | MM_SOFT | MM_OPSYS | MM_RECOVER;
285 err = fmtmsg(class, "util\-linux:mount", MM_ERROR,
286 "unknown mount option", "See mount(8).",
287 "util\-linux:mount:017");
292 printf("Nothing printed\en");
295 printf("Nothing printed to stderr\en");
298 printf("No console output\en");
301 printf("Unknown error from fmtmsg()\en");
307 The output should be:
311 util\-linux:mount: ERROR: unknown mount option
312 TO FIX: See mount(8). util\-linux:mount:017
320 MSGVERB=text:action; export MSGVERB
329 TO FIX: See mount(8).