From 2053af19e76b9c13e8bdebb13669cf915dc49981 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Sun, 25 Oct 2009 08:46:40 +0000 Subject: Ticket #981: new pj_perror() utility API git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@2965 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib/include/pj/errno.h | 21 +++++++++++++++++++++ pjlib/src/pj/errno.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/pjlib/include/pj/errno.h b/pjlib/include/pj/errno.h index 07cdcf8a..8b536c40 100644 --- a/pjlib/include/pj/errno.h +++ b/pjlib/include/pj/errno.h @@ -111,6 +111,27 @@ PJ_DECL(void) pj_set_netos_error(pj_status_t code); PJ_DECL(pj_str_t) pj_strerror( pj_status_t statcode, char *buf, pj_size_t bufsize); +/** + * Print the error message pertaining to the specified error code to + * the log. + * + * @param log_level The log will be printed at this log level. + * @param sender The log sender string. + * @param status The error code which error message will be printed. + * @param title String to be printed before the error message. Note + * that a colon will be added automatically between + * this string and the error message. + * @param options Options, currently must be zero. + */ +#if PJ_LOG_MAX_LEVEL >= 1 +PJ_DECL(void) pj_perror(int log_level, const char *sender, + pj_status_t status, const char *title, + int options); +#else +# define pj_perror(level, sender, status, title, options) +#endif /* #if PJ_LOG_MAX_LEVEL >= 1 */ + + /** * Type of callback to be specified in #pj_register_strerror() * diff --git a/pjlib/src/pj/errno.c b/pjlib/src/pj/errno.c index 9aca83de..652b8099 100644 --- a/pjlib/src/pj/errno.c +++ b/pjlib/src/pj/errno.c @@ -18,8 +18,10 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include +#include #include #include +#include #include /* Prototype for platform specific error message, which will be defined @@ -196,3 +198,30 @@ PJ_DEF(pj_str_t) pj_strerror( pj_status_t statcode, return errstr; } +#if PJ_LOG_MAX_LEVEL >= 1 +static void call_logger(const char *sender, int level, const char *format, ...) +{ + va_list arg; + va_start(arg, format); + pj_log(sender, level, format, arg); + va_end(arg); +} + +/* + * perror() + */ +PJ_DEF(void) pj_perror(int log_level, const char *sender, + pj_status_t status, const char *title, + int options) +{ + char errmsg[PJ_ERR_MSG_SIZE]; + + PJ_ASSERT_ON_FAIL(options==0, return); + PJ_UNUSED_ARG(options); + + pj_strerror(status, errmsg, sizeof(errmsg)); + call_logger(sender, log_level, "%s: %s", title, errmsg); +} +#endif /* #if PJ_LOG_MAX_LEVEL >= 1 */ + + -- cgit v1.2.3