|
|
#include <pfmt.h>int lfmt(FILE stream, long flags, char format, . . . / args /);
#include <stdarg.h> #include <pfmt.h>
int vlfmt(FILE stream, long flags, char format, va_list ap);
lfmt forwards its output to the logging and monitoring facility, even if stream is null. lfmt will also display the output on the console, with a date and time stamp, when MM_CONSOLE is specified (see below).
If the printf format string is to be retrieved from a message database, the format argument must have the following structure:
[catalog:]msgnum:defmsg.
If MM_NOGET is specified, only the defmsg part must be specified.
catalog indicates the message database that contains the localized version of the format string. catalog must be limited to 14 characters. These characters must be selected from a set of all character values, excluding \0 (null) and the ASCII codes for / (slash) and ``:'' (colon).
msgnum must be a positive number that indicates the index of the string into the message database.
If catalog does not exist in the locale (specified by the last call to setlocale using the LC_ALL or LC_MESSAGES categories), or if the message number is out of bounds, lfmt attempts to retrieve the message from the C locale. If this second retrieval fails, lfmt uses the defmsg part of the format argument.
If catalog is omitted, lfmt attempts to retrieve the string from the default catalog specified by the last call to setcat. In this case, the format argument has the following structure:
msgnum:defmsg.
lfmt outputs
Message not found!!\n
as the format string if:
The flags determine the type of output (that is, whether the format should be interpreted as is or encapsulated in the standard message format), and the access to message catalogs to retrieve a localized version of format. The flags are composed of several groups, and can take the following values (one from each group):
Additional severities can be defined. Add-on severities can be defined with number-string pairs with numeric values from the range [5-255], using addsev(3C). The numeric value ORed with other flags will generate the specified severity.
If the severity is not defined, lfmt uses the string SEV=N where N is replaced by the integer severity value passed in flags.
Multiple severities passed in flags will not be detected as an error.
Any combination of severities will be summed and the numeric value will cause
the display of either a severity string (if defined) or the string
SEV=N (if undefined).
label: severity: text
If no label was defined by a call to setlabel, the message is displayed in the format:
severity: text
If lfmt is called twice to display an error message and a helpful action or recovery message, the output can look like:
label: severity: text label: TO FIX: text
The stdarg.h header file defines the type va_list and a set of macros for advancing through a list of arguments whose number and types may vary. The argument ap to vlfmt is of type va_list. This argument is used with the stdarg.h header file macros va_start, va_arg and va_end [see va_start, va_arg, and va_end in stdarg(5)]. The USAGE section below show their use.
The macro va_alist is used as the parameter list in a function definition as in the function called error in the example below. The macro
va_start(ap, )
where ap is of type va_list, must be called before any attempt to traverse and access unnamed arguments. Calls to
va_arg(ap, atype)
traverse the argument
list.
Each execution of va_arg expands to an expression with the
value and type of the next argument in the list ap,
which is the same object initialized by va_start.
The argument atype is the type that the returned argument is
expected to be.
The va_end(ap) macro must be invoked when all
desired arguments have been accessed.
[The argument list in ap can be traversed again if va_start
is called again after va_end.]
In the example below, va_arg is executed first to
retrieve the
format string passed to error.
The remaining error arguments,
arg1,
arg2, . . .,
are given to vlfmt in the argument ap.
displays the message to ``stderr'' and to the console and makes it available for logging:
UX:test: ERROR: Cannot open file: No such file or directory
displays the message to ``stderr'' and makes it available for logging:
UX:test: INFO: test facility enabled
#include <pfmt.h> #include <stdarg.h> . . . / errlog should be called like errlog(log_info, format, arg1, ...); / void errlog(long log_info, const char format, ...){ va_list ap;
va_start(ap, format); (void) vlfmt(stderr, log_info|MM_ERROR, format, ap); va_end(ap); (void) abort(); }