Index: src/ch/OptionsDlg.cpp =================================================================== diff -u -rffbc773697bd08220163bf1e4491a34376b0f61c -r8f634460db3f225ca24f2e447b3730d4f0614166 --- src/ch/OptionsDlg.cpp (.../OptionsDlg.cpp) (revision ffbc773697bd08220163bf1e4491a34376b0f61c) +++ src/ch/OptionsDlg.cpp (.../OptionsDlg.cpp) (revision 8f634460db3f225ca24f2e447b3730d4f0614166) @@ -446,7 +446,7 @@ // log file SKIP_SEPARATOR(iPosition); SetPropValue(rConfig, GetUintProp(iPosition++)); - SetPropValue(rConfig, GetIndexProp(iPosition++)); + SetPropValue(rConfig, GetUintProp(iPosition++)); SetPropValue(rConfig, GetIndexProp(iPosition++)); SetPropValue(rConfig, GetIndexProp(iPosition++)); SetPropValue(rConfig, GetIndexProp(iPosition++)); Index: src/liblogger/SeverityLevels.h =================================================================== diff -u -r12b36349f6214befeace08efa9acc7e03be0d847 -r8f634460db3f225ca24f2e447b3730d4f0614166 --- src/liblogger/SeverityLevels.h (.../SeverityLevels.h) (revision 12b36349f6214befeace08efa9acc7e03be0d847) +++ src/liblogger/SeverityLevels.h (.../SeverityLevels.h) (revision 8f634460db3f225ca24f2e447b3730d4f0614166) @@ -21,7 +21,7 @@ namespace logger { - enum ESeverityLevel + enum ESeverityLevel : unsigned int { trace, debug, Index: src/liblogger/TAsyncMultiLogger.cpp =================================================================== diff -u -r12b36349f6214befeace08efa9acc7e03be0d847 -r8f634460db3f225ca24f2e447b3730d4f0614166 --- src/liblogger/TAsyncMultiLogger.cpp (.../TAsyncMultiLogger.cpp) (revision 12b36349f6214befeace08efa9acc7e03be0d847) +++ src/liblogger/TAsyncMultiLogger.cpp (.../TAsyncMultiLogger.cpp) (revision 8f634460db3f225ca24f2e447b3730d4f0614166) @@ -20,6 +20,7 @@ #include "TAsyncMultiLogger.h" #include #include +#include namespace logger { @@ -33,6 +34,8 @@ m_spStopEvent(CreateEvent(nullptr, TRUE, FALSE, nullptr), CloseHandle), m_spGlobalRotationInfo(std::make_shared()) { + if (!m_spStopEvent) + throw std::runtime_error("Cannot create stop event"); } void TAsyncMultiLogger::FinishLogging() @@ -75,15 +78,17 @@ return m_spGlobalRotationInfo; } - void TAsyncMultiLogger::SetRotationInfo(unsigned long long ullMaxLogSize, unsigned long ulMaxRotatedCount) + void TAsyncMultiLogger::SetRotationInfo(unsigned int uiMaxLogSize, unsigned int uiMaxRotatedCount) { - m_spGlobalRotationInfo->SetRotationInfo(ullMaxLogSize, ulMaxRotatedCount); + m_spGlobalRotationInfo->SetMaxLogSize(uiMaxLogSize); + m_spGlobalRotationInfo->SetRotatedCount(uiMaxRotatedCount); } void TAsyncMultiLogger::LoggingThread() { std::vector vHandles; + bool bStopProcessing = false; do { { @@ -96,7 +101,10 @@ DWORD dwWaitResult = WaitForMultipleObjectsEx(boost::numeric_cast(vHandles.size()), &vHandles[ 0 ], FALSE, 500, FALSE); if(dwWaitResult == WAIT_OBJECT_0) - return; + { + bStopProcessing = true; + break; + } std::vector vLogs; { @@ -106,11 +114,18 @@ for (const TLogFileDataPtr& spLogData : vLogs) { - spLogData->StoreLogEntries(); - spLogData->CloseUnusedFile(); + try + { + spLogData->StoreLogEntries(); + spLogData->CloseUnusedFile(); + } + catch (const std::exception& e) + { + ATLTRACE(e.what()); + } } } - while(true); + while(!bStopProcessing); } } Index: src/liblogger/TAsyncMultiLogger.h =================================================================== diff -u -r12b36349f6214befeace08efa9acc7e03be0d847 -r8f634460db3f225ca24f2e447b3730d4f0614166 --- src/liblogger/TAsyncMultiLogger.h (.../TAsyncMultiLogger.h) (revision 12b36349f6214befeace08efa9acc7e03be0d847) +++ src/liblogger/TAsyncMultiLogger.h (.../TAsyncMultiLogger.h) (revision 8f634460db3f225ca24f2e447b3730d4f0614166) @@ -42,7 +42,7 @@ TLogFileDataPtr CreateLoggerData(PCTSTR pszLogPath, const TMultiLoggerConfigPtr& spLoggerConfig); TLoggerRotationInfoPtr GetRotationInfo() const; - void SetRotationInfo(unsigned long long ullMaxLogSize, unsigned long ulMaxRotatedCount); + void SetRotationInfo(unsigned int uiMaxLogSize, unsigned int uiMaxRotatedCount); private: void LoggingThread(); Index: src/liblogger/TDateTimeFormatter.cpp =================================================================== diff -u -r12b36349f6214befeace08efa9acc7e03be0d847 -r8f634460db3f225ca24f2e447b3730d4f0614166 --- src/liblogger/TDateTimeFormatter.cpp (.../TDateTimeFormatter.cpp) (revision 12b36349f6214befeace08efa9acc7e03be0d847) +++ src/liblogger/TDateTimeFormatter.cpp (.../TDateTimeFormatter.cpp) (revision 8f634460db3f225ca24f2e447b3730d4f0614166) @@ -27,8 +27,8 @@ { boost::posix_time::ptime currentTime = boost::posix_time::microsec_clock::local_time(); std::wstringstream wss; - boost::posix_time::time_facet* facet = new boost::posix_time::time_facet(); - facet->format("%Y-%m-%d %H:%M:%S.%f"); + boost::posix_time::wtime_facet* facet = new boost::posix_time::wtime_facet(); + facet->format(L"%Y-%m-%d %H:%M:%S.%f"); wss.imbue(std::locale(std::locale::classic(), facet)); wss << currentTime; Index: src/liblogger/TLogFile.cpp =================================================================== diff -u -r12b36349f6214befeace08efa9acc7e03be0d847 -r8f634460db3f225ca24f2e447b3730d4f0614166 --- src/liblogger/TLogFile.cpp (.../TLogFile.cpp) (revision 12b36349f6214befeace08efa9acc7e03be0d847) +++ src/liblogger/TLogFile.cpp (.../TLogFile.cpp) (revision 8f634460db3f225ca24f2e447b3730d4f0614166) @@ -26,7 +26,7 @@ { TLogFile::TLogFile(PCTSTR pszPath, const TLoggerRotationInfoPtr& spRotationInfo) : m_strLogPath(pszPath), - m_spFileHandle(nullptr, CloseHandle), + m_spFileHandle(), m_spRotationInfo(spRotationInfo) { if(!pszPath) @@ -39,19 +39,27 @@ void TLogFile::Write(std::list& rListEntries) { - for (const std::wstring& rEntry : rListEntries) - { - size_t stEntryLen = rEntry.length() * sizeof(wchar_t); - if (NeedRotation(stEntryLen)) - RotateFile(); + if (rListEntries.empty()) + return; - DWORD dwWritten = 0; - if (!WriteFile(GetFileHandle(), rEntry.c_str(), boost::numeric_cast(stEntryLen), &dwWritten, nullptr)) + try + { + for (const std::wstring& rEntry : rListEntries) { - rListEntries.clear(); // get rid of the entries to not pile up indefinitely - throw std::runtime_error("Cannot write to file"); + size_t stEntryLen = rEntry.length() * sizeof(wchar_t); + if (NeedRotation(stEntryLen)) + RotateFile(); + + DWORD dwWritten = 0; + if (!WriteFile(GetFileHandle(), rEntry.c_str(), boost::numeric_cast(stEntryLen), &dwWritten, nullptr)) + throw std::runtime_error("Cannot write to log, system error"); } } + catch (const std::exception&) + { + rListEntries.clear(); + return; + } m_timeLastWriteTime = time(nullptr); rListEntries.clear(); @@ -105,17 +113,17 @@ if (boost::iends_with(pathNew, L".log")) pathNew.erase(pathNew.end() - 4, pathNew.end()); - boost::posix_time::ptime timeNow = boost::posix_time::second_clock::local_time(); - boost::posix_time::time_facet* facet = new boost::posix_time::time_facet(); - facet->format("%Y%m%d%H%M%S"); + boost::posix_time::ptime timeNow = boost::posix_time::microsec_clock::local_time(); + boost::posix_time::wtime_facet* facet = new boost::posix_time::wtime_facet(); + facet->format(L"%Y%m%d%H%M%S%f"); std::wstringstream stream; stream.imbue(std::locale(std::locale::classic(), facet)); - stream << time; + stream << timeNow; pathNew += L"."; pathNew += stream.str().c_str(); pathNew += L".log"; - if (!MoveFile(m_strLogPath.c_str(), pathNew.c_str())) + if (!MoveFile(m_strLogPath.c_str(), pathNew.c_str()) && GetLastError() != ERROR_FILE_NOT_FOUND) throw std::runtime_error("Cannot rotate file"); m_vRotatedFiles.push_back(std::move(pathNew)); @@ -160,7 +168,7 @@ bFound = FindNextFile(hFind, &wfd); } - std::sort(vPaths.begin(), vPaths.end(), [](const std::wstring& path1, const std::wstring& path2) { return boost::ilexicographical_compare(path2, path1); }); + std::sort(vPaths.begin(), vPaths.end(), [](const std::wstring& path1, const std::wstring& path2) { return boost::ilexicographical_compare(path1, path2); }); std::swap(m_vRotatedFiles, vPaths); } Index: src/liblogger/TLogFileData.cpp =================================================================== diff -u -r12b36349f6214befeace08efa9acc7e03be0d847 -r8f634460db3f225ca24f2e447b3730d4f0614166 --- src/liblogger/TLogFileData.cpp (.../TLogFileData.cpp) (revision 12b36349f6214befeace08efa9acc7e03be0d847) +++ src/liblogger/TLogFileData.cpp (.../TLogFileData.cpp) (revision 8f634460db3f225ca24f2e447b3730d4f0614166) @@ -21,16 +21,16 @@ namespace logger { - TLogFileData::TLogFileData(std::wstring pathLog, const TMultiLoggerConfigPtr& spLoggerConfig, const TLoggerRotationInfoPtr& spRotationInfo) : + TLogFileData::TLogFileData(PCTSTR pszLogPath, const TMultiLoggerConfigPtr& spLoggerConfig, const TLoggerRotationInfoPtr& spRotationInfo) : m_spHasEntriesEvent(CreateEvent(nullptr, TRUE, FALSE, nullptr), CloseHandle), m_spLoggerConfig(spLoggerConfig), - m_logFile(pathLog.c_str(), spRotationInfo) + m_logFile(pszLogPath, spRotationInfo) { if(m_spHasEntriesEvent.get() == INVALID_HANDLE_VALUE) throw std::runtime_error("Cannot create file data event"); } - TMultiLoggerConfigPtr TLogFileData::GetLoggerConfig() const + TMultiLoggerConfigPtr TLogFileData::GetMultiLoggerConfig() const { return m_spLoggerConfig; } Index: src/liblogger/TLogFileData.h =================================================================== diff -u -r12b36349f6214befeace08efa9acc7e03be0d847 -r8f634460db3f225ca24f2e447b3730d4f0614166 --- src/liblogger/TLogFileData.h (.../TLogFileData.h) (revision 12b36349f6214befeace08efa9acc7e03be0d847) +++ src/liblogger/TLogFileData.h (.../TLogFileData.h) (revision 8f634460db3f225ca24f2e447b3730d4f0614166) @@ -30,26 +30,29 @@ class TLogFileData { public: - TLogFileData(std::wstring pathLog, const TMultiLoggerConfigPtr& spLoggerConfig, const TLoggerRotationInfoPtr& spRotationInfo); + TLogFileData(PCTSTR pszLogPath, const TMultiLoggerConfigPtr& spLoggerConfig, const TLoggerRotationInfoPtr& spRotationInfo); - TMultiLoggerConfigPtr GetLoggerConfig() const; + TMultiLoggerConfigPtr GetMultiLoggerConfig() const; - //std::wstring GetLogPath() const; - std::shared_ptr GetEntriesEvent() const; - + private: void PushLogEntry(std::wstring strLine); + std::shared_ptr GetEntriesEvent() const; void StoreLogEntries(); void CloseUnusedFile(); private: std::list m_listEntries; boost::shared_mutex m_mutex; + std::shared_ptr m_spHasEntriesEvent; TMultiLoggerConfigPtr m_spLoggerConfig; TLogFile m_logFile; + + friend class TLogRecord; + friend class TAsyncMultiLogger; }; using TLogFileDataPtr = std::shared_ptr; Index: src/liblogger/TLogRecord.h =================================================================== diff -u -r12b36349f6214befeace08efa9acc7e03be0d847 -r8f634460db3f225ca24f2e447b3730d4f0614166 --- src/liblogger/TLogRecord.h (.../TLogRecord.h) (revision 12b36349f6214befeace08efa9acc7e03be0d847) +++ src/liblogger/TLogRecord.h (.../TLogRecord.h) (revision 8f634460db3f225ca24f2e447b3730d4f0614166) @@ -30,41 +30,50 @@ class TLogRecord : public std::wstringstream { public: + TLogRecord(const TLogFileDataPtr& spFileData, ESeverityLevel eLevel); TLogRecord(const TLogRecord&) = delete; - TLogRecord(TLogRecord&& rSrc) : - std::wstringstream(std::move(rSrc)), - m_spFileData(std::move(rSrc.m_spFileData)) - { - } + TLogRecord(TLogRecord&& rSrc); TLogRecord& operator=(const TLogRecord&) = delete; + TLogRecord& operator=(TLogRecord&&) = delete; - TLogRecord(const TLogFileDataPtr& spFileData, ESeverityLevel eLevel) : - m_spFileData(spFileData) - { - *this << TDateTimeFormatter::GetCurrentTime() << L" " << SeverityLevelToString(eLevel) << " "; - } + ~TLogRecord(); - ~TLogRecord() - { - *this << L"\r\n"; - m_spFileData->PushLogEntry(str()); - } + bool IsEnabled() const; + void Disable(); - bool IsEnabled() const - { - return m_bEnabled; - } - - void Disable() - { - m_bEnabled = false; - } - private: TLogFileDataPtr m_spFileData; bool m_bEnabled = true; }; + + inline TLogRecord::TLogRecord(TLogRecord&& rSrc) : + std::wstringstream(std::move(rSrc)), + m_spFileData(std::move(rSrc.m_spFileData)) + { + } + + inline TLogRecord::TLogRecord(const TLogFileDataPtr& spFileData, ESeverityLevel eLevel) : + m_spFileData(spFileData) + { + *this << TDateTimeFormatter::GetCurrentTime() << L" " << SeverityLevelToString(eLevel) << L" "; + } + + inline TLogRecord::~TLogRecord() + { + *this << L"\r\n"; + m_spFileData->PushLogEntry(str()); + } + + inline bool TLogRecord::IsEnabled() const + { + return m_bEnabled; + } + + inline void TLogRecord::Disable() + { + m_bEnabled = false; + } } #endif Index: src/liblogger/TLogger.cpp =================================================================== diff -u -r12b36349f6214befeace08efa9acc7e03be0d847 -r8f634460db3f225ca24f2e447b3730d4f0614166 --- src/liblogger/TLogger.cpp (.../TLogger.cpp) (revision 12b36349f6214befeace08efa9acc7e03be0d847) +++ src/liblogger/TLogger.cpp (.../TLogger.cpp) (revision 8f634460db3f225ca24f2e447b3730d4f0614166) @@ -24,7 +24,7 @@ { TLogger::TLogger(const TLogFileDataPtr& spFileData, PCTSTR pszChannel) : m_spFileData(spFileData), - m_spLoggerConfig(spFileData->GetLoggerConfig()->GetLoggerConfig(pszChannel)), + m_spLoggerConfig(spFileData->GetMultiLoggerConfig()->GetLoggerConfig(pszChannel)), m_strChannel(pszChannel) { if (!spFileData) Index: src/liblogger/TLogger.h =================================================================== diff -u -r12b36349f6214befeace08efa9acc7e03be0d847 -r8f634460db3f225ca24f2e447b3730d4f0614166 --- src/liblogger/TLogger.h (.../TLogger.h) (revision 12b36349f6214befeace08efa9acc7e03be0d847) +++ src/liblogger/TLogger.h (.../TLogger.h) (revision 8f634460db3f225ca24f2e447b3730d4f0614166) @@ -28,6 +28,7 @@ namespace logger { + // do not export class TLogger { public: Index: src/liblogger/TLoggerLevelConfig.cpp =================================================================== diff -u -r12b36349f6214befeace08efa9acc7e03be0d847 -r8f634460db3f225ca24f2e447b3730d4f0614166 --- src/liblogger/TLoggerLevelConfig.cpp (.../TLoggerLevelConfig.cpp) (revision 12b36349f6214befeace08efa9acc7e03be0d847) +++ src/liblogger/TLoggerLevelConfig.cpp (.../TLoggerLevelConfig.cpp) (revision 8f634460db3f225ca24f2e447b3730d4f0614166) @@ -18,24 +18,21 @@ // ============================================================================ #include "stdafx.h" #include "TLoggerLevelConfig.h" -#include namespace logger { TLoggerLevelConfig::TLoggerLevelConfig(ESeverityLevel eMinSeverity) : - m_eMinSeverity(eMinSeverity) + m_uiMinSeverity(eMinSeverity) { } void TLoggerLevelConfig::SetMinSeverityLevel(ESeverityLevel eLevel) { - boost::unique_lock lock; - m_eMinSeverity = eLevel; + InterlockedExchange(&m_uiMinSeverity, eLevel); } ESeverityLevel TLoggerLevelConfig::GetMinSeverityLevel() const { - boost::shared_lock lock; - return m_eMinSeverity; + return (ESeverityLevel)InterlockedCompareExchange(&m_uiMinSeverity, 0, 0); } } Index: src/liblogger/TLoggerLevelConfig.h =================================================================== diff -u -r12b36349f6214befeace08efa9acc7e03be0d847 -r8f634460db3f225ca24f2e447b3730d4f0614166 --- src/liblogger/TLoggerLevelConfig.h (.../TLoggerLevelConfig.h) (revision 12b36349f6214befeace08efa9acc7e03be0d847) +++ src/liblogger/TLoggerLevelConfig.h (.../TLoggerLevelConfig.h) (revision 8f634460db3f225ca24f2e447b3730d4f0614166) @@ -33,8 +33,7 @@ ESeverityLevel GetMinSeverityLevel() const; private: - ESeverityLevel m_eMinSeverity = trace; - boost::shared_mutex m_mutex; + volatile mutable unsigned int m_uiMinSeverity = trace; }; using TLoggerLevelConfigPtr = std::shared_ptr; Index: src/liblogger/TLoggerRotationInfo.cpp =================================================================== diff -u -r12b36349f6214befeace08efa9acc7e03be0d847 -r8f634460db3f225ca24f2e447b3730d4f0614166 --- src/liblogger/TLoggerRotationInfo.cpp (.../TLoggerRotationInfo.cpp) (revision 12b36349f6214befeace08efa9acc7e03be0d847) +++ src/liblogger/TLoggerRotationInfo.cpp (.../TLoggerRotationInfo.cpp) (revision 8f634460db3f225ca24f2e447b3730d4f0614166) @@ -18,43 +18,36 @@ // ============================================================================ #include "stdafx.h" #include "TLoggerRotationInfo.h" -#include namespace logger { TLoggerRotationInfo::TLoggerRotationInfo() { } - TLoggerRotationInfo::TLoggerRotationInfo(unsigned long long ullMaxLogSize, unsigned long ulMaxRotatedCount) : - m_ullMaxLogSize(ullMaxLogSize), - m_ulMaxRotatedCount(ulMaxRotatedCount) + TLoggerRotationInfo::TLoggerRotationInfo(unsigned int uiMaxLogSize, unsigned int uiMaxRotatedCount) : + m_uiMaxLogSize(uiMaxLogSize), + m_uiMaxRotatedCount(uiMaxRotatedCount) { } - void TLoggerRotationInfo::SetRotationInfo(unsigned long long ullMaxLogSize, unsigned long ulMaxRotatedCount) + void TLoggerRotationInfo::SetMaxLogSize(unsigned int uiMaxLogSize) { - boost::unique_lock lock(m_mutex); - m_ullMaxLogSize = ullMaxLogSize; - m_ulMaxRotatedCount = ulMaxRotatedCount; + InterlockedExchange(&m_uiMaxLogSize, uiMaxLogSize); } - void TLoggerRotationInfo::GetRotationInfo(unsigned long long& ullMaxLogSize, unsigned long& ulMaxRotatedCount) const + void TLoggerRotationInfo::SetRotatedCount(unsigned int uiMaxRotatedCount) { - boost::shared_lock lock(m_mutex); - ullMaxLogSize = m_ullMaxLogSize; - ulMaxRotatedCount = m_ulMaxRotatedCount; + InterlockedExchange(&m_uiMaxRotatedCount, uiMaxRotatedCount); } - unsigned long long TLoggerRotationInfo::GetMaxLogSize() const + unsigned int TLoggerRotationInfo::GetMaxLogSize() const { - boost::shared_lock lock(m_mutex); - return m_ullMaxLogSize; + return InterlockedCompareExchange(&m_uiMaxLogSize, 0, 0); } - unsigned long TLoggerRotationInfo::GetMaxRotatedCount() const + unsigned int TLoggerRotationInfo::GetMaxRotatedCount() const { - boost::shared_lock lock(m_mutex); - return m_ulMaxRotatedCount; + return InterlockedCompareExchange(&m_uiMaxRotatedCount, 0, 0); } } Index: src/liblogger/TLoggerRotationInfo.h =================================================================== diff -u -r12b36349f6214befeace08efa9acc7e03be0d847 -r8f634460db3f225ca24f2e447b3730d4f0614166 --- src/liblogger/TLoggerRotationInfo.h (.../TLoggerRotationInfo.h) (revision 12b36349f6214befeace08efa9acc7e03be0d847) +++ src/liblogger/TLoggerRotationInfo.h (.../TLoggerRotationInfo.h) (revision 8f634460db3f225ca24f2e447b3730d4f0614166) @@ -26,23 +26,22 @@ class TLoggerRotationInfo { public: - static const unsigned long long DefaultMaxLogSize = 10 * 1024 * 1024; - static const unsigned long DefaultMaxRotatedFiles = 5; + static const unsigned int DefaultMaxLogSize = 10 * 1024 * 1024; + static const unsigned int DefaultMaxRotatedFiles = 5; public: TLoggerRotationInfo(); - TLoggerRotationInfo(unsigned long long ullMaxLogSize, unsigned long ulMaxRotatedCount); + TLoggerRotationInfo(unsigned int uiMaxLogSize, unsigned int uiMaxRotatedCount); - void SetRotationInfo(unsigned long long ullMaxLogSize, unsigned long ulMaxRotatedCount); - void GetRotationInfo(unsigned long long& ullMaxLogSize, unsigned long& ulMaxRotatedCount) const; + void SetMaxLogSize(unsigned int uiMaxLogSize); + void SetRotatedCount(unsigned int uiMaxRotatedCount); - unsigned long long GetMaxLogSize() const; - unsigned long GetMaxRotatedCount() const; + unsigned int GetMaxLogSize() const; + unsigned int GetMaxRotatedCount() const; private: - unsigned long long m_ullMaxLogSize = 1024 * 1024; - unsigned long m_ulMaxRotatedCount = 5; - mutable boost::shared_mutex m_mutex; + volatile mutable unsigned int m_uiMaxLogSize = DefaultMaxLogSize; + volatile mutable unsigned int m_uiMaxRotatedCount = DefaultMaxRotatedFiles; }; using TLoggerRotationInfoPtr = std::shared_ptr; Index: src/liblogger/TMultiLoggerConfig.cpp =================================================================== diff -u -r12b36349f6214befeace08efa9acc7e03be0d847 -r8f634460db3f225ca24f2e447b3730d4f0614166 --- src/liblogger/TMultiLoggerConfig.cpp (.../TMultiLoggerConfig.cpp) (revision 12b36349f6214befeace08efa9acc7e03be0d847) +++ src/liblogger/TMultiLoggerConfig.cpp (.../TMultiLoggerConfig.cpp) (revision 8f634460db3f225ca24f2e447b3730d4f0614166) @@ -24,19 +24,7 @@ TLoggerLevelConfigPtr TMultiLoggerConfig::GetLoggerConfig(PCTSTR pszChannel, bool bForceAdd) { boost::upgrade_lock lock(m_mutex); - auto iterConfig = m_mapConfigs.find(pszChannel); - if (iterConfig == m_mapConfigs.end()) - { - if (bForceAdd) - { - boost::upgrade_to_unique_lock upgraded_lock(lock); - iterConfig = m_mapConfigs.insert(std::make_pair(pszChannel, std::make_shared())).first; - } - else - return GetLoggerConfig(lock, L"default", true); - } - - return iterConfig->second; + return GetLoggerConfig(lock, pszChannel, bForceAdd); } TLoggerLevelConfigPtr TMultiLoggerConfig::GetLoggerConfig(boost::upgrade_lock& lock, PCTSTR pszChannel, bool bForceAdd) @@ -50,7 +38,7 @@ iterConfig = m_mapConfigs.insert(std::make_pair(pszChannel, std::make_shared())).first; } else - return GetLoggerConfig(L"default", true); + return GetLoggerConfig(lock, L"default", true); } return iterConfig->second;