Index: src/common/TMultiFileBackend.cpp =================================================================== diff -u -N -rb8b97b70743c49fcc2aee0db4cb7118db5e26dab -r3f15d095b6b6692c9c9c469f979b9798f448b7c6 --- src/common/TMultiFileBackend.cpp (.../TMultiFileBackend.cpp) (revision b8b97b70743c49fcc2aee0db4cb7118db5e26dab) +++ src/common/TMultiFileBackend.cpp (.../TMultiFileBackend.cpp) (revision 3f15d095b6b6692c9c9c469f979b9798f448b7c6) @@ -1,95 +1,95 @@ -// ============================================================================ -// Copyright (C) 2001-2016 by Jozef Starosczyk -// ixen@copyhandler.com -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU Library General Public License -// (version 2) as published by the Free Software Foundation; -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this program; if not, write to the -// Free Software Foundation, Inc., -// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// ============================================================================ -#include "stdafx.h" -#include "TMultiFileBackend.h" -#include "..\libchcore\TTimestampProviderTickCount.h" -#include +// ============================================================================ +// Copyright (C) 2001-2016 by Jozef Starosczyk +// ixen@copyhandler.com +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Library General Public License +// (version 2) as published by the Free Software Foundation; +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// ============================================================================ +#include "stdafx.h" +#include "TMultiFileBackend.h" +#include "..\libchcore\TTimestampProviderTickCount.h" +#include #include -#include -#include -#include -#include "..\libchcore\TStringArray.h" -#include "TLoggerLocationConfig.h" - -namespace chcore -{ - TMultiFileBackend::TMultiFileBackend(ITimestampProviderPtr spTimestampProvider, unsigned int uiMaxRotatedFiles, unsigned long long ullMaxLogSize) : - m_spTimestampProvider(spTimestampProvider), - m_logRotator(uiMaxRotatedFiles, ullMaxLogSize) - { - if (!m_spTimestampProvider) - m_spTimestampProvider.reset(new TTimestampProviderTickCount); - } - - void TMultiFileBackend::Init(const TSmartPath& pathDirectory, unsigned int uiMaxRotatedFiles, unsigned long long ullMaxLogSize) - { - SetDirectory(pathDirectory); - m_logRotator.SetLimits(uiMaxRotatedFiles, ullMaxLogSize); - } - - void TMultiFileBackend::consume(const boost::log::record_view& rec, const string_type& formatted_message) - { - if (!m_bInitialized) - return; - - TSmartPath pathLog = GetLogName(rec); - if (pathLog.IsEmpty()) - return; - - TLogSink& sinkData = m_mapLogs.GetSinkData(pathLog); - - HANDLE hFile = GetLogFile(pathLog, sinkData, formatted_message.length()); - if (hFile == INVALID_HANDLE_VALUE) - return; - - string_type strFullMessage = formatted_message + "\n"; - - DWORD dwToWrite = boost::numeric_cast(strFullMessage.length()); - DWORD dwWritten = 0; - WriteFile(hFile, strFullMessage.c_str(), dwToWrite, &dwWritten, nullptr); - } - - TSmartPath TMultiFileBackend::GetLogName(const boost::log::record_view &rec) - { - auto attrLogPath = rec.attribute_values().find("LogPath"); - if (attrLogPath == rec.attribute_values().end()) - return TSmartPath(); - - boost::log::value_ref val = boost::log::extract(attrLogPath->second); - if (!val) - return TSmartPath(); - - return val.get()->GetLogPath(); - } - - HANDLE TMultiFileBackend::GetLogFile(const TSmartPath& pathLog, TLogSink& sinkData, size_t stRequiredSpace) - { - m_logRotator.RotateFile(pathLog, sinkData, stRequiredSpace); - - return sinkData.GetFileHandle(); - } - - void TMultiFileBackend::SetDirectory(const TSmartPath& pathDirectory) - { - m_mapLogs.Clear(); - m_logRotator.ScanForLogs(pathDirectory, m_mapLogs); - m_bInitialized = true; - } - -} +#include +#include +#include +#include "..\libchcore\TStringArray.h" +#include "TLoggerLocationConfig.h" + +namespace chcore +{ + TMultiFileBackend::TMultiFileBackend(ITimestampProviderPtr spTimestampProvider, unsigned int uiMaxRotatedFiles, unsigned long long ullMaxLogSize) : + m_spTimestampProvider(spTimestampProvider), + m_logRotator(uiMaxRotatedFiles, ullMaxLogSize) + { + if (!m_spTimestampProvider) + m_spTimestampProvider.reset(new TTimestampProviderTickCount); + } + + void TMultiFileBackend::Init(const TSmartPath& pathDirectory, unsigned int uiMaxRotatedFiles, unsigned long long ullMaxLogSize) + { + SetDirectory(pathDirectory); + m_logRotator.SetLimits(uiMaxRotatedFiles, ullMaxLogSize); + } + + void TMultiFileBackend::consume(const boost::log::record_view& rec, const string_type& formatted_message) + { + if (!m_bInitialized) + return; + + TSmartPath pathLog = GetLogName(rec); + if (pathLog.IsEmpty()) + return; + + TLogSink& sinkData = m_mapLogs.GetSinkData(pathLog); + + HANDLE hFile = GetLogFile(pathLog, sinkData, formatted_message.length()); + if (hFile == INVALID_HANDLE_VALUE) + return; + + string_type strFullMessage = formatted_message + "\r\n"; + + DWORD dwToWrite = boost::numeric_cast(strFullMessage.length()); + DWORD dwWritten = 0; + WriteFile(hFile, strFullMessage.c_str(), dwToWrite, &dwWritten, nullptr); + } + + TSmartPath TMultiFileBackend::GetLogName(const boost::log::record_view &rec) + { + auto attrLogPath = rec.attribute_values().find("LogPath"); + if (attrLogPath == rec.attribute_values().end()) + return TSmartPath(); + + boost::log::value_ref val = boost::log::extract(attrLogPath->second); + if (!val) + return TSmartPath(); + + return val.get()->GetLogPath(); + } + + HANDLE TMultiFileBackend::GetLogFile(const TSmartPath& pathLog, TLogSink& sinkData, size_t stRequiredSpace) + { + m_logRotator.RotateFile(pathLog, sinkData, stRequiredSpace); + + return sinkData.GetFileHandle(); + } + + void TMultiFileBackend::SetDirectory(const TSmartPath& pathDirectory) + { + m_mapLogs.Clear(); + m_logRotator.ScanForLogs(pathDirectory, m_mapLogs); + m_bInitialized = true; + } + +} Index: src/libchcore/Tests/TestsTTaskConfigVerifier.cpp =================================================================== diff -u -N -r62d767936f1675e1db51174f53c91484fe691937 -r3f15d095b6b6692c9c9c469f979b9798f448b7c6 --- src/libchcore/Tests/TestsTTaskConfigVerifier.cpp (.../TestsTTaskConfigVerifier.cpp) (revision 62d767936f1675e1db51174f53c91484fe691937) +++ src/libchcore/Tests/TestsTTaskConfigVerifier.cpp (.../TestsTTaskConfigVerifier.cpp) (revision 3f15d095b6b6692c9c9c469f979b9798f448b7c6) @@ -1,7 +1,6 @@ #include "stdafx.h" #include "gtest/gtest.h" #include "../TConfig.h" -#include "../log.h" #include "../TTaskConfiguration.h" #include "../TTaskConfigVerifier.h"