Skip to content

Commit

Permalink
log_custom: print to stderror if sending log message fails
Browse files Browse the repository at this point in the history
- help troubleshooting while avoiding looping to same function in case
the log engine is set to log custom module
  • Loading branch information
miconda committed Aug 24, 2020
1 parent a9a8aa2 commit f16d046
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/modules/log_custom/log_custom_mod.c
Expand Up @@ -139,15 +139,19 @@ void _lc_core_log_udp(int lpriority, const char *format, ...)
va_list arglist;
char obuf[LC_LOG_MSG_MAX_SIZE];
int n;
int r;

va_start(arglist, format);

n = 0;
n += snprintf(obuf + n, LC_LOG_MSG_MAX_SIZE - n, "(%d) ", my_pid());
n += vsnprintf(obuf + n, LC_LOG_MSG_MAX_SIZE - n, format, arglist);
va_end(arglist);
if(udp_send(&_lc_udp_dst, obuf, n)!=0) {
udp_send(&_lc_udp_dst, "debug: previous udp send returned non zero\n", 43);
r = udp_send(&_lc_udp_dst, obuf, n);
if(r<0) {
/* sending log message failed - print to stderror to help debugging */
fprintf(stderr, "error: previous udp send returned failure (%d:%d:%s)\n",
r, errno, strerror(errno));
}
}

Expand All @@ -160,9 +164,9 @@ int ki_log_udp(sip_msg_t *msg, str *txt)

ret=udp_send(&_lc_udp_dst, txt->s, txt->len);

if(ret==0) return 1;
if(ret>0) return 1;

return ret;
return (ret==0)?-1:ret;

}

Expand Down

0 comments on commit f16d046

Please sign in to comment.