int logmsg(char *who, int ecode, unsigned int classs, char *msg)
logmsg prints error, warning, or info/logging messages to stderr and
potentially terminates the calling program, depending on the class
given. who is the name of the program, ecode is an error code, class
determines the behavior upon call and msg is the logging message. Read
"error.h" to learn related constants.
ecode is the error code and subject to be displayed in the log file and
potentially used upon exit in case the class equals FATAL or DROP.
To avoid conflicts with syscall error codes, appplication defined error
codes should be negative. The values -15, -100 and -111 are reserved
for backwards compatibility.
The class parameter indicates how the application handles exceptions
and displays the log message.
o LOG, INFO, WARN - display message and continue operation
o DROP - display warning message and continue while going to the
o USAGE, SYNTAX, FATAL, ERROR - display error message and exit
application with error code
INFO, WARN, DROP, USAGE, and FATAL as well as ERROR display the
respective class string like warn: in the log message, while LOG shows
the log message only.
The class FATAL should be used for system error codes only, rather
ERROR and WARN shall be set in conjunction with an application
If the custom message msg is given, it will be printed additionally.
The log message format consists of the tokens who: (ecode) msg :
errmsg. ecode is displayed only for classes FATAL, ERROR, or DROP.
errmsg is the system's explanation according to the variable errno if
logmsg.c uses errstr.c routines. Error codes and classes are defined
in error.h and included by logmsg.h.
logmsg exits ecode for classes ERROR, FATAL, SYNTAX, and USAGE
terminating the application.
Dan Bernstein used sets of strerr_dieY*() and strerr_warnY() messages
which explicitely determine the message and behavior class. Other
classes were occasionally defined on demand, such als usage().
Kai Peter introduced the errmsg facility in his qlibs including a
syslog compliant severity as second parameter.
The macro definitions uses w for the calling program, e for error
code, c for class and m for message.
#define WHO "my_prog"
log_anon() is like log() but doesn't print the caller name.
An user defined message s can be build from multiple arguments by using
the B (build) macro:
err_sys_plus((errno),B("unable to run: ",*argv));
Man(1) output converted with