Exemple #1
0
static void printf_impl(CPCHANDLE handle, const TCHAR* fmt, ...)
{
    va_list args;
    va_start(args, fmt);
    _vftprintf(handle->impl->output_stream, fmt, args);
    va_end(args);
}
Exemple #2
0
void Log::tprint(int level, LPCTSTR fmt, ...)
{
    if (level > sizeof(gsLogLabels)/sizeof(char *) - 1)
    {
        return;
    }

    if (level > m_loglevel)
    {
        return;
    }
    va_list list; 
    va_start(list, fmt);
    TCHAR szTime[MAX_PATH];
    time_t now = time(NULL);
    _tcsftime(szTime, MAX_PATH, _T("%c"), localtime(&now));

    ::EnterCriticalSection(&m_lock);
    if(m_log_fp) {
        _ftprintf(m_log_fp, _T("[%s]"), szTime); 
        _vftprintf(m_log_fp, fmt, list);
        fflush(m_log_fp);
    }
    ::LeaveCriticalSection(&m_lock);
    va_end(list);
    return;
}
Exemple #3
0
/**
* In Unix systems which have a syslog facility the msg is stored there.
* The environment varibale <code>GLOBALPLATFORM_DEBUG</code> must be set to enable the logging.
* With the environment varibale <code>GLOBALPLATFORM_LOGFILE</code> an explicit log file name can
* be set. If a no log file name has been set impilictly <code>/tmp/GlobalPlatform.log</code>
* or <code>C:\TEMP\GlobalPlatform.log</code> under Windows will be used. If a log file name
* is given the syslog if available will not be used.
* \param msg The formatted message which will be stored.
* \prama ... Variable argument list
*/
void log_Log(LPTSTR msg, ...)
{
    va_list args;
    FILE *fp;
    time_t t;
    struct tm *time_s;
    TCHAR format[256];

    if (_tgetenv(_T("GLOBALPLATFORM_DEBUG")))
    {
    #ifdef HAVE_VSYSLOG
    if (getenv("GLOBALPLATFORM_LOGFILE")) {
	goto filelog;
    }
    else {
		va_start(args, msg);
		vsyslog(LOG_USER | LOG_DEBUG, msg, args);
		va_end(args);
		return;
    }
filelog:
    #endif // HAVE_VSYSLOG
    if (_tgetenv(_T("GLOBALPLATFORM_LOGFILE")))
        fp = _tfopen(_tgetenv(_T("GLOBALPLATFORM_LOGFILE")), _T("a"));
    else
        fp = _tfopen(LOG_FILENAME, _T("a"));

    if (!fp)
    {
	fp = stderr;
	_ftprintf(fp, _T("Error, could not open log file: %s\n"), LOG_FILENAME);
    }
    time(&t);
    time_s = localtime(&t);

    _sntprintf(format, 256, _T("%.2d/%.2d %.2d:%.2d:%.2d %s"),
			time_s->tm_mday,
			time_s->tm_mon+1,
			time_s->tm_hour,
			time_s->tm_min,
			time_s->tm_sec,
			msg);

    va_start(args, msg);
    _vftprintf(fp, format, args);
    va_end(args);

    #ifdef WIN32
    _fputts(_T("\r\n"), fp);
    #else
    _fputts(_T("\n"), fp);
    #endif // WIN32

    fflush(fp); /* Fixme: more accurate, but slows logging */

    if (fp != stderr)
        fclose(fp);
    }
}
Exemple #4
0
		void TerminalPrint(TCHAR* szFmt,...)
		{
			va_list ap;
			va_start(ap,szFmt);
			//vfprintf(stdout,szFmt,ap);
			_vftprintf(stdout,szFmt,ap);
			va_end(ap);
			_ftprintf(stdout,_T("\n"));
			fflush(stdout);
		}
Exemple #5
0
int CSafeBufferedFile::printf(LPCTSTR pszFmt, ...)
{
	va_list args;
	va_start(args, pszFmt);
	int iResult = _vftprintf(m_pStream, pszFmt, args);
	va_end(args);
	if (iResult < 0)
		AfxThrowFileException(CFileException::generic, _doserrno, m_strFileName);
	return iResult;
}
Exemple #6
0
// Debug printf to a file
static int __cdecl AppDebugPrintf(int nStatus, TCHAR* pszFormat, ...)
{
#if defined (FBA_DEBUG)
   DWORD ignore;
	va_list vaFormat;

	va_start(vaFormat, pszFormat);

	if (DebugLog) {

		if (nStatus != nPrevConsoleStatus) {
			switch (nStatus) {
				case PRINT_ERROR:
					_ftprintf(DebugLog, _T("</font><font color=#FF3F3F>"));
					break;
				case PRINT_IMPORTANT:
					_ftprintf(DebugLog, _T("</font><font color=#000000>"));
					break;
				default:
					_ftprintf(DebugLog, _T("</font><font color=#009F00>"));
			}
		}
		_vftprintf(DebugLog, pszFormat, vaFormat);
		fflush(DebugLog);
	}

	if (!DebugLog || bEchoLog) {
		_vsntprintf(szConsoleBuffer, 1024, pszFormat, vaFormat);

		if (nStatus != nPrevConsoleStatus) {
			switch (nStatus) {
				case PRINT_UI:
					SetConsoleTextAttribute(DebugBuffer,                                                       FOREGROUND_INTENSITY);
					break;
				case PRINT_IMPORTANT:
					SetConsoleTextAttribute(DebugBuffer, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
					break;
				case PRINT_ERROR:
					SetConsoleTextAttribute(DebugBuffer, FOREGROUND_RED | FOREGROUND_GREEN |                   FOREGROUND_INTENSITY);
					break;
				default:
					SetConsoleTextAttribute(DebugBuffer,                  FOREGROUND_GREEN |                   FOREGROUND_INTENSITY);
			}
		}

		WriteConsole(DebugBuffer, szConsoleBuffer, _tcslen(szConsoleBuffer), &ignore, NULL);
	}

	nPrevConsoleStatus = nStatus;

	va_end(vaFormat);
#endif

	return 0;
}
Exemple #7
0
void
LogFormat(const TCHAR *fmt, ...)
{
  va_list ap;

  va_start(ap, fmt);
  _vftprintf(stderr, fmt, ap);
  va_end(ap);

  fputc('\n', stderr);
}
static void addDebugLine(_In_z_ _Printf_format_string_ TCHAR const * const format, ...) {
  static Semaphore gate;
  static TCHAR *mode = _T("w");
  gate.wait();
  FILE *f = FOPEN(_T("c:\\temp\\semaphore.log"),mode);
  mode = _T("a");
  va_list argptr;
  va_start(argptr,format);
  _vftprintf(f, format, argptr);
  va_end(argptr);
  fclose(f);
  gate.signal();
}
Exemple #9
0
void log(const TCHAR *tszFormat, ...)
{
	#if defined(_DEBUG)
		FILE *out = fopen("c:\\temp\\pu.log", "a");
		if (out) {
			va_list params;
			va_start(params, tszFormat);
			_vftprintf(out, tszFormat, params);
			va_end(params);
			fputc('\n', out);
			fclose(out);
		}
	#endif
}
Exemple #10
0
static int __cdecl _vsctprintf( const _TXCHAR *format, va_list ap )
#endif
{
	FILE	*fp = _tfopen( _T("NUL"), _T("wb") );

	if ( fp )
	{
		int	retval = _vftprintf( fp, format, ap );
		fclose( fp );

		return retval;
	}

	return -1;
}
void logError(_In_z_ _Printf_format_string_ TCHAR const * const format,...) {
  FILE *f = fopen(makeErrorFileName(), _T("a"));
  if(f == NULL) {
    return;
  }

  _ftprintf(f, _T("%s"), Timestamp().toString().cstr());

  va_list argptr;
  va_start(argptr,format);
  _vftprintf(f, format, argptr);
  va_end(argptr);

  _ftprintf(f,_T("\n"));
  fclose(f);
}
Exemple #12
0
/// <summary>
///     ファイルにトレースを出力する。
///     DLLと同じフォルダ内のBkCalendar.logへ出力する。
/// </summary>
/// <param name="format">書式</param>
/// <param name="...">トレース出力用オブジェクト(可変)</param>
void Utils::Trace(LPCTSTR format, ...) {
    TCHAR path[_MAX_PATH];
    ::GetModuleFileName(hInstance, path, _MAX_PATH);
    _tcscpy_s(_tcsrchr(path, _T('\\')) + 1, 20, _T("BkCalendar.log"));

    FILE* file;
    if (0 != _tfopen_s(&file, path, _T("a"))) {
        return;
    }

    va_list args;
    va_start(args, format);
    _vftprintf(file, format, args);
    va_end(args);

    fclose(file);
}
///////////////////////////////////////////////////////////////////////////////
// HandleNotify
///////////////////////////////////////////////////////////////////////////////
void cUserNotifyStdout::HandleNotify( int level, const TCHAR* format, va_list& args )
{
    if(GetVerboseLevel() < level)
        return;

    // all verbose output now goes to stderr
    if(level < iUserNotify::V_VERBOSE)
    {
        _vtprintf(format, args);
        fflush( stdout );
    }
    else
    {
        _vftprintf(stderr, format, args);
        fflush( stderr );
    }
}
int MIOFILE::printf(const wxChar* format, ...) {
    int retval;

    va_list ap;
    va_start(ap, format);
    if (mf) {
        retval = mf->vprintf(format, ap);
    } else if (f) {
        retval = _vftprintf(f, format, ap);
    } else {
        size_t cursize = _tcslen(wbuf);
        size_t remaining_len = len - cursize;
        retval = _vsntprintf(wbuf+cursize, remaining_len, format, ap);
    }
    va_end(ap);
    return retval;
}
Exemple #15
0
INT
myPRINT::mf__lprintf(LPCTSTR lpFormat, ...)
{
	if (!m__lpFile) {
		// fopen에서 실패!
		return 0;
	}

	va_list	arglist;
	va_start(arglist, lpFormat);
	time_t	ltime;
	time(&ltime);
	fprintf(m__lpFile, "%.24s: ", ctime(&ltime));	// w/o "\n\0"
	INT	iReturnVal = _vftprintf(m__lpFile, lpFormat, arglist);
	va_end(arglist);

	return iReturnVal;
}
void Log(
    _In_  LOG_LEVEL   lvl,
    _In_  LPTSTR      frmt,
    _In_  ...
    ) {
    if (lvl >= gs_debugLevel) {
        TCHAR line[MAX_LINE] = { 0 };
        BOOL bResult = FALSE;
        va_list args;
        int size;
        size_t count;
        DWORD written;
        SYSTEMTIME time;

        GetSystemTime(&time);

        va_start(args, frmt);
        if (gs_hLogFile != INVALID_HANDLE_VALUE) {
            size = _stprintf_s(line, _countof(line), LOG_FRMT_TIME, time.wHour, time.wMinute, time.wSecond);
            if (size == -1) {
                _ftprintf(stderr, _T("Fatal error while formating log time. <errno:%x>"), errno);
                ExitProcess(EXIT_FAILURE);
            }

            bResult = WriteFile(gs_hLogFile, line, size, &written, NULL);
            if (!bResult || written != (DWORD)size) {
                _ftprintf(stderr, _T("Fatal error while writing log time to logfile : <gle:%u> <written:%u/%u>"), GetLastError(), written, (DWORD)size);
                ExitProcess(EXIT_FAILURE);
            }
            count = fwrite(line, size, 1, stderr);
            if (count != 1) {
                _ftprintf(stderr, _T("Fatal error while writing log time to output : <errno:%x>"), errno);
                ExitProcess(EXIT_FAILURE);
            }

            size = _vstprintf_s(line, _countof(line), frmt, args);
            if (size == -1) {
                _ftprintf(stderr, _T("Fatal error while formating log line. <errno:%x> <frmt:%s>"), errno, frmt);
                ExitProcess(EXIT_FAILURE);
            }
            bResult = WriteFile(gs_hLogFile, line, size, &written, NULL);
            if (!bResult || written != (DWORD)size) {
                _ftprintf(stderr, _T("Fatal error while writing log line to logfile : <gle:%u> <written:%u/%u> <frmt:%s>"), GetLastError(), written, (DWORD)size, frmt);
                ExitProcess(EXIT_FAILURE);
            }
            count = fwrite(line, size, 1, stderr);
            if (count != 1) {
                _ftprintf(stderr, _T("Fatal error while writing log line to output : <errno:%x> <count:%llu> <frmt:%s>"), errno, count, frmt);
                ExitProcess(EXIT_FAILURE);
            }
        }
        else {
            size = _ftprintf(stderr, LOG_FRMT_TIME, time.wHour, time.wMinute, time.wSecond);
            if (size == -1) {
                _ftprintf(stderr, _T("Fatal error while writing log time to output : <errno:%x>"), errno);
                ExitProcess(EXIT_FAILURE);
            }
            size = _vftprintf(stderr, frmt, args);
            if (size == -1) {
                _ftprintf(stderr, _T("Fatal error while writing log line to output : <errno:%x> <size:%u> <frmt:%s>"), errno, (DWORD)size, frmt);
                ExitProcess(EXIT_FAILURE);
            }
        }
        va_end(args);

        fflush(stderr);
    }
}
Exemple #17
0
static void iwcmd_vprint_native(struct params_struct *p, const TCHAR *fmt, va_list ap)
{
	_vftprintf(stdout,fmt,ap);
}
Exemple #18
0
BOOL DbgPrint(__in LPCTSTR lpszFormatString, ...)
{
	BOOL    bResult = TRUE;

	va_list VAList;
	va_start(VAList, lpszFormatString);

	if (g_bSaveLogFile)
	{
#if defined(DBG_THREADSAFE)
		OS_CAutoLock lock(s_mtxEntry);
#endif
		if (!s_bLogPathInit)
		{
			SYSTEMTIME stime = {0};			
			GetLocalTime(&stime);

#if defined(UNDER_CE)
			_stprintf(s_szLogFile, _T("%s\\log_%04d%02d%02d_%d.log"), g_bLogSavePath, stime.wYear, stime.wMonth, stime.wDay, GetTickCount());
#else
			_stprintf_s(s_szLogFile, MAX_PATH, _T("%s\\log_%04d%02d%02d_%d.log"), g_bLogSavePath, stime.wYear, stime.wMonth, stime.wDay, GetTickCount());
#endif
			s_bLogPathInit = true;
		}

		FILE* pFile = _tfopen(s_szLogFile, _T("a"));
		if (pFile != NULL)
		{
			fseek(pFile,SEEK_END,0);
			long cbSize = ftell(pFile);
			if (cbSize > MAX_LOG_FILE_SIZE)
			{
				fclose(pFile);
				{
					SYSTEMTIME stime = {0};			
					GetLocalTime(&stime);
#if defined(UNDER_CE)
					_stprintf(s_szLogFile, _T("%s\\log_%04d%02d%02d_%d.log"), g_bLogSavePath, stime.wYear, stime.wMonth, stime.wDay, GetTickCount());
#else
					_stprintf_s(s_szLogFile, MAX_PATH, _T("%s\\log_%04d%02d%02d_%d.log"), g_bLogSavePath, stime.wYear, stime.wMonth, stime.wDay, GetTickCount());
#endif
					s_bLogPathInit = true;
				}
				pFile = _tfopen(s_szLogFile, _T("a"));
				if (pFile == NULL)
				{
					return FALSE;
				}
			}
			_vftprintf(pFile, lpszFormatString, VAList);
			fflush(pFile);
			fclose(pFile);
			pFile = NULL;
		}
	}
	else
	{
#if defined(UNDER_CE)
		_vtprintf(lpszFormatString, VAList);
#else
		TCHAR szBuf[MAX_PATH * 2] = {0};
		_vstprintf_s(szBuf, MAX_PATH, lpszFormatString, VAList);
		OutputDebugString(szBuf);
#endif
	}
	va_end(VAList);

	return bResult;
}