[Patch] Improve logging function
Jacek Raczkiewicz <[email protected]>
| Newsgroups | gmane.comp.mobile.kannel.devel |
|---|---|
| Message-ID | <CABsGpit9OeU91SNRtT0wSuk+1JS5KqVyrKZatHtaFOdDoX0OiA@mail.gmail.com> |
Hi, I have been working on imrpving application that uses a lot libraries from kannel/gwlib. I noticed that logging function does format the string even if there is no intention to save it to the log due to configured log level. My improvement is that I moved the format() function inside the conditional block which check for log level. This really make a difference when logged string is large (in our case it may be as big as 1MB) and that is formatted for no reason. Please include this fix into kannel codebase. Regards Jacek Raczkiewicz
logging.diff
(application/octet-stream, 2.6 KB)
*** kannel_fromSVN/gwlib/log.c 2013-10-02 11:02:28.288291416 -0400
--- kannel/gwlib/log.c 2013-10-02 11:40:08.369745312 -0400
***************
*** 511,528 ****
char buf[FORMAT_SIZE]; \
va_list args; \
\
- format(buf, level, place, err, fmt, 1); \
- gw_rwlock_rdlock(&rwlock); \
for (i = 0; i < num_logfiles; ++i) { \
if (logfiles[i].exclusive == GW_NON_EXCL && \
level >= logfiles[i].minimum_output_level && \
logfiles[i].file != NULL) { \
va_start(args, fmt); \
output(logfiles[i].file, buf, args); \
va_end(args); \
} \
} \
- gw_rwlock_unlock(&rwlock); \
if (dosyslog) { \
format(buf, level, place, err, fmt, 0); \
va_start(args, fmt); \
--- 513,530 ----
char buf[FORMAT_SIZE]; \
va_list args; \
\
for (i = 0; i < num_logfiles; ++i) { \
if (logfiles[i].exclusive == GW_NON_EXCL && \
level >= logfiles[i].minimum_output_level && \
logfiles[i].file != NULL) { \
+ format(buf, level, place, err, fmt, 1); \
+ gw_rwlock_rdlock(&rwlock); \
va_start(args, fmt); \
output(logfiles[i].file, buf, args); \
va_end(args); \
+ gw_rwlock_unlock(&rwlock); \
} \
} \
if (dosyslog) { \
format(buf, level, place, err, fmt, 0); \
va_start(args, fmt); \
***************
*** 536,551 ****
char buf[FORMAT_SIZE]; \
va_list args; \
\
- format(buf, level, place, err, fmt, 1); \
- gw_rwlock_rdlock(&rwlock); \
if (logfiles[e].exclusive == GW_EXCL && \
level >= logfiles[e].minimum_output_level && \
logfiles[e].file != NULL) { \
va_start(args, fmt); \
output(logfiles[e].file, buf, args); \
va_end(args); \
} \
- gw_rwlock_unlock(&rwlock); \
} while (0)
--- 538,553 ----
char buf[FORMAT_SIZE]; \
va_list args; \
\
if (logfiles[e].exclusive == GW_EXCL && \
level >= logfiles[e].minimum_output_level && \
logfiles[e].file != NULL) { \
+ format(buf, level, place, err, fmt, 1); \
+ gw_rwlock_rdlock(&rwlock); \
va_start(args, fmt); \
output(logfiles[e].file, buf, args); \
va_end(args); \
+ gw_rwlock_unlock(&rwlock); \
} \
} while (0)