logging.c: since log level is a mask, do not compare with == operator but & instead

parent 16848a37
/* /*
The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack. The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack.
Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version. version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details. Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
...@@ -31,8 +31,8 @@ static OList *__log_stored_messages_list = NULL; ...@@ -31,8 +31,8 @@ static OList *__log_stored_messages_list = NULL;
static ortp_mutex_t __log_stored_messages_mutex; static ortp_mutex_t __log_stored_messages_mutex;
/** /**
*@param file a FILE pointer where to output the ortp logs. *@param file a FILE pointer where to output the ortp logs.
* *
**/ **/
void ortp_set_log_file(FILE *file) void ortp_set_log_file(FILE *file)
{ {
...@@ -44,8 +44,8 @@ static void __ortp_logv_out(OrtpLogLevel lev, const char *fmt, va_list args); ...@@ -44,8 +44,8 @@ static void __ortp_logv_out(OrtpLogLevel lev, const char *fmt, va_list args);
OrtpLogFunc ortp_logv_out=__ortp_logv_out; OrtpLogFunc ortp_logv_out=__ortp_logv_out;
/** /**
*@param func: your logging function, compatible with the OrtpLogFunc prototype. *@param func: your logging function, compatible with the OrtpLogFunc prototype.
* *
**/ **/
void ortp_set_log_handler(OrtpLogFunc func){ void ortp_set_log_handler(OrtpLogFunc func){
ortp_logv_out=func; ortp_logv_out=func;
...@@ -58,8 +58,8 @@ OrtpLogFunc ortp_get_log_handler(){ ...@@ -58,8 +58,8 @@ OrtpLogFunc ortp_get_log_handler(){
static unsigned int __ortp_log_mask=ORTP_WARNING|ORTP_ERROR|ORTP_FATAL; static unsigned int __ortp_log_mask=ORTP_WARNING|ORTP_ERROR|ORTP_FATAL;
/** /**
* @ param levelmask a mask of ORTP_DEBUG, ORTP_MESSAGE, ORTP_WARNING, ORTP_ERROR * @ param levelmask a mask of ORTP_DEBUG, ORTP_MESSAGE, ORTP_WARNING, ORTP_ERROR
* ORTP_FATAL . * ORTP_FATAL .
**/ **/
void ortp_set_log_level_mask(int levelmask){ void ortp_set_log_level_mask(int levelmask){
__ortp_log_mask=levelmask; __ortp_log_mask=levelmask;
...@@ -81,43 +81,42 @@ void ortp_set_log_thread_id(unsigned long thread_id) { ...@@ -81,43 +81,42 @@ void ortp_set_log_thread_id(unsigned long thread_id) {
char * ortp_strdup_vprintf(const char *fmt, va_list ap) char * ortp_strdup_vprintf(const char *fmt, va_list ap)
{ {
/* Guess we need no more than 100 bytes. */ /* Guess we need no more than 100 bytes. */
int n, size = 200; int n, size = 200;
char *p,*np; char *p,*np;
#ifndef _WIN32 #ifndef _WIN32
va_list cap;/*copy of our argument list: a va_list cannot be re-used (SIGSEGV on linux 64 bits)*/ va_list cap;/*copy of our argument list: a va_list cannot be re-used (SIGSEGV on linux 64 bits)*/
#endif #endif
if ((p = (char *) ortp_malloc (size)) == NULL) if ((p = (char *) ortp_malloc (size)) == NULL)
return NULL; return NULL;
while (1) while (1)
{ {
/* Try to print in the allocated space. */ /* Try to print in the allocated space. */
#ifndef _WIN32 #ifndef _WIN32
va_copy(cap,ap); va_copy(cap,ap);
n = vsnprintf (p, size, fmt, cap); n = vsnprintf (p, size, fmt, cap);
va_end(cap); va_end(cap);
#else #else
/*this works on 32 bits, luckily*/ /*this works on 32 bits, luckily*/
n = vsnprintf (p, size, fmt, ap); n = vsnprintf (p, size, fmt, ap);
#endif #endif
/* If that worked, return the string. */ /* If that worked, return the string. */
if (n > -1 && n < size) if (n > -1 && n < size)
return p; return p;
//printf("Reallocing space.\n"); //printf("Reallocing space.\n");
/* Else try again with more space. */ /* Else try again with more space. */
if (n > -1) /* glibc 2.1 */ if (n > -1) /* glibc 2.1 */
size = n + 1; /* precisely what is needed */ size = n + 1; /* precisely what is needed */
else /* glibc 2.0 */ else /* glibc 2.0 */
size *= 2; /* twice the old size */ size *= 2; /* twice the old size */
if ((np = (char *) ortp_realloc (p, size)) == NULL) if ((np = (char *) ortp_realloc (p, size)) == NULL)
{ {
free(p); free(p);
return NULL; return NULL;
} } else
else {
{
p = np; p = np;
} }
} }
} }
...@@ -136,7 +135,7 @@ char * ortp_strcat_vprintf(char* dst, const char *fmt, va_list ap){ ...@@ -136,7 +135,7 @@ char * ortp_strcat_vprintf(char* dst, const char *fmt, va_list ap){
ret=ortp_strdup_vprintf(fmt, ap); ret=ortp_strdup_vprintf(fmt, ap);
if (!dst) return ret; if (!dst) return ret;
dstlen = strlen(dst); dstlen = strlen(dst);
retlen = strlen(ret); retlen = strlen(ret);
...@@ -244,44 +243,38 @@ static void __ortp_logv_out(OrtpLogLevel lev, const char *fmt, va_list args){ ...@@ -244,44 +243,38 @@ static void __ortp_logv_out(OrtpLogLevel lev, const char *fmt, va_list args){
#endif #endif
if (__log_file==NULL) __log_file=stderr; if (__log_file==NULL) __log_file=stderr;
switch(lev){ if ((lev & ORTP_DEBUG) != 0) {
case ORTP_DEBUG: lname="debug";
lname="debug"; } else if ((lev & ORTP_MESSAGE) != 0) {
break; lname="message";
case ORTP_MESSAGE: } else if ((lev & ORTP_WARNING) != 0) {
lname="message"; lname="warning";
break; } else if ((lev & ORTP_ERROR) != 0) {
case ORTP_WARNING: lname="error";
lname="warning"; } else if ((lev & ORTP_FATAL) != 0) {
break; lname="fatal";
case ORTP_ERROR: } else {
lname="error"; ortp_fatal("Bad level !");
break;
case ORTP_FATAL:
lname="fatal";
break;
default:
ortp_fatal("Bad level !");
} }
msg=ortp_strdup_vprintf(fmt,args); msg=ortp_strdup_vprintf(fmt,args);
#if defined(_MSC_VER) && !defined(_WIN32_WCE) #if defined(_MSC_VER) && !defined(_WIN32_WCE)
#ifndef _UNICODE #ifndef _UNICODE
OutputDebugStringA(msg); OutputDebugStringA(msg);
OutputDebugStringA("\r\n"); OutputDebugStringA("\r\n");
#else #else
{ {
size_t len=strlen(msg); size_t len=strlen(msg);
wchar_t *tmp=(wchar_t*)ortp_malloc0((len+1)*sizeof(wchar_t)); wchar_t *tmp=(wchar_t*)ortp_malloc0((len+1)*sizeof(wchar_t));
mbstowcs(tmp,msg,len); mbstowcs(tmp,msg,len);
OutputDebugStringW(tmp); OutputDebugStringW(tmp);
OutputDebugStringW(L"\r\n"); OutputDebugStringW(L"\r\n");
ortp_free(tmp); ortp_free(tmp);
} }
#endif #endif
#endif #endif
fprintf(__log_file,"%i-%.2i-%.2i %.2i:%.2i:%.2i:%.3i ortp-%s-%s" ENDLINE fprintf(__log_file,"%i-%.2i-%.2i %.2i:%.2i:%.2i:%.3i ortp-%s-%s" ENDLINE
,1900+lt->tm_year,1+lt->tm_mon,lt->tm_mday,lt->tm_hour,lt->tm_min,lt->tm_sec ,1900+lt->tm_year,1+lt->tm_mon,lt->tm_mday,lt->tm_hour,lt->tm_min,lt->tm_sec
,(int)(tp.tv_usec/1000), lname,msg); ,(int)(tp.tv_usec/1000), lname,msg);
fflush(__log_file); fflush(__log_file);
ortp_free(msg); ortp_free(msg);
} }
...@@ -315,29 +308,22 @@ void ortp_qnx_log_handler(const char *domain, OrtpLogLevel lev, const char *fmt, ...@@ -315,29 +308,22 @@ void ortp_qnx_log_handler(const char *domain, OrtpLogLevel lev, const char *fmt,
} }
} }
switch (lev) { if ((lev & ORTP_DEBUG) != 0) {
case ORTP_DEBUG: severity = SLOG2_DEBUG1;
severity = SLOG2_DEBUG1; } else if ((lev & ORTP_MESSAGE) != 0) {
buffer_idx = 0; severity = SLOG2_INFO;
break; } else if ((lev & ORTP_WARNING) != 0) {
case ORTP_MESSAGE: severity = SLOG2_WARNING;
severity = SLOG2_INFO; } else if ((lev & ORTP_ERROR) != 0) {
buffer_idx = 0; severity = SLOG2_ERROR;
break; } else if ((lev & ORTP_FATAL) != 0) {
case ORTP_WARNING: severity = SLOG2_CRITICAL;
severity = SLOG2_WARNING; } else {
break; ortp_fatal("Bad level!");
case ORTP_ERROR:
severity = SLOG2_ERROR;
break;
case ORTP_FATAL:
severity = SLOG2_CRITICAL;
break;
default:
ortp_fatal("Bad level!");
} }
}
msg=ortp_strdup_vprintf(fmt,args); msg=ortp_strdup_vprintf(fmt,args);
slog2c(slog2_buffer_handle[buffer_idx], 0, severity, msg); slog2c(slog2_buffer_handle[buffer_idx], 0, severity, msg);
} }
#endif /* __QNX__ */ #endif /* __QNX__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment