Exemple #1
0
NMPRKC_API nmprk_status_t NMPRK_StartDebugLogging(
	const char *filename)
{
	char dateStr[MAX_DATE_STR_LEN];
	char timeStr[MAX_DATE_STR_LEN];

	if(si_fsDebugLog.is_open() == true)
		return NMPRK_FAILURE;

	try
	{
		si_debugModule = SI_DEBUG_MODULE_ALL;
		si_debugLevel = SI_DEBUG_LEVEL_ALL;
		si_fsDebugLog.open(filename, std::fstream::out | std::fstream::app);
		if(si_fsDebugLog.is_open() != true)
			return NMPRK_FAILURE;
	}
	catch (...)
	{
		return NMPRK_FAILURE;
	}

#if defined WIN32
	_strdate_s(dateStr, MAX_DATE_STR_LEN);
	_strtime_s(timeStr, MAX_DATE_STR_LEN);
#else
	time_t mytime = time(NULL);
	strftime(dateStr, 9, "%D", localtime(&mytime));
	strftime(timeStr, 9, "%T", localtime(&mytime));
#endif
		
	SI_DEBUG_INFO(SI_THIS_MODULE, "Debug Logging Started: %s %s", dateStr, timeStr);

	return NMPRK_SUCCESS;
}
Exemple #2
0
	void Log::m_print(const char* levtext, const char* text) {
		char timer[9];
		_strtime_s(timer, 9);
		clock_t cl = clock();

		printf("%s::%d: %s%s\n", timer, cl, levtext, text);
		if(m_file) {
			fprintf(m_file, "%s::%d: %s%s\n", timer, cl, levtext, text);
			fflush(m_file);
		}
	}
Exemple #3
0
	void Log::m_close() {
		if(!m_file) {
			return;
		}

		char timer[9];
		_strtime_s(timer, 9);
		char date[9];
		_strdate_s(date, 9);
		fprintf(m_file, "\nКонец лога: %s %s.", date, timer);
		fclose(m_file);
	}
Exemple #4
0
	void Log::m_close()
	{
		if (!m_file)
			return;
		char timer[9];
		_strtime_s(timer, 9);
		char date[9];
		_strdate_s(date, 9);
		fprintf(m_file, "\n---------------------------------------\n");
		fprintf(m_file, "Log end: %s %s\n", date, timer);
		fclose(m_file);
	}
Exemple #5
0
void SSIEIGEN::ErrorCalc()
{
	int i,j;
	double s_freq,s_form;

	char tmpbuf[256];

	if (ITL > ITLlastshift)
	{
		err_freq_old = err_freq;
		err_form_old = err_form;

		err_freq = 0;
		err_form = 0;
		for (i=0; i<nform; i++)
		{
			err_freq_mas[i] = abs((LM[tmpi[i]] - LMold[tmpi_old[i]])/LM[tmpi[i]]);
			err_form_mas[i] = abs((UFmax[tmpi[i]] - UFmaxold[tmpi_old[i]])/UFmax[tmpi[i]]);
		}
		for (i=0; i<nf; i++)
		{
			s_freq = abs((LM[tmpi[i]] - LMold[tmpi_old[i]])/LM[tmpi[i]]);
			s_form = abs((UFmax[tmpi[i]] - UFmaxold[tmpi_old[i]])/UFmax[tmpi[i]]);
			if ( low_err[tmpi[i]] == 0 && err_freq < s_freq) err_freq = s_freq;
			fprintf(fp,"low_err %d = %d\n",i,low_err[tmpi[i]]);
			fprintf(fp,"freq %d = %e   err_freq = %e  \n",i,LM[tmpi[i]],s_freq);
			
			if ( low_err[tmpi[i]] == 0 && err_form < s_form) err_form = s_form;
			fprintf(fp,"form %d = %e   err_form = %e  \n",i,UFmax[tmpi[i]],s_form);
			fprintf(fp,"\n");
			fflush(fp);
		}
	}
	_strtime_s( tmpbuf, 128 );
	fprintf(fp," TOLLERANCE  ITL = %d    freq = %f  form = %f      OS time:\t%s\n\n\n",ITL,err_freq,err_form,tmpbuf);
	fflush(fp);

//определение количества сошедшихся до требуемой точности частот, следующих подряд
	consecutive_convfreq = 0;
	for (i=0; i<nform; i++)
	{
		if ( err_freq_mas[i] < eps_freq )
		{
			consecutive_convfreq++;
		}
		else
		{
			break;
		}
	}

}
Exemple #6
0
	void Log::m_init() {
		setlocale(LC_ALL, "rus");
		
		if(fopen_s(&m_file, LOGNAME, "w") == 0) {
			char timer[9];
			_strtime_s(timer, 9);
			char date[9];
			_strdate_s(date, 9);
			fprintf(m_file, "Лог создан: %s %s.\n\n", date, timer);
		} else {
			printf("Ошибка при создании файла лога\n");
			m_file = nullptr;
		}
	}
Exemple #7
0
void CCenTime::GenCurrentTime(char *timebuf, int Len)
{

    char tmpbuf[128];
	if(!timebuf) 
	{
		return;
	}
    // Set time zone from TZ environment variable. If TZ is not set,
    // the operating system is queried to obtain the default value 
    // for the variable. 
    //
    _tzset();

    // Display operating system-style date and time. 
    _strtime_s( tmpbuf, 128 );
	strcpy_s(timebuf, Len, tmpbuf);

	return;
}
Exemple #8
0
void CGCServiceApp::log(const char* msg)
{
	if (!m_Fh)
	{
		m_Fh = Safe::fopen("desura_service.log", "a");

		char dateStr[9];
		char timeStr[9];
		_strdate_s(dateStr);
		_strtime_s(timeStr);

		if (m_Fh)
			fprintf(m_Fh, "\n\nStarted Logging: %s at %s\n", dateStr, timeStr);
	}

	if (m_Fh)
		fprintf(m_Fh, "%s", msg);

	printf("%s", msg);
}
Exemple #9
0
	//--------Инициализация класса--------//
	void Log::m_init()
	{
		setlocale(LC_ALL, "RUS");
		//Если файл можно открыть для записи
		if (fopen_s(&m_file, LOGNAME, "w") == 0)
		{
			//Получение времени и даты
			char timer[9];
			_strtime_s(timer, 9);
			char date[9];
			_strdate_s(date, 9);
			//Запись в файл
			fprintf(m_file, "Log has created at %s %s \n", date, timer);
			fprintf(m_file, "-------------------------------------------\n\n");
		}
		else
		{
			printf("Error while log creating....\n");
			m_file = nullptr;
		}
	}
Exemple #10
0
//로그 찍기
VOID cLogMgr::AddLog( char* strmsg, ... )
{

	char szBuff[4096];
	char szDate[128];		//날짜
	char szTime[128];		//시간

	_strdate_s( szDate, 128 );
	_strtime_s( szTime, 128 );
	vsprintf_s( szBuff, strmsg, (char*)(&strmsg+1) );

	//Console에 출력할 경우
	if( m_nTarget & LOG_CONSOLE )
	{
		printf( "(data[%s] time[%s] ) : %s\n", szDate, szTime, szBuff );
	}

	//FILE 에 출력 할경우
	if( m_nTarget & LOG_FILE )
	{
		LogFile( "(data[%s] time[%s] ) : %s\n", szDate, szTime, szBuff );
	}

	//LOG 윈도우에 출력할 경우 ( 디버그 모드에서만 지원
#ifdef _DEBUG

	if( m_nTarget & LOG_WINDOW )
	{
		//윈도우 리스트 박스에 로그 추가
		SendMessage( m_hWndListBox, LB_ADDSTRING, 0, (LPARAM)szBuff );

		//추가된 리스트 박스의 순번 얻기 (마지막을 선택하면 된다 )
		UINT32 n = SendMessage( m_hWndListBox, LB_GETCOUNT, 0, 0 ) - 1;

		//선택 커서 마지막으로
		SendMessage( m_hWndListBox, LB_SETCURSEL, (WPARAM)n, 0 );
	}

#endif //_DEBUG
}
Exemple #11
0
void Time::SetSystemTime ()
{
	int hr, mn, sec, m, d, y;
	char timebuf[100];
	char datebuf[100];
	std::string line;

	#ifdef _MSC_VER
		#ifdef VS2005
		_strtime_s ( timebuf, 100 );
		_strdate_s ( datebuf, 100 );
		#else
		_strtime ( timebuf );
		_strdate ( datebuf );
		#endif
	#endif
	#if (defined(__linux__) || defined(__CYGWIN__))
		time_t tt; 
		struct tm tim;
		tt = time(NULL);	
		localtime_r(&tt, &tim);	
		sprintf( timebuf, "%02i:%02i:%02i", tim.tm_hour, tim.tm_min, tim.tm_sec);
		sprintf( datebuf, "%02i:%02i:%02i", tim.tm_mon, tim.tm_mday, tim.tm_year % 100);
	#endif

	line = timebuf;
	hr = atoi ( line.substr ( 0, 2).c_str() );
	mn = atoi ( line.substr ( 3, 2).c_str() );
	sec = atoi ( line.substr ( 6, 2).c_str() );
	line = datebuf;
	m = atoi ( line.substr ( 0, 2).c_str() );
	d = atoi ( line.substr ( 3, 2).c_str() );
	y = atoi ( line.substr ( 6, 2).c_str() );
	
	// NOTE: This only works from 1930 to 2030
	if ( y > 30) y += 1900;
	else y += 2000;
	
	SetTime ( hr, mn, m, d, y, sec, 0, 0);
}
Exemple #12
0
int KLog::Log(LPSTR fmt, ...){

	if (m_nTarget & K_LOG_TARGET_UNDEFINED){
		return 0;
	}

	char buff[1024];
	char date[128];
	char time[128];

	_strdate_s(date);
	_strtime_s(time);
	vsprintf_s(buff, fmt, (char*)(&fmt + 1));

	// Console에 출력할 경우
	if (m_nTarget & K_LOG_TARGET_CONSOLE){
		printf("(date[%s] time[%s]) : %s\n", date, time, buff);
	}

	// Log File에 출력할 경우
	if (m_nTarget & K_LOG_TARGET_FILE){
		FILE* fp = NULL;
		fopen_s(&fp, m_szFilename, "a+");
		if (fp){
//			fprintf(fp, "(date[%s] time[%s] : %s\n", date, time, buff);
			fprintf(fp, "%s\n", buff);
			fclose(fp);
		}
	}

	//Log Window에 출력할 경우
	if (m_nTarget& K_LOG_TARGET_WINDOW){
		SendMessage(m_hwndList, LB_ADDSTRING, 0, (LPARAM)buff);
		UINT32 n = SendMessage(m_hwndList, LB_GETCOUNT, 0, 0L) - 1;
		SendMessage(m_hwndList, LB_SETCURSEL, (WPARAM)n, 0L);
	}
	return 1;
}
Exemple #13
0
void Logger::Log(eLogLevel level, const char* message, ...){
	if(!m_ostream) return;
	if(level >= m_logLevel){
		//guarding output for multithreading
		ZThread::Guard<ZThread::FastMutex> gvrd(m_lock);
		std::string outStrPref("[");
		char buff[16*1024];
		_strtime_s(buff,1024);
		outStrPref += buff;
		switch(level){
			case LVL_DEBUG:
				outStrPref += "][DEBUG] ";
				SetConColor(GREEN);
				break;
			case LVL_NOTICE:
				outStrPref += "][NOTICE] ";
				SetConColor(GREEN,true);
				break;
			case LVL_WARNING:
				outStrPref += "][WARNING] ";
				SetConColor(YELLOW);
				break;
			case LVL_ERROR:
				outStrPref += "][ERROR] ";
				SetConColor(RED,true);
				break;
		}
		va_list args;

		va_start(args, message);
		vsprintf_s(buff, 16*1024, message, args);
		(*m_ostream)<<outStrPref;
		SetConColor(WHITE);
		(*m_ostream)<<buff<<std::endl;
	}
}
Exemple #14
0
/*
CAUTION: Try to avoid use AddLogInfo from the main application thread. Otherwise deadlock can occur!!
TODO : make this function into a new thread on every call...
*/
void CLogger::AddLogInfo(int color, char *lpszText, ...)
{

    char szColor[10];
    strcpy_s(szColor,sizeof(szColor),"000000");	  //Default

    if(color==GS_LOG_WARNING)
        strcpy_s(szColor,sizeof(szColor),"99dd00");
    else if(color==GS_LOG_DEBUG)
        strcpy_s(szColor,sizeof(szColor),"0000FF");
    else if(color==GS_LOG_ERROR)
        strcpy_s(szColor,sizeof(szColor),"FF0000");

    char time[64], date[64];
    // Set time zone from TZ environment variable. If TZ is not set,
    // the operating system is queried to obtain the default value
    // for the variable.
    //
    _tzset();

    // Display operating system-style date and time.
    _strtime_s( time, 64 );
    _strdate_s( date, 64 );

    if(TryEnterCriticalSection(&CS_Logger)==FALSE)
        return;


    va_list argList;
    FILE *pFile = NULL;


    //Initialize variable argument list
    va_start(argList, lpszText);

    if(szLogPath!=NULL)
        SetCurrentDirectory(szLogPath);
    //Open the g_log.file for appending
    pFile = fopen("g_log.htm", "a+");

    if(pFile != NULL)
    {
        //Write the error to the g_log.file
        fprintf(pFile, "<font face=\"Arial\" size=\"2\" color=\"#%s\"><b>",szColor);
        fprintf(pFile, "[%s][%s]",date,time);

        vfprintf(pFile, lpszText, argList);
        fprintf(pFile, "</b></font><br>\n");

        //Close the file
        fclose(pFile);
        char szBuffer[512];
        vsprintf_s(szBuffer,sizeof(szBuffer),lpszText, argList);


        UTILZ_sLogger.append(szBuffer);
        UTILZ_sLogger.append("\r\n");

        if(UTILZ_sLogger.length()>1000)
            UTILZ_sLogger.erase(UTILZ_sLogger.begin(),UTILZ_sLogger.begin()+UTILZ_sLogger.find_first_of("\n")); //strlen(szBuffer));

        SetWindowText(hwndLogger,UTILZ_sLogger.c_str());


        SendMessage(hwndLogger,WM_VSCROLL,LOWORD(SB_BOTTOM),NULL);
#ifdef _DEBUG
        OutputDebugString(szBuffer);
        OutputDebugString("\n");
#endif

    }
    va_end(argList);

    LeaveCriticalSection(&CS_Logger);

}
Exemple #15
0
void CSimpleLog::Add(const char* fmt, ...)
{



	if(!m_fp)
	{

		// 设置当前目录为流媒体主程序目录
		std::string app_path = GetAppPath();

		app_path = app_path + m_logdir;

		_mkdir(app_path.c_str());


		struct tm *now;
		time_t ltime;

		time(&ltime);
		now = localtime(&ltime);

		char chFile[512] = {0};
	
		

		sprintf_s(chFile, "%s\\Log_%d_%d_%d %02d_%02d_%02d.log", app_path.c_str()
			, now->tm_year+1900, now->tm_mon+1, now->tm_mday,now->tm_hour,now->tm_min,now->tm_sec);


		m_fp = fopen(chFile, "w+"); //以添加的方式输出到文件
		if (!m_fp)
			return;

	}



	/*-----------------------进入临界区(写文件)------------------------------*/	
	::EnterCriticalSection(&m_crit);   
	try      
	{
		va_list argptr;          //分析字符串的格式
		va_start(argptr, fmt);
		_vsnprintf(m_tBuf, BUFSIZE, fmt, argptr);
		va_end(argptr);
	}
	catch (...)
	{
		m_tBuf[0] = 0;
	}


	char szDate[64] = {0};
	char szTime[64] = {0};
	_strdate_s(szDate);
	_strtime_s(szTime);

	fprintf(m_fp,"%s %s\t", szDate, szTime);
	fprintf(m_fp, "%s\n", m_tBuf);	
	fflush(m_fp);

	::LeaveCriticalSection(&m_crit);  
	/*----------------------------退出临界区---------------------------------*/	

}