static void EsifDataLogFire(int isHeader) { int i = 0; char outLine[MAX_LOG_LINE] = { 0 }; EsifLogType logtype = ESIF_LOG_UI; time_t now = time(NULL); struct tm time = { 0 }; esif_ccb_time_t msec = 0; esif_ccb_system_time(&msec); if (isHeader > 0) { esif_ccb_sprintf(MAX_LOG_LINE, outLine, "Time,Server Msec,"); } else { if (esif_ccb_localtime(&time, &now) == 0) { esif_ccb_sprintf(MAX_LOG_LINE, outLine, "%04d-%02d-%02d %02d:%02d:%02d,%llu,", time.tm_year + 1900, time.tm_mon + 1, time.tm_mday, time.tm_hour, time.tm_min, time.tm_sec, msec); } } for (i = 0; i < MAX_PARTICIPANT_ENTRY; i++) { eEsifError rc = ESIF_OK; DataLogParticipant currentParticipant = g_dataLogParticipants[i]; if (currentParticipant.participantNumFields > 0) { rc = EsifDataLogAddParticipant(outLine, i, isHeader); } } EsifLogFile_Write(logtype, "%s\n", outLine); }
int EsifTraceMessage( esif_tracemask_t module, int level, const char *func, const char *file, int line, const char *msg, ...) { int rc=0; char *appname = ""; char *fmtDetail= "%s%s:[<%s>%s@%s#%d]<%llu ms>: "; char *fmtInfo = "%s%s:[<%s>]<%llu ms>: "; const char *sep=NULL; size_t fmtlen=esif_ccb_strlen(msg, 0x7FFFFFFF); int detailed_message = (level >= DETAILED_TRACELEVEL ? ESIF_TRUE : ESIF_FALSE); va_list args; esif_ccb_time_t msec = 0; enum esif_tracemodule moduleid = ESIF_TRACEMODULE_DEFAULT; const char *module_name = NULL; esif_ccb_system_time(&msec); while (module >>= 1) moduleid++; module_name = EsifTraceModule_ToString(moduleid); level = esif_ccb_min(level, ESIF_TRACELEVEL_MAX); level = esif_ccb_max(level, ESIF_TRACELEVEL_FATAL); if ((sep = strrchr(file, *ESIF_PATH_SEP)) != NULL) file = sep+1; // Do not log function/file/line information for DPTF app interface messages logged from EsifSvcWriteLog if (moduleid == ESIF_TRACEMODULE_DPTF) { detailed_message = ESIF_FALSE; } if (g_traceinfo[level].routes & ESIF_TRACEROUTE_CONSOLE) { if (detailed_message) rc = CMD_CONSOLE(fmtDetail, appname, g_traceinfo[level].label, module_name, func, file, line, msec); else rc = CMD_CONSOLE(fmtInfo, appname, g_traceinfo[level].label, module_name, msec); va_start(args, msg); rc += EsifConsole_WriteConsole(msg, args); va_end(args); if (fmtlen && msg[fmtlen-1]!='\n') CMD_CONSOLE("\n"); } if (g_traceinfo[level].routes & ESIF_TRACEROUTE_LOGFILE && EsifLogFile_IsOpen(ESIF_LOG_TRACE)) { time_t now=0; char timestamp[MAX_CTIME_LEN]={0}; time(&now); esif_ccb_ctime(timestamp, sizeof(timestamp), &now); timestamp[20] = 0; // truncate year if (detailed_message) rc = EsifLogFile_Write(ESIF_LOG_TRACE, fmtDetail, timestamp + 4, g_traceinfo[level].label, module_name, func, file, line, msec); else rc = EsifLogFile_Write(ESIF_LOG_TRACE, fmtInfo, timestamp+4, g_traceinfo[level].label, module_name, msec); va_start(args, msg); rc += EsifLogFile_WriteArgsAppend(ESIF_LOG_TRACE, "\n", msg, args); va_end(args); } #ifdef ESIF_ATTR_OS_WINDOWS if (g_traceinfo[level].routes & (ESIF_TRACEROUTE_DEBUGGER)) { size_t msglen=0; char *buffer=0; int offset=0; va_start(args, msg); msglen = esif_ccb_vscprintf(msg, args) + esif_ccb_strlen(g_traceinfo[level].label, MAX_PATH) + esif_ccb_strlen(appname, MAX_PATH) + esif_ccb_strlen(func, MAX_PATH) + esif_ccb_strlen(file, MAX_PATH) + esif_ccb_strlen(module_name, MAX_PATH) + 22; va_end(args); msglen += (detailed_message ? esif_ccb_strlen(fmtDetail, MAX_PATH) : esif_ccb_strlen(fmtInfo, MAX_PATH)); buffer = (char *)esif_ccb_malloc(msglen); if (NULL != buffer) { if (detailed_message) rc = esif_ccb_sprintf(msglen, buffer, fmtDetail, appname, g_traceinfo[level].label, module_name, func, file, line, msec); else rc = esif_ccb_sprintf(msglen, buffer, fmtInfo, appname, g_traceinfo[level].label, module_name, msec); offset = rc; va_start(args, msg); rc += esif_ccb_vsprintf(msglen-offset, buffer+offset, msg, args); va_end(args); if (rc && buffer[rc-1]!='\n') esif_ccb_strcat(buffer, "\n", msglen); OutputDebugStringA(buffer); esif_ccb_free(buffer); } } if (g_traceinfo[level].routes & (ESIF_TRACEROUTE_EVENTLOG)) { size_t msglen=0; char *buffer=0; char *replaced=0; int offset=0; int backset=0; WORD eventType; appname = ""; fmtInfo = "%sESIF(%s) TYPE: %s MODULE: %s TIME %llu ms\n\n"; fmtDetail= "%sESIF(%s) TYPE: %s MODULE: %s FUNC: %s FILE: %s LINE: %d TIME: %llu ms\n\n"; backset = 0; va_start(args, msg); msglen = esif_ccb_vscprintf(msg,args) + esif_ccb_strlen(g_traceinfo[level].label, MAX_PATH) + esif_ccb_strlen(appname, MAX_PATH) + esif_ccb_strlen(func, MAX_PATH) + esif_ccb_strlen(file, MAX_PATH) + esif_ccb_strlen(module_name, MAX_PATH) + 32; va_end(args); msglen += (detailed_message ? esif_ccb_strlen(fmtDetail, MAX_PATH) : esif_ccb_strlen(fmtInfo, MAX_PATH)); buffer = (char *)esif_ccb_malloc(msglen); if (NULL != buffer) { if (detailed_message) rc = esif_ccb_sprintf(msglen, buffer, fmtDetail, appname, ESIF_UF_VERSION, g_traceinfo[level].label, module_name, func, file, line, msec); else rc = esif_ccb_sprintf(msglen, buffer, fmtInfo, appname, ESIF_UF_VERSION, g_traceinfo[level].label, module_name, msec); if (backset && backset < rc) buffer[rc-backset-1] = 0; offset = rc-backset; va_start(args, msg); rc += esif_ccb_vsprintf(msglen-(offset+backset), buffer+offset+backset, msg, args); va_end(args); if (rc && buffer[rc-1]=='\n') buffer[--rc] = 0; switch (g_traceinfo[level].level) { case ESIF_TRACELEVEL_FATAL: case ESIF_TRACELEVEL_ERROR: eventType = EVENTLOG_ERROR_TYPE; break; case ESIF_TRACELEVEL_WARN: eventType = EVENTLOG_WARNING_TYPE; break; case ESIF_TRACELEVEL_INFO: case ESIF_TRACELEVEL_DEBUG: default: eventType = EVENTLOG_INFORMATION_TYPE; break; } // Escape any "%" in message before writing to EventLog if ((replaced = esif_str_replace(buffer, "%", "%%")) != NULL) { esif_ccb_free(buffer); buffer = replaced; replaced = NULL; } report_event_to_event_log(CATEGORY_GENERAL, eventType, buffer); esif_ccb_free(buffer); } } #endif #ifdef ESIF_ATTR_OS_LINUX if (g_traceinfo[level].routes & (ESIF_TRACEROUTE_EVENTLOG|ESIF_TRACEROUTE_DEBUGGER)) { size_t msglen=0; char *buffer=0; int offset=0; int priority; fmtDetail= "%s:[<%s>%s@%s#%d]<%llu ms>: "; fmtInfo = "%s:[<%s>]<%llu ms>: "; va_start(args, msg); msglen = esif_ccb_vscprintf(msg,args) + esif_ccb_strlen(g_traceinfo[level].label, MAX_PATH) + esif_ccb_strlen(func, MAX_PATH) + esif_ccb_strlen(file, MAX_PATH) + esif_ccb_strlen(module_name, MAX_PATH) + 22; va_end(args); msglen += (detailed_message ? esif_ccb_strlen(fmtDetail, MAX_PATH) : esif_ccb_strlen(fmtInfo, MAX_PATH)); buffer = (char *)esif_ccb_malloc(msglen); if (NULL != buffer) { char *lf; if (detailed_message) rc = esif_ccb_sprintf(msglen, buffer, fmtDetail, g_traceinfo[level].label, module_name, func, file, line, msec); else rc = esif_ccb_sprintf(msglen, buffer, fmtInfo, g_traceinfo[level].label, module_name, msec); offset = rc; va_start(args, msg); rc += esif_ccb_vsprintf(msglen-offset, buffer+offset, msg, args); va_end(args); if (rc && buffer[rc-1]=='\n') buffer[--rc] = 0; while ((lf = esif_ccb_strchr(buffer, '\n')) != NULL) *lf = '\t'; switch (g_traceinfo[level].level) { case ESIF_TRACELEVEL_FATAL: priority = ESIF_PRIORITY_FATAL; break; case ESIF_TRACELEVEL_ERROR: priority = ESIF_PRIORITY_ERROR; break; case ESIF_TRACELEVEL_WARN: priority = ESIF_PRIORITY_WARNING; break; case ESIF_TRACELEVEL_INFO: priority = ESIF_PRIORITY_INFO; break; case ESIF_TRACELEVEL_DEBUG: default: priority = ESIF_PRIORITY_DEBUG; break; } #ifdef ESIF_ATTR_OS_ANDROID __android_log_write(priority, IDENT, buffer); #else openlog(IDENT, OPTION, FACILITY); syslog(priority, "%s", buffer); closelog(); #endif esif_ccb_free(buffer); } } #endif return rc; }