void Log::PrintString(const tchar_t* string, Stream stream, Level level, Color color, int indent, tchar_t* output, uint32_t outputSize) { Helium::MutexScopeLock mutex (g_Mutex); // check trace files bool trace = false; M_OutputFile::iterator itr = g_TraceFiles.begin(); M_OutputFile::iterator end = g_TraceFiles.end(); for( ; itr != end; ++itr ) { if ( ( (*itr).second.m_StreamType & stream ) == stream && ( (*itr).second.m_ThreadId == -1 || (*itr).second.m_ThreadId == GetCurrentThreadID() ) ) { trace = true; } } // determine if we should be displayed bool display = ( g_Streams & stream ) == stream && level <= g_Level; // check for nothing to do if ( trace || display || output ) { if ( indent < 0 ) { indent = g_Indent; } // the statement Statement statement ( string, stream, level, indent ); // construct the print statement PrintingArgs args ( statement ); // is this statement to be output via normal channels if ( display ) { // raise the printing event g_PrintingEvent.Raise( args ); } // only process this string if it was not handled by a handler if ( !args.m_Skip ) { // apply indentation statement.m_String.clear(); statement.ApplyIndent( string, statement.m_String ); // output to screen window if ( display ) { // deduce the color if we were told to do so if ( color == Colors::Auto ) { color = GetStreamColor( stream ); } // print the statement to the window Helium::PrintString((Helium::ConsoleColor)color, stream == Streams::Error ? stderr : stdout, statement.m_String); // raise the printed event g_PrintedEvent.Raise( PrintedArgs (statement) ); } // send the text to the debugger, if no debugger nothing happens OutputDebugString(statement.m_String.c_str()); // output to trace file(s) static bool stampNewLine = true; itr = g_TraceFiles.begin(); end = g_TraceFiles.end(); for( ; itr != end; ++itr ) { if ( ( (*itr).second.m_StreamType & stream ) == stream && ( (*itr).second.m_ThreadId == -1 || (*itr).second.m_ThreadId == GetCurrentThreadID() ) ) { Redirect( (*itr).first, statement.m_String.c_str(), stampNewLine ); } } // update stampNewLine if ( !statement.m_String.empty() ) { stampNewLine = ( *statement.m_String.rbegin() == '\n' ) ? true : false ; } // output to buffer if (output && outputSize > 0) { _tcsncpy( output, statement.m_String.c_str(), outputSize - 1 ); } } } }