qlibs:(logmsg)
π¦ qlibs manual: logmsg π¦
β¨ NAME β¨
logmsg β handle system errors and application log messages π
πΈ SYNTAX πΈ
#include "logmsg.h"
int logmsg(const char *who, int ecode, unsigned int classs, char *msg)
err_sys(w,e) logmsg(w,e,FATAL,"")
err_sys_plus(w,e,m) logmsg(w,e,FATAL,m)
err_tmp(w,e) logmsg(w,e,WARN,"")
err_tmp_plus(w,e,m) logmsg(w,e,WARN,m)
err_int(w,e,c) logmsg(w,e,c,"")
err_int_plus(w,e,c,m) logmsg(w,e,c,m)
log_who(w,m) logmsg(w,0,LOG,m)
log_anon(m) logmsg("",0,LOG,m)
π DESCRIPTION π
Okay so bestie, logmsg prints error, warning, or info/logging messages to stderr, and it may literally terminate the calling program depending on the class you give it π
- who is the name of the program
- ecode is an error code
- class determines the behavior upon call
- msg is the logging message
Read "error.h" to learn more about related constants πβ¨
π ECODE π
ecode is the error code, and itβs subject to be displayed in the log file and potentially used upon exit if the class equals ERROR, FATAL, or DROP π
To avoid conflicts with syscall error codes, application-defined error codes should be negative. The values -15, -100 and -111 are reserved for backward compatibility π«Ά
π CLASS π
The class parameter indicates how the application handles exceptions and displays the log message. Vibe check:
LOG,INFO,ALERT,WARNβ display message and continue operation β¨DROPβ display warning message and continue while returning to the calling program πUSAGE,SYNTAX,FATAL,ERRORβ display error message and exit application with error code π₯
INFO, ALERT, WARN, DROP, USAGE, and FATAL as well as ERROR display the respective class string like warning: 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 error/warning. Periodt π
π MESSAGE π
If the custom message msg is given, it will be printed additionally π¬
π§ FORMAT π§
The log message format consists of the tokens who: (ecode) msg : msg πͺ
ecode is displayed only for classes FATAL, ERROR, or DROP. msg is the systemβs explanation according to the variable errno if provided πΈ
π NOTES π
logmsg.c uses errstr.c routines. Error codes and classes are defined in error.h and included by logmsg.h πβ¨
π₯ EXIT CODE π₯
logmsg exits ecode for classes ERROR, FATAL, SYNTAX, and USAGE, terminating the application π΅βπ«
π¦ HISTORY π¦
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 π
π EXAMPLES π
The macro definitions uses w for the calling program, e for error code, c for class, and m for message.
#include "logmsg.h"
#define WHO "my_prog"
err_sys(WHO,errno);
err_sys_plus(WHO,-111,"additional message");
err_tmp("",-100);
err_tmp_plus("",errno,"additional message");
log_who(WHO,"message");
log_anon() is like log_who() but doesnβt print the caller name π
A 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));
π SEE ALSO π
okay bye bestie π this is section 3 of the qlibs manual, the (logmsg) page β mwah, slay, and happy logging β¨π
π¦ where this page comes from
- alpine 3.24: fehqlibs-doc 31-r0 Β· Public-Domain
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms