static void __ortp_logv_out(OrtpLogLevel lev, const char *fmt, va_list args){ const char *lname="undef"; char *msg; if (__log_file==NULL) __log_file=stderr; switch(lev){ case ORTP_DEBUG: lname="debug"; break; case ORTP_MESSAGE: lname="message"; break; case ORTP_WARNING: lname="warning"; break; case ORTP_ERROR: lname="error"; break; case ORTP_FATAL: lname="fatal"; break; default: ortp_fatal("Bad level !"); } msg=ortp_strdup_vprintf(fmt,args); #ifdef _MSC_VER OutputDebugString(msg); OutputDebugString("\r\n"); #else fprintf(__log_file,"ortp-%s-%s" ENDLINE,lname,msg); fflush(__log_file); #endif ortp_free(msg); }
static void __ortp_logv_out(OrtpLogLevel lev, const char *fmt, va_list args){ const char *lname="undef"; char *msg; struct timeval tp; struct tm *lt; #ifndef _WIN32 struct tm tmbuf; #endif time_t tt; ortp_gettimeofday(&tp,NULL); tt = (time_t)tp.tv_sec; #ifdef _WIN32 lt = localtime(&tt); #else lt = localtime_r(&tt,&tmbuf); #endif if (__log_file==NULL) __log_file=stderr; switch(lev){ case ORTP_DEBUG: lname="debug"; break; case ORTP_MESSAGE: lname="message"; break; case ORTP_WARNING: lname="warning"; break; case ORTP_ERROR: lname="error"; break; case ORTP_FATAL: lname="fatal"; break; default: ortp_fatal("Bad level !"); } msg=ortp_strdup_vprintf(fmt,args); #if defined(_MSC_VER) && !defined(_WIN32_WCE) #ifndef _UNICODE OutputDebugStringA(msg); OutputDebugStringA("\r\n"); #else { int len=strlen(msg); wchar_t *tmp=(wchar_t*)ortp_malloc0((len+1)*sizeof(wchar_t)); mbstowcs(tmp,msg,len); OutputDebugStringW(tmp); OutputDebugStringW(L"\r\n"); ortp_free(tmp); } #endif #endif 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 ,(int)(tp.tv_usec/1000), lname,msg); fflush(__log_file); ortp_free(msg); }
char *ortp_strdup_printf(const char *fmt,...){ char *ret; va_list args; va_start (args, fmt); ret=ortp_strdup_vprintf(fmt, args); va_end (args); return ret; }
void linphonec_out(const char *fmt,...){ char *res; va_list args; va_start (args, fmt); res=ortp_strdup_vprintf(fmt,args); va_end (args); printf("%s",res); fflush(stdout); #if !defined(_WIN32_WCE) if (client_sock!=ORTP_PIPE_INVALID){ if (ortp_pipe_write(client_sock,(uint8_t*)res,strlen(res))==-1){ fprintf(stderr,"Fail to send output via pipe: %s",strerror(errno)); } } #endif /*_WIN32_WCE*/ ortp_free(res); }
char * ortp_strcat_vprintf(char* dst, const char *fmt, va_list ap){ char *ret; unsigned long dstlen, retlen; ret=ortp_strdup_vprintf(fmt, ap); dstlen = strlen(dst); retlen = strlen(ret); if ((dst = ortp_realloc(dst, dstlen+retlen+1)) != NULL){ strncat(dst,ret,retlen); dst[dstlen+retlen] = '\0'; ortp_free(ret); return dst; } else { ortp_free(ret); return NULL; } }
void ortp_logv(int level, const char *fmt, va_list args) { if ((ortp_logv_out != NULL) && ortp_log_level_enabled(level)) { if (__log_thread_id == 0) { ortp_logv_out(level, fmt, args); } else if (__log_thread_id == ortp_thread_self()) { ortp_logv_flush(); ortp_logv_out(level, fmt, args); } else { ortp_stored_log_t *l = ortp_new(ortp_stored_log_t, 1); l->level = level; l->msg = ortp_strdup_vprintf(fmt, args); ortp_mutex_lock(&__log_stored_messages_mutex); __log_stored_messages_list = o_list_append(__log_stored_messages_list, l); ortp_mutex_unlock(&__log_stored_messages_mutex); } } #if !defined(_WIN32_WCE) if (level == ORTP_FATAL) abort(); #endif }
void CorePlugin::log(OrtpLogLevel lev, const char *fmt, va_list args) { const char *lname="undef"; char *msg; switch(lev){ case ORTP_DEBUG: lname="debug"; break; case ORTP_MESSAGE: lname="message"; break; case ORTP_WARNING: lname="warning"; break; case ORTP_ERROR: lname="error"; break; case ORTP_FATAL: lname="fatal"; break; default: ortp_fatal("Bad level !"); } msg = ortp_strdup_vprintf(fmt, args); #ifdef DEBUG #ifdef WIN32 fprintf(s_log_file, FBSTRING_PluginFileName"-%s-%s\r\n", lname, msg); fflush(s_log_file); #else //WIN32 fprintf(stdout, FBSTRING_PluginFileName"-%s-%s\r\n", lname, msg); fflush(stdout); #endif //WIN32 #endif //DEBUG CorePluginPtr plugin = s_log_plugin.lock(); if(plugin) { CoreAPIPtr core = FB::ptr_cast<CoreAPI>(plugin->getRootJSAPI()); if(core) { core->log(lname, msg); } } ortp_free(msg); }
static void linphone_log_handler(OrtpLogLevel lev, const char *fmt, va_list args){ const char *lname="undef"; char *msg; char *msg_str; switch(lev){ case ORTP_DEBUG: lname="DEBUG"; break; case ORTP_MESSAGE: lname="MESSAGE"; break; case ORTP_WARNING: lname="WARING"; break; case ORTP_ERROR: lname="ERROR"; break; case ORTP_FATAL: lname="FATAL"; break; default: lname = ("Bad level !"); } msg=ortp_strdup_vprintf(fmt,args); msg_str = ortp_strdup_printf("%s: %s\r\n",lname,msg); #ifdef _MSC_VER OutputDebugString(msg_str); #endif ms_free(msg); ms_free(msg_str); }