Index: src/liblogger/TAsyncMultiLogger.cpp =================================================================== diff -u -ra4635addad389b9e117679437a3e1b64a739ea96 -rdf9de596aad09b008aa076f8e5bb479f19c77259 --- src/liblogger/TAsyncMultiLogger.cpp (.../TAsyncMultiLogger.cpp) (revision a4635addad389b9e117679437a3e1b64a739ea96) +++ src/liblogger/TAsyncMultiLogger.cpp (.../TAsyncMultiLogger.cpp) (revision df9de596aad09b008aa076f8e5bb479f19c77259) @@ -21,6 +21,7 @@ #include #include #include +#include namespace logger { @@ -64,6 +65,8 @@ TLogFileDataPtr TAsyncMultiLogger::CreateLoggerData(PCTSTR pszLogPath, const TMultiLoggerConfigPtr& spLoggerConfig) { TLogFileDataPtr spLogFileData = std::make_shared(pszLogPath, spLoggerConfig, m_spGlobalRotationInfo); + if(!m_bLoggingEnabled) + spLogFileData->DisableLogging(); boost::unique_lock lock(m_mutex); m_setLoggerData.insert(spLogFileData); @@ -97,14 +100,14 @@ try { - std::vector vHandles; - bool bStopProcessing = false; do { + std::vector vHandles; + std::wstring strError; + { boost::unique_lock lock(pAsyncLogger->m_mutex); - vHandles.clear(); vHandles.push_back(pAsyncLogger->m_spStopEvent.get()); std::transform(pAsyncLogger->m_setLoggerData.begin(), pAsyncLogger->m_setLoggerData.end(), std::back_inserter(vHandles), [](const TLogFileDataPtr& rData) { return rData->GetEntriesEvent().get(); }); @@ -116,7 +119,17 @@ bStopProcessing = true; break; } + if(dwWaitResult == WAIT_FAILED) + { + DWORD dwLastError = GetLastError(); + _ASSERTE(dwLastError == ERROR_SUCCESS); + strError = boost::str(boost::wformat(L"Asynchronous logger critical failure: waiting failed with error %1%. Logging will be disabled until the application will be restarted.") % dwLastError); + pAsyncLogger->m_bLoggingEnabled = false; + + bStopProcessing = true; + } + std::vector vLogs; { boost::shared_lock lock(pAsyncLogger->m_mutex); @@ -127,6 +140,13 @@ { try { + // append emergency message + if(!strError.empty()) + { + spLogData->PushLogEntry(strError); + spLogData->DisableLogging(); + } + spLogData->StoreLogEntries(); spLogData->CloseUnusedFile(); } Index: src/liblogger/TAsyncMultiLogger.h =================================================================== diff -u -rd9527df01ee91b35d9a5fdccb80ded25a9c8265f -rdf9de596aad09b008aa076f8e5bb479f19c77259 --- src/liblogger/TAsyncMultiLogger.h (.../TAsyncMultiLogger.h) (revision d9527df01ee91b35d9a5fdccb80ded25a9c8265f) +++ src/liblogger/TAsyncMultiLogger.h (.../TAsyncMultiLogger.h) (revision df9de596aad09b008aa076f8e5bb479f19c77259) @@ -61,6 +61,7 @@ TLoggerRotationInfoPtr m_spGlobalRotationInfo; #pragma warning(pop) + bool m_bLoggingEnabled = true; }; } Index: src/liblogger/TLogFileData.cpp =================================================================== diff -u -re98c03b108baad889dfd7c7fbb1a49f5ea5a55d8 -rdf9de596aad09b008aa076f8e5bb479f19c77259 --- src/liblogger/TLogFileData.cpp (.../TLogFileData.cpp) (revision e98c03b108baad889dfd7c7fbb1a49f5ea5a55d8) +++ src/liblogger/TLogFileData.cpp (.../TLogFileData.cpp) (revision df9de596aad09b008aa076f8e5bb479f19c77259) @@ -53,6 +53,7 @@ { rLoggerPaths.Add(strPath.c_str()); } + rLoggerPaths.Add(m_spLogFile->GetLogPath().c_str()); } @@ -68,9 +69,14 @@ return m_spHasEntriesEvent; } + void TLogFileData::DisableLogging() + { + m_bLoggingEnabled = false; + } + void TLogFileData::PushLogEntry(std::wstring strLine) { - if(m_spLogFile) + if(m_spLogFile && m_bLoggingEnabled) { boost::unique_lock lock(m_mutex); m_listEntries.push_back(strLine); @@ -92,6 +98,8 @@ m_spLogFile->Write(listEntries); } + else + ResetEvent(m_spHasEntriesEvent.get()); } void TLogFileData::CloseUnusedFile() Index: src/liblogger/TLogFileData.h =================================================================== diff -u -re98c03b108baad889dfd7c7fbb1a49f5ea5a55d8 -rdf9de596aad09b008aa076f8e5bb479f19c77259 --- src/liblogger/TLogFileData.h (.../TLogFileData.h) (revision e98c03b108baad889dfd7c7fbb1a49f5ea5a55d8) +++ src/liblogger/TLogFileData.h (.../TLogFileData.h) (revision df9de596aad09b008aa076f8e5bb479f19c77259) @@ -43,6 +43,7 @@ private: void PushLogEntry(std::wstring strLine); + void DisableLogging(); std::shared_ptr GetEntriesEvent() const; void StoreLogEntries(); @@ -61,6 +62,8 @@ std::unique_ptr m_spLogFile; #pragma warning(pop) + bool m_bLoggingEnabled = true; + friend class TLogRecord; friend class TAsyncMultiLogger; };