예제 #1
0
void Redirect(const tstring& fileName, const tchar_t* str, bool stampNewLine = true )
{
    FILE* f = g_FileManager.Find(fileName);
    if (f)
    {
        if ( stampNewLine )
        {
            _timeb currentTime;
            _ftime( &currentTime );

            uint32_t time = (uint32_t) currentTime.time;
            uint32_t milli = currentTime.millitm;
            uint32_t sec = time % 60; time /= 60;
            uint32_t min = time % 60; time -= currentTime.timezone; time /= 60;
            time += currentTime.dstflag ? 1 : 0;
            uint32_t hour = time % 24;

            fprintf( f, "[%02d:%02d:%02d.%03d TID:%d] %s", hour, min, sec, milli, GetCurrentThreadId(), str );
        }
        else
        {
            fprintf( f, "%s", str );
        }

        fflush( f );
    }
}
예제 #2
0
void Redirect(const std::string& fileName, const char* str, bool stampNewLine = true )
{
	File* f = g_FileManager.Find(fileName);
	if (f)
	{
		size_t length = 0;
		size_t count = ( StringLength( str ) + 128 );
		char* temp = (char*)alloca( sizeof(char) * count );
		if ( stampNewLine )
		{
#if defined(HELIUM_OS_WIN)
			_timeb currentTime;
			_ftime( &currentTime );
#else
			struct timeb currentTime;
			ftime( &currentTime );
#endif

			uint32_t time = (uint32_t) currentTime.time;
			uint32_t milli = currentTime.millitm;
			uint32_t sec = time % 60; time /= 60;
			uint32_t min = time % 60; time -= currentTime.timezone; time /= 60;
			time += currentTime.dstflag ? 1 : 0;
			uint32_t hour = time % 24;

			length = StringPrint( temp, count, TXT("[%02d:%02d:%02d.%03d TID:%d] %s"), hour, min, sec, milli, Thread::GetCurrentId(), str );
		}
		else
		{
			length = StringPrint( temp, count, TXT("%s"), str );
		}

		f->Write( temp, length );
		f->Flush();
	}
}