@@ -190,6 +190,52 @@ PJ_DECL(pj_str_t) pj_strerror( pj_status_t statcode,
190190 pj_perror_wrapper_##level(arg); \
191191 } while (0)
192192
193+ /**
194+ * A utility macro to print error message pertaining to the specified error
195+ * code to the log. This macro will construct the error message title
196+ * according to the 'title_fmt' argument, and add the error string pertaining
197+ * to the error code after the title string. A colon (':') will be added
198+ * automatically between the title and the error string.
199+ *
200+ * This function is similar to pj_perror() function, but has the advantage
201+ * that the function call can be omitted from the link process if the
202+ * log level argument is below PJ_LOG_MAX_LEVEL threshold.
203+ *
204+ * Note that the title string constructed from the title_fmt will be built on
205+ * a string buffer which size is PJ_PERROR_TITLE_BUF_SIZE, which normally is
206+ * allocated from the stack. By default this buffer size is small (around
207+ * 120 characters). Application MUST ensure that the constructed title string
208+ * will not exceed this limit, since not all platforms support truncating
209+ * the string.
210+ *
211+ * @see pj_perror()
212+ *
213+ * @param LVL The logging verbosity level, valid values are 0-6. Lower
214+ * number indicates higher importance, with level zero
215+ * indicates fatal error. Variable argument is not permitted,
216+ * the argument may be a numeral constant or a numeral value
217+ * macros.
218+ * @param arg Enclosed 'printf' like arguments, with the following
219+ * arguments:
220+ * @param sender the sender (NULL terminated string),
221+ * @param status the error code (pj_status_t)
222+ * @param title_fmt the printf style format string, and optional variable
223+ * number of arguments suitable for the format string.
224+ *
225+ * Sample:
226+ * \verbatim
227+ #ifdef PJ_DEBUG
228+ # define MY_ERROR_LEVEL 1
229+ #else
230+ # define MY_ERROR_LEVEL 2
231+ #endif
232+ PJ_PERROR_(MY_ERROR_LEVEL, __FILE__, PJ_EBUSY, "Error making %s", "coffee");
233+ \endverbatim
234+ * @hideinitializer
235+ */
236+ #define PJ_PERROR_ (LVL , sender , status , title_fmt , ...) \
237+ PJ_PERROR(LVL,(sender,status,title_fmt, __VA_ARGS__))
238+
193239/**
194240 * A utility function to print error message pertaining to the specified error
195241 * code to the log. This function will construct the error message title
@@ -213,7 +259,7 @@ PJ_DECL(pj_str_t) pj_strerror( pj_status_t statcode,
213259 * @see PJ_PERROR()
214260 */
215261PJ_DECL (void ) pj_perror (int log_level , const char * sender , pj_status_t status ,
216- const char * title_fmt , ...)
262+ PJ_PRINT_PARAM_DECOR const char * title_fmt , ...)
217263 PJ_PRINT_FUNC_DECOR (4 );
218264
219265
@@ -512,7 +558,7 @@ void pj_errno_clear_handlers(void);
512558 #define pj_perror_wrapper_1 (arg ) pj_perror_1 arg
513559 /** Internal function. */
514560 PJ_DECL (void ) pj_perror_1 (const char * sender , pj_status_t status ,
515- const char * title_fmt , ...)
561+ PJ_PRINT_PARAM_DECOR const char * title_fmt , ...)
516562 PJ_PRINT_FUNC_DECOR (3 );
517563#else
518564 #define pj_perror_wrapper_1 (arg )
@@ -528,7 +574,7 @@ void pj_errno_clear_handlers(void);
528574 #define pj_perror_wrapper_2 (arg ) pj_perror_2 arg
529575 /** Internal function. */
530576 PJ_DECL (void ) pj_perror_2 (const char * sender , pj_status_t status ,
531- const char * title_fmt , ...)
577+ PJ_PRINT_PARAM_DECOR const char * title_fmt , ...)
532578 PJ_PRINT_FUNC_DECOR (3 );
533579#else
534580 #define pj_perror_wrapper_2 (arg )
@@ -544,7 +590,7 @@ void pj_errno_clear_handlers(void);
544590 #define pj_perror_wrapper_3 (arg ) pj_perror_3 arg
545591 /** Internal function. */
546592 PJ_DECL (void ) pj_perror_3 (const char * sender , pj_status_t status ,
547- const char * title_fmt , ...)
593+ PJ_PRINT_PARAM_DECOR const char * title_fmt , ...)
548594 PJ_PRINT_FUNC_DECOR (3 );
549595#else
550596 #define pj_perror_wrapper_3 (arg )
@@ -560,7 +606,7 @@ void pj_errno_clear_handlers(void);
560606 #define pj_perror_wrapper_4 (arg ) pj_perror_4 arg
561607 /** Internal function. */
562608 PJ_DECL (void ) pj_perror_4 (const char * sender , pj_status_t status ,
563- const char * title_fmt , ...)
609+ PJ_PRINT_PARAM_DECOR const char * title_fmt , ...)
564610 PJ_PRINT_FUNC_DECOR (3 );
565611#else
566612 #define pj_perror_wrapper_4 (arg )
@@ -576,7 +622,7 @@ void pj_errno_clear_handlers(void);
576622 #define pj_perror_wrapper_5 (arg ) pj_perror_5 arg
577623 /** Internal function. */
578624 PJ_DECL (void ) pj_perror_5 (const char * sender , pj_status_t status ,
579- const char * title_fmt , ...)
625+ PJ_PRINT_PARAM_DECOR const char * title_fmt , ...)
580626 PJ_PRINT_FUNC_DECOR (3 );
581627#else
582628 #define pj_perror_wrapper_5 (arg )
@@ -592,7 +638,7 @@ void pj_errno_clear_handlers(void);
592638 #define pj_perror_wrapper_6 (arg ) pj_perror_6 arg
593639 /** Internal function. */
594640 PJ_DECL (void ) pj_perror_6 (const char * sender , pj_status_t status ,
595- const char * title_fmt , ...)
641+ PJ_PRINT_PARAM_DECOR const char * title_fmt , ...)
596642 PJ_PRINT_FUNC_DECOR (3 );
597643#else
598644 #define pj_perror_wrapper_6 (arg )
0 commit comments