Index: src/ch/AsyncHttpFile.cpp =================================================================== diff -u -r8068e0c351055554340ac9755d1bc846893bf2b8 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/ch/AsyncHttpFile.cpp (.../AsyncHttpFile.cpp) (revision 8068e0c351055554340ac9755d1bc846893bf2b8) +++ src/ch/AsyncHttpFile.cpp (.../AsyncHttpFile.cpp) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -18,6 +18,8 @@ // ============================================================================ #include "stdafx.h" #include "AsyncHttpFile.h" +#include "../common/TLogger.h" +#include "ch.h" // timeout used with waiting for events (avoiding hangs) #define FORCE_TIMEOUT 60000 @@ -355,7 +357,7 @@ strMsg.Format(_T("[CAsyncHttpFile::InternetStatusCallback] hInternet: %p, dwContext: %Iu (operation: %lu), dwInternetStatus: %lu, lpvStatusInformation: %p, dwStatusInformationLength: %lu\n"), hInternet, (size_t)dwContext, pRequest->eOperationType, dwInternetStatus, lpvStatusInformation, dwStatusInformationLength); ATLTRACE(L"%s\n", strMsg); - LOG_DEBUG(strMsg); + LOG_DEBUG(GetLogger()) << strMsg; switch(dwInternetStatus) { Index: src/ch/MainWnd.cpp =================================================================== diff -u -r8068e0c351055554340ac9755d1bc846893bf2b8 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision 8068e0c351055554340ac9755d1bc846893bf2b8) +++ src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -188,7 +188,7 @@ if(!LoadTaskManager()) { - LOG_ERROR(_T("Couldn't load task manager data. User did not allow re-creation of the database.")); + LOG_ERROR(GetLogger()) << _T("Couldn't load task manager data. User did not allow re-creation of the database."); return -1; } @@ -200,7 +200,7 @@ m_spTasks->TasksRetryProcessing(); // start clipboard monitoring - LOG_INFO(_T("Starting clipboard monitor...")); + LOG_INFO(GetLogger()) << _T("Starting clipboard monitor..."); CClipboardMonitor::StartMonitor(m_spTasks); CheckForUpdates(); @@ -229,7 +229,7 @@ if(bCaughtError) { - LOG_ERROR(szErrInfo.get()); + LOG_ERROR(GetLogger()) << szErrInfo.get(); return -1; } return 0; @@ -264,7 +264,7 @@ } // load last state - LOG_INFO(_T("Loading existing tasks...")); + LOG_INFO(GetLogger()) << _T("Loading existing tasks..."); // load tasks m_spTasks->Load(); @@ -405,7 +405,7 @@ if(!strMessage.IsEmpty()) { - LOG_ERROR(L"Failed to finalize tasks before exiting Copy Handler. Error: " + strMessage); + LOG_ERROR(GetLogger()) << L"Failed to finalize tasks before exiting Copy Handler. Error: " + strMessage; ictranslate::CFormat fmt; @@ -437,7 +437,7 @@ fmt.SetFormat(_T("Failed to autosave task. Error: %err.")); fmt.SetParam(_T("%err"), (PCTSTR)strError); - LOG_ERROR(fmt); + LOG_ERROR(GetLogger()) << fmt; } SetTimer(1023, GetPropValue(GetConfig()), nullptr); @@ -518,7 +518,7 @@ fmt.SetParam(_T("%xml"), wstrData.c_str()); fmt.SetParam(_T("%err"), (PCTSTR)strError); - LOG_ERROR(fmt); + LOG_ERROR(GetLogger()) << fmt; fmt.SetFormat(GetResManager().LoadString(IDS_SHELLEXT_XML_IMPORT_FAILED)); fmt.SetParam(_T("%err"), (PCTSTR)strError); @@ -628,7 +628,7 @@ fmt.SetParam(_T("%path"), strPath.ToString()); fmt.SetParam(_T("%err"), szBuffer.get()); - LOG_ERROR(fmt); + LOG_ERROR(GetLogger()) << fmt; fmt.SetFormat(GetResManager().LoadString(IDS_TASK_IMPORT_FAILED)); fmt.SetParam(_T("%path"), strPath.ToString()); @@ -899,7 +899,7 @@ _ASSERTE(FALSE); CString strMsg; strMsg.Format(L"Encountered problem trying to retrieve shell ext configuration.\nReason: %S", e.what()); - LOG_ERROR(strMsg); + LOG_ERROR(GetLogger()) << strMsg; return FALSE; } @@ -1062,7 +1062,7 @@ // perform checking for updates only when the minimal interval has passed if(ullCurrentStamp - ullTimestamp >= ullMinInterval) { - LOG_INFO(_T("Checking for updates...")); + LOG_INFO(GetLogger()) << _T("Checking for updates..."); CUpdaterDlg* pDlg = new CUpdaterDlg(true); pDlg->m_bAutoDelete = true; @@ -1076,7 +1076,7 @@ } catch(const std::exception& /*e*/) { - LOG_ERROR(_T("Storing last update check timestamp in configuration failed")); + LOG_ERROR(GetLogger()) << _T("Storing last update check timestamp in configuration failed"); } } } Index: src/ch/Stdafx.h =================================================================== diff -u -r4fe995b304ea342b50293f92d3c1992b43b820f7 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/ch/Stdafx.h (.../Stdafx.h) (revision 4fe995b304ea342b50293f92d3c1992b43b820f7) +++ src/ch/Stdafx.h (.../Stdafx.h) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -50,7 +50,6 @@ #include "debug.h" #include "../libictranslate/LanguageDialog.h" -#include "../libchcore/TLogger.h" #include "../libchcore/TConfigSerializers.h" #ifdef _UNICODE Index: src/ch/UpdaterDlg.cpp =================================================================== diff -u -r4797e4b6b266900bfdcdf4ca6eda47c216ad9db1 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/ch/UpdaterDlg.cpp (.../UpdaterDlg.cpp) (revision 4797e4b6b266900bfdcdf4ca6eda47c216ad9db1) +++ src/ch/UpdaterDlg.cpp (.../UpdaterDlg.cpp) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -10,9 +10,9 @@ #include #include #include "WindowsVersion.h" -#include "../libchcore/TLogger.h" #include "resource.h" #include "CfgProperties.h" +#include "../common/TLogger.h" #define UPDATER_TIMER 639 @@ -87,13 +87,13 @@ { CString str; str.Format(_T("Opening a browser with address %s..."), (PCTSTR)strDownloadAddr); - LOG_DEBUG(str); + LOG_DEBUG(GetLogger()) << str; str.Format(_T("url.dll,FileProtocolHandler %s"), (PCTSTR)strDownloadAddr); ULONG_PTR ulRes = (ULONG_PTR)ShellExecute(nullptr, _T("open"), _T("rundll32.exe"), str, nullptr, SW_SHOW); str.Format(_T("ShellExecute returned %I64u"), (unsigned long long)ulRes); - LOG_DEBUG(str); + LOG_DEBUG(GetLogger()) << str; // close the dialog if succeeded; 32 is some arbitrary value from ms docs if(ulRes > 32) @@ -389,7 +389,7 @@ if(!strError.IsEmpty()) { - LOG_ERROR(strError); + LOG_ERROR(GetLogger()) << strError; } } Index: src/ch/ch.cpp =================================================================== diff -u -r8068e0c351055554340ac9755d1bc846893bf2b8 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/ch/ch.cpp (.../ch.cpp) (revision 8068e0c351055554340ac9755d1bc846893bf2b8) +++ src/ch/ch.cpp (.../ch.cpp) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -43,6 +43,7 @@ #include "TMsgBox.h" #include "../libchcore/TWin32ErrorFormatter.h" #include "resource.h" +#include "../common/TLogger.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -97,7 +98,8 @@ } CCopyHandlerApp::CCopyHandlerApp() : - m_pMainWindow(nullptr) + m_pMainWindow(nullptr), + m_log(L"CH") { // this is the one-instance application InitProtection(); @@ -113,17 +115,17 @@ } } -CCopyHandlerApp& GetApp() +CCopyHandlerApp& GetApplication() { return theApp; } -ictranslate::CResourceManager& GetResManager() +ictranslate::CResourceManager& CCopyHandlerApp::GetResManager() { return ictranslate::CResourceManager::Acquire(); } -chcore::TConfig& GetConfig() +chcore::TConfig& CCopyHandlerApp::GetConfig() { static chcore::TConfig tCfg; return tCfg; @@ -281,7 +283,6 @@ // ================================= Configuration ======================================== CString strPath; CString strCfgPath; - CString strLogPath; // note that the GetProgramDataPath() below should create a directory; ExpandPath() could // depend on the directory to be created earlier @@ -308,38 +309,29 @@ // ================================= Logging ======================================== // initialize the global log file if it is requested by configuration file - strLogPath = strPath + _T("\\ch.log"); + CString strLogPath = strPath + _T("\\ch.log"); - chcore::TLogger& rLogger = chcore::TLogger::Acquire(); - try - { - rLogger.init(strLogPath, GetPropValue(rCfg), GetPropValue(rCfg), false, false); - rLogger.Enable(GetPropValue(rCfg)); - } - catch(...) - { - BOOST_ASSERT(false); - } + m_log.SetLogPath(strLogPath); - LOG_INFO(_T("============================ Initializing Copy Handler ============================")); - LOG_INFO(_T("")); + LOG_INFO(m_log) << _T("============================ Initializing Copy Handler ============================"); + LOG_INFO(m_log) << _T(""); // ================================= COM ======================================== - LOG_INFO(_T("Initializing COM")); + LOG_INFO(m_log) << _T("Initializing COM"); HRESULT hResult = CoInitializeEx(nullptr, COINIT_MULTITHREADED); if(FAILED(hResult)) { CString strMsg; strMsg.Format(_T("Cannot initialize COM, the application will now exit (result = 0x%lx)"), hResult); - LOG_ERROR(strMsg); + LOG_ERROR(m_log) << strMsg; AfxMessageBox(strMsg, MB_ICONERROR | MB_OK); return FALSE; } // ================================= Resource manager ======================================== - LOG_INFO(_T("Initializing resource manager...")); + LOG_INFO(m_log) << _T("Initializing resource manager..."); ictranslate::CResourceManager& rResManager = ictranslate::CResourceManager::Acquire(); @@ -352,7 +344,7 @@ { TCHAR szData[2048]; _sntprintf(szData, 2048, _T("Couldn't find the language file specified in configuration file:\n%s\nPlease correct this path to point the language file to use.\nProgram will now exit."), (PCTSTR)strPath); - LOG_ERROR(szData); + LOG_ERROR(m_log) << szData; AfxMessageBox(szData, MB_ICONSTOP | MB_OK); return FALSE; } @@ -377,7 +369,7 @@ // ================================= Checking for running instances of CH ======================================== // check instance - return false if it's the second one - LOG_INFO(_T("Checking for other running instances of Copy Handler")); + LOG_INFO(m_log) << _T("Checking for other running instances of Copy Handler"); if(!IsFirstInstance()) { // if there is a command line specified, send it to the existing instance @@ -387,7 +379,7 @@ if(hWnd == nullptr) { // cannot pass command line to running ch - LOG_ERROR(_T("Cannot determine running CH's window. Cannot pass command line there.")); + LOG_ERROR(m_log) << _T("Cannot determine running CH's window. Cannot pass command line there."); MsgBox(IDS_COMMAND_LINE_FAILED_STRING, MB_OK | MB_ICONERROR); return FALSE; } @@ -402,22 +394,22 @@ // send a message to ch if(::SendMessage(hWnd, WM_COPYDATA, 0, reinterpret_cast(&cds)) == 0) { - LOG_ERROR(_T("Command line was not processed properly at the running CH's instance.")); + LOG_ERROR(m_log) << _T("Command line was not processed properly at the running CH's instance."); MsgBox(IDS_COMMAND_LINE_FAILED_STRING, MB_OK | MB_ICONERROR); } return FALSE; } else { - LOG_WARNING(_T("Other instance of Copy Handler is already running. Exiting.")); + LOG_WARNING(m_log) << _T("Other instance of Copy Handler is already running. Exiting."); MsgBox(IDS_ONECOPY_STRING, MB_OK | MB_ICONWARNING); return FALSE; } } // ================================= Common controls ======================================== - LOG_INFO(_T("Initializing GUI common controls")); + LOG_INFO(m_log) << _T("Initializing GUI common controls"); // InitCommonControlsEx() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable @@ -429,25 +421,25 @@ InitCtrls.dwICC = ICC_WIN95_CLASSES; if(!InitCommonControlsEx(&InitCtrls)) { - LOG_ERROR(_T("Cannot initialize common controls.")); + LOG_ERROR(m_log) << _T("Cannot initialize common controls."); MsgBox(IDS_ERROR_INITIALIZING_COMMON_CONTROLS, MB_OK | MB_ICONERROR); return FALSE; } if(!AfxInitRichEdit2()) { - LOG_ERROR(_T("Cannot initialize rich edit control.")); + LOG_ERROR(m_log) << _T("Cannot initialize rich edit control."); MsgBox(IDS_ERROR_INITIALIZING_RICH_EDIT_CONTROL, MB_OK | MB_ICONERROR); return FALSE; } // ================================= Shell extension ======================================== - LOG_INFO(_T("Checking shell extension compatibility")); + LOG_INFO(m_log) << _T("Checking shell extension compatibility"); InitShellExtension(); // ================================= Initial settings ======================================== - LOG_INFO(_T("Applying initial settings")); + LOG_INFO(m_log) << _T("Applying initial settings"); // set this process priority class HANDLE hProcess = GetCurrentProcess(); @@ -459,7 +451,7 @@ #endif // ================================= Main window ======================================== - LOG_INFO(_T("Creating main application window")); + LOG_INFO(m_log) << _T("Creating main application window"); // create main window m_pMainWindow=new CMainWnd; if (!((CMainWnd*)m_pMainWindow)->Create()) @@ -468,7 +460,7 @@ m_pMainWnd = m_pMainWindow; CWinApp::InitInstance(); - LOG_INFO(_T("Copy Handler initialized successfully")); + LOG_INFO(m_log) << _T("Copy Handler initialized successfully"); return TRUE; #endif @@ -517,7 +509,7 @@ { CString strMsg; strMsg.Format(_T("Shell extension is not registered.")); - LOG_WARNING(strMsg); + LOG_WARNING(m_log) << strMsg; switch(iDoNotShowAgain_Unregistered) { @@ -542,7 +534,7 @@ { CString strMsg; strMsg.Format(_T("Shell extension has different version (0x%lx) than Copy Handler (0x%lx)."), (unsigned long)lExtensionVersion, (unsigned long)(PRODUCT_VERSION1 << 24 | PRODUCT_VERSION2 << 16 | PRODUCT_VERSION3 << 8 | PRODUCT_VERSION4)); - LOG_WARNING(strMsg); + LOG_WARNING(m_log) << strMsg; switch(iDoNotShowAgain_VersionMismatch) { @@ -575,6 +567,11 @@ } } +TLogger& CCopyHandlerApp::GetLogger() +{ + return m_log; +} + void CCopyHandlerApp::RegisterShellExtension() { CString strPath = CString(m_pathProcessor.GetProgramPath()) + _T("\\"); @@ -605,7 +602,7 @@ // registered ok, but incompatible versions - probably restart required CString strMsg; strMsg.Format(_T("Registration succeeded, but still the shell extension has different version (0x%lx) than Copy Handler (0x%lx)."), (unsigned long)lExtensionVersion, (unsigned long)(PRODUCT_VERSION1 << 24 | PRODUCT_VERSION2 << 16 | PRODUCT_VERSION3 << 8 | PRODUCT_VERSION4)); - LOG_WARNING(strMsg); + LOG_WARNING(m_log) << strMsg; MsgBox(IDS_SHELL_EXTENSION_REGISTERED_MISMATCH_STRING, MB_ICONWARNING | MB_OK); } @@ -652,6 +649,7 @@ GetPropValue(GetConfig(), strPath); GetResManager().SetLanguage(m_pathProcessor.ExpandPath(strPath)); } +/* if(setPropNames.HasValue(PropData::GetPropertyName())) { @@ -672,7 +670,7 @@ chcore::TLogger& rLogger = chcore::TLogger::Acquire(); rLogger.set_max_size(GetPropValue(GetConfig())); - } + }*/ } void CCopyHandlerApp::OnResManNotify(UINT uiType) @@ -755,14 +753,14 @@ int CCopyHandlerApp::ExitInstance() { - LOG_INFO(_T("Pre-exit step - releasing shell extension")); + LOG_INFO(m_log) << _T("Pre-exit step - releasing shell extension"); m_tShellExtClient.Close(); - LOG_INFO(_T("Pre-exit step - uninitializing COM")); + LOG_INFO(m_log) << _T("Pre-exit step - uninitializing COM"); CoUninitialize(); - LOG_INFO(_T("============================ Leaving Copy Handler ============================")); + LOG_INFO(m_log) << _T("============================ Leaving Copy Handler ============================"); return __super::ExitInstance(); } Index: src/ch/ch.h =================================================================== diff -u -r4fe995b304ea342b50293f92d3c1992b43b820f7 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/ch/ch.h (.../ch.h) (revision 4fe995b304ea342b50293f92d3c1992b43b820f7) +++ src/ch/ch.h (.../ch.h) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -24,12 +24,10 @@ #include "../libchcore/TConfig.h" #include "TShellExtensionClient.h" #include "TCommandLineParser.h" +#include "../common/TLogger.h" +#include "../common/TLoggerInitializer.h" +#include "../libchcore/TCoreEngine.h" -///////////////////////////////////////////////////////////////////////////// -// CCopyHandlerApp: -// See CopyHandler.cpp for the implementation of this class -// - class CCopyHandlerApp : public CWinApp, public CAppHelper { public: @@ -45,10 +43,12 @@ friend int MsgBox(UINT uiID, UINT nType=MB_OK, UINT nIDHelp=0); - friend CCopyHandlerApp& GetApp(); - friend ictranslate::CResourceManager& GetResManager(); - friend chcore::TConfig& GetConfig(); + friend CCopyHandlerApp& GetApplication(); + static ictranslate::CResourceManager& GetResManager(); + static chcore::TConfig& GetConfig(); + TLogger& GetLogger(); + void RegisterShellExtension(); void UnregisterShellExtension(); @@ -68,9 +68,33 @@ TShellExtensionClient m_tShellExtClient; TCommandLineParser m_cmdLineParser; + chcore::TCoreEngine m_chEngine; + TLoggerInitializer m_logInitializer; + TLogger m_log; + CWnd *m_pMainWindow; DECLARE_MESSAGE_MAP() }; +inline CCopyHandlerApp& GetApp() +{ + return GetApplication(); +} + +inline TLogger& GetLogger() +{ + return GetApp().GetLogger(); +} + +inline ictranslate::CResourceManager& GetResManager() +{ + return CCopyHandlerApp::GetResManager(); +} + +inline chcore::TConfig& GetConfig() +{ + return CCopyHandlerApp::GetConfig(); +} + #endif Index: src/ch/ch.vc140.vcxproj =================================================================== diff -u -r4a481bbe77043e0bda2435c6d62a02700b3e46c5 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/ch/ch.vc140.vcxproj (.../ch.vc140.vcxproj) (revision 4a481bbe77043e0bda2435c6d62a02700b3e46c5) +++ src/ch/ch.vc140.vcxproj (.../ch.vc140.vcxproj) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -198,6 +198,7 @@ true true NoExtensions + 4714 _DEBUG;%(PreprocessorDefinitions) @@ -237,6 +238,7 @@ true true NoExtensions + 4714 _DEBUG;%(PreprocessorDefinitions) @@ -276,8 +278,7 @@ Level4 true ProgramDatabase - - + 4714 false true true @@ -317,8 +318,7 @@ Level4 true ProgramDatabase - - + 4714 false true true @@ -364,6 +364,7 @@ ProgramDatabase true NoExtensions + 4714 NDEBUG;%(PreprocessorDefinitions) @@ -404,6 +405,7 @@ ProgramDatabase true NoExtensions + 4714 NDEBUG;%(PreprocessorDefinitions) @@ -445,6 +447,7 @@ true ProgramDatabase true + 4714 NDEBUG;%(PreprocessorDefinitions) @@ -484,6 +487,7 @@ true ProgramDatabase true + 4714 NDEBUG;%(PreprocessorDefinitions) @@ -506,6 +510,8 @@ + + @@ -758,6 +764,17 @@ NotUsing NotUsing + + 4512;4714 + 4512;4714 + 4512;4714 + 4512;4714 + 4512;4714 + 4512;4714 + 4512;4714 + 4512;4714 + + Index: src/ch/ch.vc140.vcxproj.filters =================================================================== diff -u -r25129f39720523eca2cb702242890a7862f70ec6 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/ch/ch.vc140.vcxproj.filters (.../ch.vc140.vcxproj.filters) (revision 25129f39720523eca2cb702242890a7862f70ec6) +++ src/ch/ch.vc140.vcxproj.filters (.../ch.vc140.vcxproj.filters) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -63,6 +63,9 @@ {2e2638f2-07f6-4472-bd2d-32151a7ef9ce} + + {475febbf-e9ec-4293-a92f-d31c3f8c8072} + @@ -245,6 +248,12 @@ Source Files\Core + + Source Files\Shared\Logging + + + Source Files\Shared\Logging + @@ -418,6 +427,12 @@ Source Files\Core + + Source Files\Shared\Logging + + + Source Files\Shared\Logging + Index: src/common/TLogger.cpp =================================================================== diff -u --- src/common/TLogger.cpp (revision 0) +++ src/common/TLogger.cpp (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -0,0 +1,41 @@ +// ============================================================================ +// 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 "TLogger.h" +#include + +namespace keywords = boost::log::keywords; + +TLogger::TLogger(PCTSTR pszChannel) : + Logger(keywords::channel = pszChannel) +{ +} + +TLogger::TLogger(PCTSTR pszLogPath, PCTSTR pszChannel) : + TLogger(pszChannel) +{ + m_iterLogPath = add_attribute("LogPath", boost::log::attributes::constant< std::wstring >(pszLogPath)).first; +} + +void TLogger::SetLogPath(PCTSTR pszLogPath) +{ + if(m_iterLogPath != boost::log::attribute_set::iterator()) + remove_attribute(m_iterLogPath); + m_iterLogPath = add_attribute("LogPath", boost::log::attributes::constant< std::wstring >(pszLogPath)).first; +} Index: src/common/TLogger.h =================================================================== diff -u --- src/common/TLogger.h (revision 0) +++ src/common/TLogger.h (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -0,0 +1,47 @@ +// ============================================================================ +// 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. +// ============================================================================ +#ifndef __TLOGGER_H__ +#define __TLOGGER_H__ + +#include +#include + +using boost::log::trivial::severity_level; +using Logger = boost::log::sources::wseverity_channel_logger_mt; + +class TLogger : public Logger +{ +public: + TLogger(PCTSTR pszChannel); + TLogger(PCTSTR pszLogPath, PCTSTR pszChannel); + + void SetLogPath(PCTSTR pszLogPath); + +private: + boost::log::attribute_set::iterator m_iterLogPath; +}; + +#define LOG_TRACE(logger) BOOST_LOG_SEV(logger, boost::log::trivial::trace) +#define LOG_DEBUG(logger) BOOST_LOG_SEV(logger, boost::log::trivial::debug) +#define LOG_INFO(logger) BOOST_LOG_SEV(logger, boost::log::trivial::info) +#define LOG_WARNING(logger) BOOST_LOG_SEV(logger, boost::log::trivial::warning) +#define LOG_ERROR(logger) BOOST_LOG_SEV(logger, boost::log::trivial::error) +#define LOG_FATAL(logger) BOOST_LOG_SEV(logger, boost::log::trivial::fatal) + +#endif Index: src/common/TLoggerInitializer.cpp =================================================================== diff -u --- src/common/TLoggerInitializer.cpp (revision 0) +++ src/common/TLoggerInitializer.cpp (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -0,0 +1,117 @@ +// ============================================================================ +// 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 "TLoggerInitializer.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace logging = boost::log; +namespace src = boost::log::sources; +namespace sinks = boost::log::sinks; +namespace keywords = boost::log::keywords; +namespace expr = boost::log::expressions; +namespace attrs = boost::log::attributes; + +using namespace boost::log::trivial; + +using LogSink = sinks::asynchronous_sink< sinks::text_multifile_backend >; +using LogSinkPtr = boost::shared_ptr; + +struct TLoggerInitializer::InternalData +{ + LogSinkPtr m_spSink; +}; + +TLoggerInitializer::TLoggerInitializer() : + m_spData(new InternalData) +{ + InitSink(); +} + +TLoggerInitializer::~TLoggerInitializer() +{ + Uninit(); +} + +void TLoggerInitializer::InitSink() +{ + if(m_bWasInitialized) + return; + + boost::shared_ptr< logging::core > core = logging::core::get(); + + logging::add_common_attributes(); + + // sink BACKEND + boost::shared_ptr< sinks::text_multifile_backend > backend = boost::make_shared< sinks::text_multifile_backend >(); + + // Set up the file naming pattern + backend->set_file_name_composer + ( + sinks::file::as_file_name_composer(expr::stream << expr::attr< std::wstring >("LogPath")) + ); + + // Sink FRONTEND + LogSinkPtr sink(new LogSink(backend)); + + // Set the formatter + sink->set_formatter + ( + expr::stream + << expr::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d %H:%M:%S.%f") + << " [" << boost::log::trivial::severity << "] " + << expr::attr< std::wstring >("Channel") << ": " + << expr::wmessage + ); + + std::locale loc = boost::locale::generator()("en_EN.UTF-8"); + sink->imbue(loc); + + core->add_sink(sink); + + m_spData->m_spSink = sink; + + m_bWasInitialized = true; +} + +void TLoggerInitializer::Uninit() +{ + if (!m_spData->m_spSink || !m_bWasInitialized) + return; + + boost::shared_ptr< logging::core > core = logging::core::get(); + + // Remove the sink from the core, so that no records are passed to it + core->remove_sink(m_spData->m_spSink); + + // Break the feeding loop + m_spData->m_spSink->stop(); + + // Flush all log records that may have left buffered + m_spData->m_spSink->flush(); + + m_spData->m_spSink.reset(); +} Fisheye: tag d18db617f4727a237c94b59af9b4328f829eda16 is not in file src/common/TLoggerInitializer.h Fisheye: tag d18db617f4727a237c94b59af9b4328f829eda16 is not in file src/libchcore/TCoreEngine.cpp Fisheye: tag d18db617f4727a237c94b59af9b4328f829eda16 is not in file src/libchcore/TCoreEngine.h Index: src/libchcore/TFilesystemFeedbackWrapper.cpp =================================================================== diff -u -rd18db617f4727a237c94b59af9b4328f829eda16 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/libchcore/TFilesystemFeedbackWrapper.cpp (.../TFilesystemFeedbackWrapper.cpp) (revision d18db617f4727a237c94b59af9b4328f829eda16) +++ src/libchcore/TFilesystemFeedbackWrapper.cpp (.../TFilesystemFeedbackWrapper.cpp) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -22,14 +22,13 @@ #include "TFileException.h" #include "TFileInfo.h" #include "TWorkerThreadController.h" -#include "log.h" namespace chcore { - TFilesystemFeedbackWrapper::TFilesystemFeedbackWrapper(const IFeedbackHandlerPtr& spFeedbackHandler, const IFilesystemPtr& spFilesystem, log_file& rLog, TWorkerThreadController& rThreadController) : + TFilesystemFeedbackWrapper::TFilesystemFeedbackWrapper(const IFeedbackHandlerPtr& spFeedbackHandler, const IFilesystemPtr& spFilesystem, const TSmartPath& pathLogger, TWorkerThreadController& rThreadController) : m_spFeedbackHandler(spFeedbackHandler), m_spFilesystem(spFilesystem), - m_rLog(rLog), + m_log(pathLogger.ToString(), L"Filesystem"), m_rThreadController(rThreadController) { if (!spFilesystem) @@ -62,7 +61,7 @@ strFormat = _T("Error %errno while calling CreateDirectory %path (ProcessFiles)"); strFormat.Replace(_T("%errno"), boost::lexical_cast(dwLastError).c_str()); strFormat.Replace(_T("%path"), pathDirectory.ToString()); - m_rLog.loge(strFormat.c_str()); + LOG_ERROR(m_log) << strFormat.c_str(); TFeedbackResult frResult = m_spFeedbackHandler->FileError(pathDirectory.ToWString(), TString(), EFileError::eCreateError, dwLastError); switch (frResult.GetResult()) @@ -110,7 +109,7 @@ { bRetry = false; - m_rLog.logi(_T("Checking for free space on destination disk...")); + LOG_INFO(m_log) << _T("Checking for free space on destination disk..."); // get free space DWORD dwLastError = ERROR_SUCCESS; @@ -131,7 +130,7 @@ strFormat = _T("Error %errno while checking free space at %path"); strFormat.Replace(_T("%errno"), boost::lexical_cast(dwLastError).c_str()); strFormat.Replace(_T("%path"), pathDestination.ToString()); - m_rLog.loge(strFormat.c_str()); + LOG_ERROR(m_log) << strFormat.c_str(); frResult = m_spFeedbackHandler->FileError(pathDestination.ToWString(), TString(), EFileError::eCheckForFreeSpace, dwLastError); switch (frResult.GetResult()) @@ -160,22 +159,22 @@ TString strFormat = _T("Not enough free space on disk - needed %needsize bytes for data, available: %availablesize bytes."); strFormat.Replace(_T("%needsize"), boost::lexical_cast(ullNeededSize).c_str()); strFormat.Replace(_T("%availablesize"), boost::lexical_cast(ullAvailableSize).c_str()); - m_rLog.logw(strFormat.c_str()); + LOG_WARNING(m_log) << strFormat.c_str(); frResult = m_spFeedbackHandler->NotEnoughSpace(pathFirstSrc.ToWString(), pathDestination.ToWString(), ullNeededSize); switch (frResult.GetResult()) { case EFeedbackResult::eResult_Cancel: - m_rLog.logi(_T("Cancel request while checking for free space on disk.")); + LOG_INFO(m_log) << _T("Cancel request while checking for free space on disk."); return TSubTaskBase::eSubResult_CancelRequest; case EFeedbackResult::eResult_Retry: - m_rLog.logi(_T("Retrying to read drive's free space...")); + LOG_INFO(m_log) << _T("Retrying to read drive's free space..."); bRetry = true; break; case EFeedbackResult::eResult_Ignore: - m_rLog.logi(_T("Ignored warning about not enough place on disk to copy data.")); + LOG_INFO(m_log) << _T("Ignored warning about not enough place on disk to copy data."); return TSubTaskBase::eSubResult_Continue; default: @@ -221,13 +220,13 @@ TString strFormat = _T("Error #%errno while deleting folder %path"); strFormat.Replace(_T("%errno"), boost::lexical_cast(dwLastError).c_str()); strFormat.Replace(_T("%path"), spFileInfo->GetFullFilePath().ToString()); - m_rLog.loge(strFormat.c_str()); + LOG_ERROR(m_log) << strFormat.c_str(); TFeedbackResult frResult = m_spFeedbackHandler->FileError(spFileInfo->GetFullFilePath().ToWString(), TString(), EFileError::eDeleteError, dwLastError); switch (frResult.GetResult()) { case EFeedbackResult::eResult_Cancel: - m_rLog.logi(_T("Cancel request while deleting file.")); + LOG_INFO(m_log) << _T("Cancel request while deleting file."); return TSubTaskBase::eSubResult_CancelRequest; case EFeedbackResult::eResult_Retry: @@ -282,13 +281,13 @@ TString strFormat = _T("Error #%errno while deleting file %path"); strFormat.Replace(_T("%errno"), boost::lexical_cast(dwLastError).c_str()); strFormat.Replace(_T("%path"), spFileInfo->GetFullFilePath().ToString()); - m_rLog.loge(strFormat.c_str()); + LOG_ERROR(m_log) << strFormat.c_str(); TFeedbackResult frResult = m_spFeedbackHandler->FileError(spFileInfo->GetFullFilePath().ToWString(), TString(), EFileError::eDeleteError, dwLastError); switch (frResult.GetResult()) { case EFeedbackResult::eResult_Cancel: - m_rLog.logi(_T("Cancel request while deleting file.")); + LOG_INFO(m_log) << _T("Cancel request while deleting file."); return TSubTaskBase::eSubResult_CancelRequest; case EFeedbackResult::eResult_Retry: @@ -347,7 +346,7 @@ strFormat.Replace(_T("%errno"), boost::lexical_cast(dwLastError).c_str()); strFormat.Replace(_T("%srcpath"), spFileInfo->GetFullFilePath().ToString()); strFormat.Replace(_T("%dstpath"), pathDestination.ToString()); - m_rLog.loge(strFormat.c_str()); + LOG_ERROR(m_log) << strFormat.c_str(); TFeedbackResult frResult = m_spFeedbackHandler->FileError(pathSrc.ToWString(), pathDestination.ToWString(), EFileError::eFastMoveError, dwLastError); switch (frResult.GetResult()) Index: src/libchcore/TFilesystemFeedbackWrapper.h =================================================================== diff -u -r4fe995b304ea342b50293f92d3c1992b43b820f7 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/libchcore/TFilesystemFeedbackWrapper.h (.../TFilesystemFeedbackWrapper.h) (revision 4fe995b304ea342b50293f92d3c1992b43b820f7) +++ src/libchcore/TFilesystemFeedbackWrapper.h (.../TFilesystemFeedbackWrapper.h) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -21,6 +21,7 @@ #include "IFilesystem.h" #include "TSubTaskBase.h" +#include "../common/TLogger.h" namespace chcore { @@ -30,7 +31,7 @@ class TFilesystemFeedbackWrapper { public: - TFilesystemFeedbackWrapper(const IFeedbackHandlerPtr& spFeedbackHandler, const IFilesystemPtr& spFilesystem, log_file& rLog, TWorkerThreadController& rThreadController); + TFilesystemFeedbackWrapper(const IFeedbackHandlerPtr& spFeedbackHandler, const IFilesystemPtr& spFilesystem, const TSmartPath& pathLogger, TWorkerThreadController& rThreadController); TFilesystemFeedbackWrapper& operator=(const TFilesystemFeedbackWrapper&) = delete; TSubTaskBase::ESubOperationResult CreateDirectoryFB(const TSmartPath& pathDirectory); @@ -51,7 +52,7 @@ private: IFeedbackHandlerPtr m_spFeedbackHandler; IFilesystemPtr m_spFilesystem; - log_file& m_rLog; + TLogger m_log; TWorkerThreadController& m_rThreadController; }; } Index: src/libchcore/TFilesystemFileFeedbackWrapper.cpp =================================================================== diff -u -rd18db617f4727a237c94b59af9b4328f829eda16 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/libchcore/TFilesystemFileFeedbackWrapper.cpp (.../TFilesystemFileFeedbackWrapper.cpp) (revision d18db617f4727a237c94b59af9b4328f829eda16) +++ src/libchcore/TFilesystemFileFeedbackWrapper.cpp (.../TFilesystemFileFeedbackWrapper.cpp) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -23,13 +23,12 @@ #include #include "TFileInfo.h" #include "TWorkerThreadController.h" -#include "log.h" namespace chcore { - TFilesystemFileFeedbackWrapper::TFilesystemFileFeedbackWrapper(const IFeedbackHandlerPtr& spFeedbackHandler, log_file& rLog, TWorkerThreadController& rThreadController, const IFilesystemPtr& spFilesystem) : + TFilesystemFileFeedbackWrapper::TFilesystemFileFeedbackWrapper(const IFeedbackHandlerPtr& spFeedbackHandler, const TSmartPath& pathLogger, TWorkerThreadController& rThreadController, const IFilesystemPtr& spFilesystem) : m_spFeedbackHandler(spFeedbackHandler), - m_rLog(rLog), + m_log(pathLogger.ToString(), L"Filesystem-File"), m_rThreadController(rThreadController), m_spFilesystem(spFilesystem) { @@ -71,7 +70,7 @@ TString strFormat = _T("Cancel request [error %errno] while opening source file %path (OpenSourceFileFB)"); strFormat.Replace(_T("%errno"), boost::lexical_cast(dwLastError).c_str()); strFormat.Replace(_T("%path"), fileSrc->GetFilePath().ToString()); - m_rLog.loge(strFormat.c_str()); + LOG_ERROR(m_log) << strFormat.c_str(); return TSubTaskBase::eSubResult_CancelRequest; } @@ -85,7 +84,7 @@ TString strFormat = _T("Retrying [error %errno] to open source file %path (OpenSourceFileFB)"); strFormat.Replace(_T("%errno"), boost::lexical_cast(dwLastError).c_str()); strFormat.Replace(_T("%path"), fileSrc->GetFilePath().ToString()); - m_rLog.loge(strFormat.c_str()); + LOG_ERROR(m_log) << strFormat.c_str(); bRetry = true; break; @@ -158,7 +157,7 @@ TString strFormat = _T("Retrying [error %errno] to open destination file %path (CustomCopyFileFB)"); strFormat.Replace(_T("%errno"), boost::lexical_cast(dwLastError).c_str()); strFormat.Replace(_T("%path"), fileDst->GetFilePath().ToString()); - m_rLog.loge(strFormat.c_str()); + LOG_ERROR(m_log) << strFormat.c_str(); bRetry = true; break; @@ -169,7 +168,7 @@ TString strFormat = _T("Cancel request [error %errno] while opening destination file %path (CustomCopyFileFB)"); strFormat.Replace(_T("%errno"), boost::lexical_cast(dwLastError).c_str()); strFormat.Replace(_T("%path"), fileDst->GetFilePath().ToString()); - m_rLog.loge(strFormat.c_str()); + LOG_ERROR(m_log) << strFormat.c_str(); return TSubTaskBase::eSubResult_CancelRequest; } @@ -261,7 +260,7 @@ // log TString strFormat = _T("Cancel request while checking result of dialog before opening source file %path (CustomCopyFileFB)"); strFormat.Replace(_T("%path"), fileDst->GetFilePath().ToString()); - m_rLog.logi(strFormat.c_str()); + LOG_INFO(m_log) << strFormat.c_str(); return TSubTaskBase::eSubResult_CancelRequest; } @@ -283,7 +282,7 @@ TString strFormat = _T("Retrying [error %errno] to open destination file %path (CustomCopyFileFB)"); strFormat.Replace(_T("%errno"), boost::lexical_cast(dwLastError).c_str()); strFormat.Replace(_T("%path"), fileDst->GetFilePath().ToString()); - m_rLog.loge(strFormat.c_str()); + LOG_ERROR(m_log) << strFormat.c_str(); bRetry = true; @@ -295,7 +294,7 @@ TString strFormat = _T("Cancel request [error %errno] while opening destination file %path (CustomCopyFileFB)"); strFormat.Replace(_T("%errno"), boost::lexical_cast(dwLastError).c_str()); strFormat.Replace(_T("%path"), fileDst->GetFilePath().ToString()); - m_rLog.loge(strFormat.c_str()); + LOG_ERROR(m_log) << strFormat.c_str(); return TSubTaskBase::eSubResult_CancelRequest; } @@ -342,7 +341,7 @@ TString strFormat = _T("Error %errno while truncating file %path to 0"); strFormat.Replace(_T("%errno"), boost::lexical_cast(dwLastError).c_str()); strFormat.Replace(_T("%path"), pathFile.ToString()); - m_rLog.loge(strFormat.c_str()); + LOG_ERROR(m_log) << strFormat.c_str(); TFeedbackResult frResult = m_spFeedbackHandler->FileError(pathFile.ToWString(), TString(), EFileError::eResizeError, dwLastError); switch (frResult.GetResult()) @@ -398,7 +397,7 @@ strFormat.Replace(_T("%errno"), boost::lexical_cast(dwLastError).c_str()); strFormat.Replace(_T("%count"), boost::lexical_cast(rBuffer.GetRequestedDataSize()).c_str()); strFormat.Replace(_T("%path"), pathFile.ToString()); - m_rLog.loge(strFormat.c_str()); + LOG_ERROR(m_log) << strFormat.c_str(); TFeedbackResult frResult = m_spFeedbackHandler->FileError(pathFile.ToWString(), TString(), EFileError::eReadError, dwLastError); switch (frResult.GetResult()) @@ -455,7 +454,7 @@ strFormat.Replace(_T("%errno"), boost::lexical_cast(dwLastError).c_str()); strFormat.Replace(_T("%count"), boost::lexical_cast(rBuffer.GetBytesTransferred()).c_str()); strFormat.Replace(_T("%path"), pathFile.ToString()); - m_rLog.loge(strFormat.c_str()); + LOG_ERROR(m_log) << strFormat.c_str(); TFeedbackResult frResult = m_spFeedbackHandler->FileError(pathFile.ToWString(), TString(), EFileError::eWriteError, dwLastError); switch (frResult.GetResult()) @@ -511,7 +510,7 @@ TString strFormat = _T("Error %errno while trying to finalize file %path (CustomCopyFileFB)"); strFormat.Replace(_T("%errno"), boost::lexical_cast(dwLastError).c_str()); strFormat.Replace(_T("%path"), pathFile.ToString()); - m_rLog.loge(strFormat.c_str()); + LOG_ERROR(m_log) << strFormat.c_str(); TFeedbackResult frResult = m_spFeedbackHandler->FileError(pathFile.ToWString(), TString(), EFileError::eFinalizeError, dwLastError); switch (frResult.GetResult()) Index: src/libchcore/TFilesystemFileFeedbackWrapper.h =================================================================== diff -u -r4fe995b304ea342b50293f92d3c1992b43b820f7 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/libchcore/TFilesystemFileFeedbackWrapper.h (.../TFilesystemFileFeedbackWrapper.h) (revision 4fe995b304ea342b50293f92d3c1992b43b820f7) +++ src/libchcore/TFilesystemFileFeedbackWrapper.h (.../TFilesystemFileFeedbackWrapper.h) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -23,6 +23,7 @@ #include "TSubTaskBase.h" #include "IFeedbackHandler.h" #include "IFilesystem.h" +#include "../common/TLogger.h" namespace chcore { @@ -32,7 +33,7 @@ class TFilesystemFileFeedbackWrapper { public: - TFilesystemFileFeedbackWrapper(const IFeedbackHandlerPtr& spFeedbackHandler, log_file& rLog, TWorkerThreadController& rThreadController, const IFilesystemPtr& spFilesystem); + TFilesystemFileFeedbackWrapper(const IFeedbackHandlerPtr& spFeedbackHandler, const TSmartPath& pathLogger, TWorkerThreadController& rThreadController, const IFilesystemPtr& spFilesystem); TFilesystemFileFeedbackWrapper& operator=(const TFilesystemFileFeedbackWrapper&) = delete; TSubTaskBase::ESubOperationResult OpenSourceFileFB(const IFilesystemFilePtr& fileSrc); @@ -57,7 +58,7 @@ private: IFeedbackHandlerPtr m_spFeedbackHandler; IFilesystemPtr m_spFilesystem; - log_file& m_rLog; + TLogger m_log; TWorkerThreadController& m_rThreadController; }; } Fisheye: Tag 6f8b891b60eb0f33199fd29db75d4d9f4a22c248 refers to a dead (removed) revision in file `src/libchcore/TLogger.cpp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 6f8b891b60eb0f33199fd29db75d4d9f4a22c248 refers to a dead (removed) revision in file `src/libchcore/TLogger.h'. Fisheye: No comparison available. Pass `N' to diff? Index: src/libchcore/TLoggerInfo.cpp =================================================================== diff -u --- src/libchcore/TLoggerInfo.cpp (revision 0) +++ src/libchcore/TLoggerInfo.cpp (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -0,0 +1,15 @@ +#include "stdafx.h" +#include "TLoggerInfo.h" + +namespace chcore +{ + TLoggerInfo::TLoggerInfo(const TSmartPath& pathLog) : + m_strLogPath(pathLog) + { + } + + TSmartPath TLoggerInfo::GetLogPath() const + { + return m_strLogPath; + } +} Index: src/libchcore/TLoggerInfo.h =================================================================== diff -u --- src/libchcore/TLoggerInfo.h (revision 0) +++ src/libchcore/TLoggerInfo.h (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -0,0 +1,23 @@ +#ifndef __TLOGGERINFO_H__ +#define __TLOGGERINFO_H__ + +#include "libchcore.h" +#include "TPath.h" + +namespace chcore +{ + class LIBCHCORE_API TLoggerInfo + { + public: + TLoggerInfo(const TSmartPath& pathLog); + + TSmartPath GetLogPath() const; + + private: + TSmartPath m_strLogPath; + }; + + using TLoggerInfoPtr = std::shared_ptr; +} + +#endif Index: src/libchcore/TSubTaskContext.cpp =================================================================== diff -u -rd18db617f4727a237c94b59af9b4328f829eda16 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/libchcore/TSubTaskContext.cpp (.../TSubTaskContext.cpp) (revision d18db617f4727a237c94b59af9b4328f829eda16) +++ src/libchcore/TSubTaskContext.cpp (.../TSubTaskContext.cpp) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -25,20 +25,19 @@ #include "ErrorCodes.h" #include "TCoreException.h" #include "TFileFiltersArray.h" -#include "log.h" namespace chcore { TSubTaskContext::TSubTaskContext(TConfig& rConfig, const TBasePathDataContainerPtr& spBasePaths, const TFileFiltersArray& rFilters, - TTaskConfigTracker& rCfgTracker, log_file& rLog, + TTaskConfigTracker& rCfgTracker, const TSmartPath& rPathLogFile, TWorkerThreadController& rThreadController, const IFilesystemPtr& spFilesystem) : m_rConfig(rConfig), m_eOperationType(eOperation_None), m_spBasePaths(spBasePaths), m_pathDestination(), m_rCfgTracker(rCfgTracker), - m_rLog(rLog), + m_pathLogFile(rPathLogFile), m_rThreadController(rThreadController), m_spFilesystem(spFilesystem), m_rFilters(rFilters) @@ -106,14 +105,14 @@ return m_rCfgTracker; } - log_file& TSubTaskContext::GetLog() + TSmartPath TSubTaskContext::GetLogPath() const { - return m_rLog; + return m_pathLogFile; } - const log_file& TSubTaskContext::GetLog() const + void TSubTaskContext::SetLogPath(const TSmartPath& pathLog) { - return m_rLog; + m_pathLogFile = pathLog; } TWorkerThreadController& TSubTaskContext::GetThreadController() Index: src/libchcore/TSubTaskContext.h =================================================================== diff -u -rd18db617f4727a237c94b59af9b4328f829eda16 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/libchcore/TSubTaskContext.h (.../TSubTaskContext.h) (revision d18db617f4727a237c94b59af9b4328f829eda16) +++ src/libchcore/TSubTaskContext.h (.../TSubTaskContext.h) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -29,6 +29,7 @@ #include "TBasePathData.h" #include "TFileInfoArray.h" #include "IFilesystem.h" +#include "TLoggerInfo.h" namespace chcore { @@ -46,7 +47,7 @@ public: TSubTaskContext(TConfig& rConfig, const TBasePathDataContainerPtr& spBasePaths, const TFileFiltersArray& rFilters, - TTaskConfigTracker& rCfgTracker, log_file& rLog, + TTaskConfigTracker& rCfgTracker, const TSmartPath& rPathLogFile, TWorkerThreadController& rThreadController, const IFilesystemPtr& spFilesystem); ~TSubTaskContext(); @@ -68,8 +69,8 @@ TTaskConfigTracker& GetCfgTracker(); const TTaskConfigTracker& GetCfgTracker() const; - log_file& GetLog(); - const log_file& GetLog() const; + TSmartPath GetLogPath() const; + void SetLogPath(const TSmartPath& pathLog); TWorkerThreadController& GetThreadController(); const TWorkerThreadController& GetThreadController() const; @@ -108,7 +109,7 @@ #pragma warning(pop) // additional data - log_file& m_rLog; + TSmartPath m_pathLogFile; // thread control TWorkerThreadController& m_rThreadController; Index: src/libchcore/TSubTaskCopyMove.cpp =================================================================== diff -u -rd18db617f4727a237c94b59af9b4328f829eda16 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/libchcore/TSubTaskCopyMove.cpp (.../TSubTaskCopyMove.cpp) (revision d18db617f4727a237c94b59af9b4328f829eda16) +++ src/libchcore/TSubTaskCopyMove.cpp (.../TSubTaskCopyMove.cpp) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -47,7 +47,6 @@ #include "TFileException.h" #include "TFilesystemFeedbackWrapper.h" #include "TFilesystemFileFeedbackWrapper.h" -#include "log.h" #include "TDestinationPathProvider.h" namespace chcore @@ -66,9 +65,10 @@ /////////////////////////////////////////////////////////////////////////////////////////////////// // class TSubTaskCopyMove - TSubTaskCopyMove::TSubTaskCopyMove(TSubTaskContext& tSubTaskContext) : - TSubTaskBase(tSubTaskContext), - m_tSubTaskStats(eSubOperation_Copying) + TSubTaskCopyMove::TSubTaskCopyMove(TSubTaskContext& rContext) : + TSubTaskBase(rContext), + m_tSubTaskStats(eSubOperation_Copying), + m_log(rContext.GetLogPath().ToString(), L"ST-CopyMove") { } @@ -101,7 +101,6 @@ TScopedRunningTimeTracker guard(m_tSubTaskStats); TFeedbackHandlerWrapperPtr spFeedbackHandler(std::make_shared(spFeedback, guard)); - log_file& rLog = GetContext().GetLog(); TFileInfoArray& rFilesCache = GetContext().GetFilesCache(); TTaskConfigTracker& rCfgTracker = GetContext().GetCfgTracker(); TWorkerThreadController& rThreadController = GetContext().GetThreadController(); @@ -110,10 +109,10 @@ IFilesystemPtr spFilesystem = GetContext().GetLocalFilesystem(); TBasePathDataContainerPtr spSrcPaths = GetContext().GetBasePaths(); - TFilesystemFeedbackWrapper tFilesystemFBWrapper(spFeedbackHandler, spFilesystem, rLog, rThreadController); + TFilesystemFeedbackWrapper tFilesystemFBWrapper(spFeedbackHandler, spFilesystem, GetContext().GetLogPath(), rThreadController); // log - rLog.logi(_T("Processing files/folders (ProcessFiles)")); + LOG_INFO(m_log) << _T("Processing files/folders (ProcessFiles)"); // initialize stats if not resuming (when resuming we have already initialized // the stats once - it is being restored in Load() too). @@ -166,15 +165,15 @@ strFormat.Replace(_T("%dstpath"), pathDestination.ToString()); strFormat.Replace(_T("%currindex"), boost::lexical_cast(fcIndex).c_str()); - rLog.logi(strFormat.c_str()); + LOG_INFO(m_log) << strFormat.c_str(); for(; fcIndex < fcSize; fcIndex++) { // should we kill ? if(rThreadController.KillRequested()) { // log - rLog.logi(_T("Kill request while processing file in ProcessFiles")); + LOG_INFO(m_log) << _T("Kill request while processing file in ProcessFiles"); return TSubTaskBase::eSubResult_KillRequest; } @@ -253,7 +252,7 @@ bool bUpdateDirTimes = GetTaskPropValue(rConfig); if(bUpdateDirTimes) { - rLog.logi(_T("Setting directory attributes")); + LOG_INFO(m_log) << _T("Setting directory attributes"); // iterate backwards for(file_count_t fcAttrIndex = fcSize; fcAttrIndex != 0; --fcAttrIndex) @@ -262,7 +261,7 @@ if(rThreadController.KillRequested()) { // log - rLog.logi(_T("Kill request while processing file in ProcessFiles")); + LOG_INFO(m_log) << _T("Kill request while processing file in ProcessFiles"); return TSubTaskBase::eSubResult_KillRequest; } @@ -282,7 +281,7 @@ m_tSubTaskStats.SetCurrentPath(TString()); // log - rLog.logi(_T("Finished processing in ProcessFiles")); + LOG_INFO(m_log) << _T("Finished processing in ProcessFiles"); return TSubTaskBase::eSubResult_Continue; } @@ -334,11 +333,10 @@ TSubTaskBase::ESubOperationResult TSubTaskCopyMove::CustomCopyFileFB(const IFeedbackHandlerPtr& spFeedbackHandler, CUSTOM_COPY_PARAMS* pData) { TWorkerThreadController& rThreadController = GetContext().GetThreadController(); - log_file& rLog = GetContext().GetLog(); const TConfig& rConfig = GetContext().GetConfig(); IFilesystemPtr spFilesystem = GetContext().GetLocalFilesystem(); - TFilesystemFileFeedbackWrapper tFileFBWrapper(spFeedbackHandler, rLog, rThreadController, spFilesystem); + TFilesystemFileFeedbackWrapper tFileFBWrapper(spFeedbackHandler, GetContext().GetLogPath(), rThreadController, spFilesystem); TString strFormat; TSubTaskBase::ESubOperationResult eResult = TSubTaskBase::eSubResult_Continue; @@ -408,7 +406,7 @@ strFormat = _T("Kill request while main copying file %srcpath -> %dstpath"); strFormat.Replace(_T("%srcpath"), pData->spSrcFile->GetFullFilePath().ToString()); strFormat.Replace(_T("%dstpath"), pData->pathDstFile.ToString()); - rLog.logi(strFormat.c_str()); + LOG_INFO(m_log) << strFormat.c_str(); eResult = TSubTaskBase::eSubResult_KillRequest; bStopProcessing = true; @@ -792,7 +790,6 @@ { const TConfig& rConfig = GetContext().GetConfig(); TTaskConfigTracker& rCfgTracker = GetContext().GetCfgTracker(); - log_file& rLog = GetContext().GetLog(); if(bForce || (rCfgTracker.IsModified() && rCfgTracker.IsModified(TOptionsSet() % eTO_DefaultBufferSize % eTO_OneDiskBufferSize % eTO_TwoDisksBufferSize % eTO_CDBufferSize % eTO_LANBufferSize % eTO_UseOnlyDefaultBuffer % eTO_BufferQueueDepth, true))) { @@ -809,7 +806,7 @@ strFormat.Replace(_T("%lansize2"), boost::lexical_cast(rBufferSizes.GetLANSize()).c_str()); strFormat.Replace(_T("%cnt"), boost::lexical_cast(rBufferSizes.GetBufferCount()).c_str()); - rLog.logi(strFormat.c_str()); + LOG_INFO(m_log) << strFormat.c_str(); rBuffer.ReinitializeBuffers(rBufferSizes.GetBufferCount(), rBufferSizes.GetMaxSize()); @@ -824,7 +821,6 @@ const TSmartPath& pathFile, bool& bSkip) { - log_file& rLog = GetContext().GetLog(); DWORD dwLastError = rBuffer.GetErrorCode(); bSkip = false; @@ -834,7 +830,7 @@ strFormat.Replace(_T("%errno"), boost::lexical_cast(dwLastError).c_str()); strFormat.Replace(_T("%count"), boost::lexical_cast(rBuffer.GetRequestedDataSize()).c_str()); strFormat.Replace(_T("%path"), pathFile.ToString()); - rLog.loge(strFormat.c_str()); + LOG_ERROR(m_log) << strFormat.c_str(); TFeedbackResult frResult = spFeedbackHandler->FileError(pathFile.ToWString(), TString(), EFileError::eReadError, dwLastError); switch(frResult.GetResult()) @@ -863,7 +859,6 @@ const TSmartPath& pathFile, bool& bSkip) { - log_file& rLog = GetContext().GetLog(); DWORD dwLastError = rBuffer.GetErrorCode(); bSkip = false; @@ -873,7 +868,7 @@ strFormat.Replace(_T("%errno"), boost::lexical_cast(rBuffer.GetErrorCode()).c_str()); strFormat.Replace(_T("%count"), boost::lexical_cast(rBuffer.GetBytesTransferred()).c_str()); strFormat.Replace(_T("%path"), pathFile.ToString()); - rLog.loge(strFormat.c_str()); + LOG_ERROR(m_log) << strFormat.c_str(); TFeedbackResult frResult = spFeedbackHandler->FileError(pathFile.ToWString(), TString(), EFileError::eWriteError, dwLastError); switch (frResult.GetResult()) Index: src/libchcore/TSubTaskCopyMove.h =================================================================== diff -u -r4fe995b304ea342b50293f92d3c1992b43b820f7 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/libchcore/TSubTaskCopyMove.h (.../TSubTaskCopyMove.h) (revision 4fe995b304ea342b50293f92d3c1992b43b820f7) +++ src/libchcore/TSubTaskCopyMove.h (.../TSubTaskCopyMove.h) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -28,6 +28,7 @@ #include "CommonDataTypes.h" #include "TBufferSizes.h" #include "IFilesystemFile.h" +#include "../common/TLogger.h" namespace chcore { @@ -81,6 +82,7 @@ #pragma warning(push) #pragma warning(disable: 4251) TSubTaskStatsInfo m_tSubTaskStats; + TLogger m_log; #pragma warning(pop) }; } Index: src/libchcore/TSubTaskDelete.cpp =================================================================== diff -u -rd18db617f4727a237c94b59af9b4328f829eda16 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/libchcore/TSubTaskDelete.cpp (.../TSubTaskDelete.cpp) (revision d18db617f4727a237c94b59af9b4328f829eda16) +++ src/libchcore/TSubTaskDelete.cpp (.../TSubTaskDelete.cpp) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -38,7 +38,6 @@ #include "TBufferSizes.h" #include "TFileException.h" #include "TFilesystemFeedbackWrapper.h" -#include "log.h" namespace chcore { @@ -47,7 +46,8 @@ TSubTaskDelete::TSubTaskDelete(TSubTaskContext& rContext) : TSubTaskBase(rContext), - m_tSubTaskStats(eSubOperation_Deleting) + m_tSubTaskStats(eSubOperation_Deleting), + m_log(rContext.GetLogPath().ToString(), L"ST-Delete") { } @@ -81,15 +81,14 @@ TFeedbackHandlerWrapperPtr spFeedbackHandler(std::make_shared(spFeedback, guard)); // log - log_file& rLog = GetContext().GetLog(); TFileInfoArray& rFilesCache = GetContext().GetFilesCache(); TWorkerThreadController& rThreadController = GetContext().GetThreadController(); IFilesystemPtr spFilesystem = GetContext().GetLocalFilesystem(); - TFilesystemFeedbackWrapper tFilesystemFBWrapper(spFeedbackHandler, spFilesystem, rLog, rThreadController); + TFilesystemFeedbackWrapper tFilesystemFBWrapper(spFeedbackHandler, spFilesystem, GetContext().GetLogPath(), rThreadController); // log - rLog.logi(_T("Deleting files (DeleteFiles)...")); + LOG_INFO(m_log) << _T("Deleting files (DeleteFiles)..."); // new stats m_tSubTaskStats.SetCurrentBufferIndex(TBufferSizes::eBuffer_Default); @@ -119,7 +118,7 @@ if (rThreadController.KillRequested()) { // log - rLog.logi(_T("Kill request while deleting files (Delete Files)")); + LOG_INFO(m_log) << _T("Kill request while deleting files (Delete Files)"); return TSubTaskBase::eSubResult_KillRequest; } @@ -147,7 +146,7 @@ m_tSubTaskStats.SetCurrentPath(TString()); // log - rLog.logi(_T("Deleting files finished")); + LOG_INFO(m_log) << _T("Deleting files finished"); return TSubTaskBase::eSubResult_Continue; } Index: src/libchcore/TSubTaskDelete.h =================================================================== diff -u -rcb4e9d4b60d62b25ae2cf556c0642601af56c787 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/libchcore/TSubTaskDelete.h (.../TSubTaskDelete.h) (revision cb4e9d4b60d62b25ae2cf556c0642601af56c787) +++ src/libchcore/TSubTaskDelete.h (.../TSubTaskDelete.h) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -25,6 +25,7 @@ #include "libchcore.h" #include "TSubTaskBase.h" +#include "../common/TLogger.h" namespace chcore { @@ -53,6 +54,7 @@ #pragma warning(push) #pragma warning(disable: 4251) TSubTaskStatsInfo m_tSubTaskStats; + TLogger m_log; #pragma warning(pop) }; } Index: src/libchcore/TSubTaskFastMove.cpp =================================================================== diff -u -rd18db617f4727a237c94b59af9b4328f829eda16 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/libchcore/TSubTaskFastMove.cpp (.../TSubTaskFastMove.cpp) (revision d18db617f4727a237c94b59af9b4328f829eda16) +++ src/libchcore/TSubTaskFastMove.cpp (.../TSubTaskFastMove.cpp) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -39,14 +39,14 @@ #include "TBufferSizes.h" #include "TFileException.h" #include "TFilesystemFeedbackWrapper.h" -#include "log.h" #include "TDestinationPathProvider.h" namespace chcore { TSubTaskFastMove::TSubTaskFastMove(TSubTaskContext& rContext) : TSubTaskBase(rContext), - m_tSubTaskStats(eSubOperation_FastMove) + m_tSubTaskStats(eSubOperation_FastMove), + m_log(rContext.GetLogPath().ToString(), L"ST-FastMove") { } @@ -84,17 +84,16 @@ TFeedbackHandlerWrapperPtr spFeedbackHandler(std::make_shared(spFeedback, guard)); // log - log_file& rLog = GetContext().GetLog(); TWorkerThreadController& rThreadController = GetContext().GetThreadController(); TBasePathDataContainerPtr spBasePaths = GetContext().GetBasePaths(); const TConfig& rConfig = GetContext().GetConfig(); TSmartPath pathDestination = GetContext().GetDestinationPath(); const TFileFiltersArray& rafFilters = GetContext().GetFilters(); IFilesystemPtr spFilesystem = GetContext().GetLocalFilesystem(); - TFilesystemFeedbackWrapper tFilesystemFBWrapper(spFeedbackHandler, spFilesystem, rLog, rThreadController); + TFilesystemFeedbackWrapper tFilesystemFBWrapper(spFeedbackHandler, spFilesystem, GetContext().GetLogPath(), rThreadController); - rLog.logi(_T("Performing initial fast-move operation...")); + LOG_INFO(m_log) << _T("Performing initial fast-move operation..."); // new stats m_tSubTaskStats.SetCurrentBufferIndex(TBufferSizes::eBuffer_Default); @@ -173,7 +172,7 @@ if (rThreadController.KillRequested()) { // log - rLog.logi(_T("Kill request while fast moving items")); + LOG_INFO(m_log) << _T("Kill request while fast moving items"); return eSubResult_KillRequest; } } @@ -183,7 +182,7 @@ m_tSubTaskStats.SetCurrentPath(TString()); // log - rLog.logi(_T("Fast moving finished")); + LOG_INFO(m_log) << _T("Fast moving finished"); return eSubResult_Continue; } Index: src/libchcore/TSubTaskFastMove.h =================================================================== diff -u -r4fe995b304ea342b50293f92d3c1992b43b820f7 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/libchcore/TSubTaskFastMove.h (.../TSubTaskFastMove.h) (revision 4fe995b304ea342b50293f92d3c1992b43b820f7) +++ src/libchcore/TSubTaskFastMove.h (.../TSubTaskFastMove.h) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -25,6 +25,7 @@ #include "libchcore.h" #include "TSubTaskBase.h" +#include "../Common/TLogger.h" namespace chcore { @@ -56,6 +57,7 @@ #pragma warning(push) #pragma warning(disable: 4251) TSubTaskStatsInfo m_tSubTaskStats; + TLogger m_log; #pragma warning(pop) }; } Index: src/libchcore/TSubTaskScanDirectory.cpp =================================================================== diff -u -rd18db617f4727a237c94b59af9b4328f829eda16 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/libchcore/TSubTaskScanDirectory.cpp (.../TSubTaskScanDirectory.cpp) (revision d18db617f4727a237c94b59af9b4328f829eda16) +++ src/libchcore/TSubTaskScanDirectory.cpp (.../TSubTaskScanDirectory.cpp) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -39,15 +39,15 @@ #include "TBufferSizes.h" #include "TFileException.h" #include "TFilesystemFeedbackWrapper.h" -#include "log.h" namespace chcore { /////////////////////////////////////////////////////////////////////////////////////////////////// // class TSubTaskScanDirectories TSubTaskScanDirectories::TSubTaskScanDirectories(TSubTaskContext& rContext) : TSubTaskBase(rContext), - m_tSubTaskStats(eSubOperation_Scanning) + m_tSubTaskStats(eSubOperation_Scanning), + m_log(rContext.GetLogPath().ToString(), L"ST-ScanDirs") { } @@ -85,17 +85,16 @@ TFeedbackHandlerWrapperPtr spFeedbackHandler(std::make_shared(spFeedback, guard)); // log - log_file& rLog = GetContext().GetLog(); TFileInfoArray& rFilesCache = GetContext().GetFilesCache(); TWorkerThreadController& rThreadController = GetContext().GetThreadController(); TBasePathDataContainerPtr spBasePaths = GetContext().GetBasePaths(); const TConfig& rConfig = GetContext().GetConfig(); const TFileFiltersArray& rafFilters = GetContext().GetFilters(); IFilesystemPtr spFilesystem = GetContext().GetLocalFilesystem(); - TFilesystemFeedbackWrapper tFilesystemFBWrapper(spFeedbackHandler, spFilesystem, rLog, rThreadController); + TFilesystemFeedbackWrapper tFilesystemFBWrapper(spFeedbackHandler, spFilesystem, GetContext().GetLogPath(), rThreadController); - rLog.logi(_T("Searching for files...")); + LOG_INFO(m_log) << _T("Searching for files..."); // reset progress rFilesCache.SetComplete(false); @@ -148,7 +147,7 @@ // log strFormat = _T("Adding file/folder (clipboard) : %path ..."); strFormat.Replace(_T("%path"), pathCurrent.ToString()); - rLog.logi(strFormat.c_str()); + LOG_INFO(m_log) << strFormat.c_str(); // add if needed if (spFileInfo->IsDirectory()) @@ -162,22 +161,22 @@ // log strFormat = _T("Added folder %path"); strFormat.Replace(_T("%path"), spFileInfo->GetFullFilePath().ToString()); - rLog.logi(strFormat.c_str()); + LOG_INFO(m_log) << strFormat.c_str(); } // don't add folder contents when moving inside one disk boundary // log strFormat = _T("Recursing folder %path"); strFormat.Replace(_T("%path"), spFileInfo->GetFullFilePath().ToString()); - rLog.logi(strFormat.c_str()); + LOG_INFO(m_log) << strFormat.c_str(); ScanDirectory(spFileInfo->GetFullFilePath(), spBasePath, true, !bIgnoreDirs || bForceDirectories, rafFilters); // check for kill need if (rThreadController.KillRequested()) { // log - rLog.logi(_T("Kill request while adding data to files array (RecurseDirectories)")); + LOG_INFO(m_log) << _T("Kill request while adding data to files array (RecurseDirectories)"); rFilesCache.Clear(); return eSubResult_KillRequest; } @@ -191,7 +190,7 @@ // log strFormat = _T("Added file %path"); strFormat.Replace(_T("%path"), spFileInfo->GetFullFilePath().ToString()); - rLog.logi(strFormat.c_str()); + LOG_INFO(m_log) << strFormat.c_str(); } } @@ -203,7 +202,7 @@ rFilesCache.SetComplete(true); // log - rLog.logi(_T("Searching for files finished")); + LOG_INFO(m_log) << _T("Searching for files finished"); return eSubResult_Continue; } Index: src/libchcore/TSubTaskScanDirectory.h =================================================================== diff -u -r4fe995b304ea342b50293f92d3c1992b43b820f7 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/libchcore/TSubTaskScanDirectory.h (.../TSubTaskScanDirectory.h) (revision 4fe995b304ea342b50293f92d3c1992b43b820f7) +++ src/libchcore/TSubTaskScanDirectory.h (.../TSubTaskScanDirectory.h) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -27,6 +27,7 @@ #include "TSubTaskBase.h" #include "TPath.h" #include "TBasePathData.h" +#include "../common/TLogger.h" namespace chcore { @@ -61,6 +62,7 @@ #pragma warning(push) #pragma warning(disable: 4251) TSubTaskStatsInfo m_tSubTaskStats; + TLogger m_log; #pragma warning(pop) }; } Index: src/libchcore/TTask.cpp =================================================================== diff -u -rd18db617f4727a237c94b59af9b4328f829eda16 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/libchcore/TTask.cpp (.../TTask.cpp) (revision d18db617f4727a237c94b59af9b4328f829eda16) +++ src/libchcore/TTask.cpp (.../TTask.cpp) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -38,7 +38,6 @@ #include "TFeedbackHandlerWrapper.h" #include #include "TTaskConfigBufferSizes.h" -#include "log.h" #include #include "TLocalFilesystem.h" #include "TTaskConfigVerifier.h" @@ -48,14 +47,14 @@ //////////////////////////////////////////////////////////////////////////// // TTask members - TTask::TTask(const ISerializerPtr& spSerializer, const IFeedbackHandlerPtr& spFeedbackHandler) : - m_log(), + TTask::TTask(const ISerializerPtr& spSerializer, const IFeedbackHandlerPtr& spFeedbackHandler, const TTaskDefinition& rTaskDefinition, const TSmartPath& rLogPath) : + m_log(rLogPath.ToString(), L"Task"), m_spInternalFeedbackHandler(spFeedbackHandler), m_spSrcPaths(new TBasePathDataContainer), m_bForce(false), m_bContinue(false), m_tSubTaskContext(m_tConfiguration, m_spSrcPaths, m_afFilters, - m_cfgTracker, m_log, m_workerThread, + m_cfgTracker, rLogPath, m_workerThread, std::make_shared()), m_tSubTasksArray(m_tSubTaskContext), m_spSerializer(spSerializer) @@ -64,8 +63,29 @@ throw TCoreException(eErr_InvalidArgument, L"spFeedbackHandler", LOCATION); if(!spSerializer) throw TCoreException(eErr_InvalidArgument, L"spSerializer", LOCATION); + + m_tBaseData.SetLogPath(rLogPath); + SetTaskDefinition(rTaskDefinition); } + TTask::TTask(const ISerializerPtr& spSerializer, const IFeedbackHandlerPtr& spFeedbackHandler, const TTaskBaseData& rBaseTaskData) : + m_log(rBaseTaskData.GetLogPath().ToString(), L"Task"), + m_spInternalFeedbackHandler(spFeedbackHandler), + m_spSrcPaths(new TBasePathDataContainer), + m_bForce(false), + m_bContinue(false), + m_tSubTaskContext(m_tConfiguration, m_spSrcPaths, m_afFilters, + m_cfgTracker, rBaseTaskData.GetLogPath(), m_workerThread, + std::make_shared()), + m_tSubTasksArray(m_tSubTaskContext), + m_spSerializer(spSerializer) + { + if(!spFeedbackHandler) + throw TCoreException(eErr_InvalidArgument, L"spFeedbackHandler", LOCATION); + if(!spSerializer) + throw TCoreException(eErr_InvalidArgument, L"spSerializer", LOCATION); + } + TTask::~TTask() { KillThread(); @@ -124,10 +144,8 @@ SetTaskPropValue(m_tConfiguration, nPriority); } - void TTask::Load() + void TTask::Load(const TTaskBaseData& rBaseData) { - using namespace chcore; - bool bLogPathLoaded = false; bool bLoadFailed = false; const size_t stMaxSize = 1024; @@ -138,7 +156,7 @@ boost::unique_lock lock(m_lock); ISerializerContainerPtr spContainer = m_spSerializer->GetContainer(_T("task")); - m_tBaseData.Load(spContainer); + m_tBaseData = rBaseData;// .Load(spContainer); bLogPathLoaded = true; @@ -160,11 +178,11 @@ spContainer = m_spSerializer->GetContainer(_T("feedback")); m_spInternalFeedbackHandler->Load(spContainer); - m_tSubTasksArray.Load(m_spSerializer); - // ensure copy-based context entries are properly updated after loading m_tSubTaskContext.SetDestinationPath(m_tBaseData.GetDestinationPath()); m_tSubTaskContext.SetOperationType(m_tSubTasksArray.GetOperationType()); + + m_tSubTasksArray.Load(m_spSerializer); } catch (const TBaseException& e) { @@ -188,14 +206,28 @@ try { if (bLogPathLoaded) - GetLog().loge(szErr); + { + LOG_ERROR(m_log) << szErr; + } } catch (const std::exception&) { } } } + TTaskPtr TTask::Load(const ISerializerPtr& spSerializer, const IFeedbackHandlerPtr& spFeedbackHandler) + { + TTaskBaseData tBaseData; + ISerializerContainerPtr spContainer = spSerializer->GetContainer(_T("task")); + tBaseData.Load(spContainer); + + TTaskPtr spTask = std::shared_ptr(new TTask(spSerializer, spFeedbackHandler, tBaseData)); + spTask->Load(tBaseData); + + return spTask; + } + void TTask::Store(bool bForce) { if (GetTaskState() == eTaskState_LoadError) @@ -275,7 +307,7 @@ void TTask::BeginProcessing() { - GetLog().logi(_T("Requested task to begin processing")); + LOG_INFO(m_log) << _T("Requested task to begin processing"); boost::unique_lock lock(m_lock); if (m_tBaseData.GetCurrentState() != eTaskState_LoadError) @@ -287,7 +319,7 @@ // the same as retry but less demanding if (GetTaskState() == eTaskState_Paused) { - GetLog().logi(_T("Requested task resume")); + LOG_INFO(m_log) << _T("Requested task resume"); SetTaskState(eTaskState_Processing); BeginProcessing(); } @@ -321,7 +353,7 @@ void TTask::RestartProcessing() { - GetLog().logi(_T("Requested task restart")); + LOG_INFO(m_log) << _T("Requested task restart"); KillThread(); SetTaskState(eTaskState_None); @@ -346,7 +378,7 @@ { if (GetTaskState() != eTaskState_Finished && GetTaskState() != eTaskState_Cancelled) { - GetLog().logi(_T("Requested task pause")); + LOG_INFO(m_log) << _T("Requested task pause"); KillThread(); SetTaskState(eTaskState_Paused); } @@ -357,7 +389,7 @@ // change to ST_CANCELLED if (GetTaskState() != eTaskState_Finished) { - GetLog().logi(_T("Requested task cancel")); + LOG_INFO(m_log) << _T("Requested task cancel"); KillThread(); SetTaskState(eTaskState_Cancelled); } @@ -495,7 +527,7 @@ SetTaskState(eTaskState_Processing); bContinue = true; - m_log.logi(_T("Finished waiting for begin permission")); + LOG_INFO(m_log) << _T("Finished waiting for begin permission"); // return; // skips sleep and kill flag checking } @@ -505,7 +537,7 @@ if (m_workerThread.KillRequested()) { // log - m_log.logi(_T("Kill request while waiting for begin permission (wait state)")); + LOG_INFO(m_log) << _T("Kill request while waiting for begin permission (wait state)"); return TSubTaskBase::eSubResult_KillRequest; } } @@ -535,9 +567,6 @@ { TSubTaskBase::ESubOperationResult eResult = TSubTaskBase::eSubResult_Continue; - // initialize log file - m_log.init(m_tBaseData.GetLogPath().ToString(), 262144, log_file::level_debug, false, false); - // start operation OnBeginOperation(); @@ -643,7 +672,7 @@ // log TString strMsg = TString(L"Caught exception in ThrdProc: ") + upExceptionInfoBuffer.get(); - m_log.loge(strMsg.c_str()); + LOG_ERROR(m_log) << strMsg.c_str(); // let others know some error happened spFeedbackHandler->OperationError(); @@ -668,7 +697,7 @@ strFormat.Replace(_T("%hour"), boost::lexical_cast(tm.GetHour()).c_str()); strFormat.Replace(_T("%minute"), boost::lexical_cast(tm.GetMinute()).c_str()); strFormat.Replace(_T("%second"), boost::lexical_cast(tm.GetSecond()).c_str()); - m_log.logi(strFormat.c_str()); + LOG_INFO(m_log) << strFormat.c_str(); } void TTask::OnEndOperation() @@ -682,7 +711,7 @@ strFormat.Replace(_T("%hour"), boost::lexical_cast(tm.GetHour()).c_str()); strFormat.Replace(_T("%minute"), boost::lexical_cast(tm.GetMinute()).c_str()); strFormat.Replace(_T("%second"), boost::lexical_cast(tm.GetSecond()).c_str()); - m_log.logi(strFormat.c_str()); + LOG_INFO(m_log) << strFormat.c_str(); } void TTask::RequestStopThread() @@ -726,12 +755,4 @@ { return m_spSerializer; } - - log_file& TTask::GetLog() - { - if (!m_log.is_initialized()) - m_log.init(m_tBaseData.GetLogPath().ToString(), 262144, log_file::level_debug, false, false); - - return m_log; - } } Index: src/libchcore/TTask.h =================================================================== diff -u -rd18db617f4727a237c94b59af9b4328f829eda16 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/libchcore/TTask.h (.../TTask.h) (revision d18db617f4727a237c94b59af9b4328f829eda16) +++ src/libchcore/TTask.h (.../TTask.h) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -33,20 +33,23 @@ #include "ISerializer.h" #include "TTaskBaseData.h" #include -#include "log.h" #include "IFilesystem.h" +#include "..\Common\TLogger.h" namespace chcore { class TBufferSizes; /////////////////////////////////////////////////////////////////////////// // TTask + class TTask; + using TTaskPtr = std::shared_ptr; class LIBCHCORE_API TTask { private: - TTask(const ISerializerPtr& spSerializer, const IFeedbackHandlerPtr& spFeedbackHandler); + TTask(const ISerializerPtr& spSerializer, const IFeedbackHandlerPtr& spFeedbackHandler, const TTaskBaseData& rBaseTaskData); + TTask(const ISerializerPtr& spSerializer, const IFeedbackHandlerPtr& spFeedbackHandler, const TTaskDefinition& rTaskDefinition, const TSmartPath& rLogPath); public: ~TTask(); @@ -66,7 +69,7 @@ // thread void SetPriority(int nPriority); - void Load(); + static TTaskPtr Load(const ISerializerPtr& spSerializer, const IFeedbackHandlerPtr& spFeedbackHandler); void Store(bool bForce); void BeginProcessing(); @@ -85,10 +88,11 @@ void RestoreFeedbackDefaults(); private: + void Load(const TTaskBaseData& rBaseData); + void SetTaskDefinition(const TTaskDefinition& rTaskDefinition); void SetLogPath(const TSmartPath& pathLog); - log_file& GetLog(); // methods are called when task is being added or removed from the global task array /// Method is called when this task is being added to a TTaskManager object @@ -162,7 +166,10 @@ bool m_bContinue; // allows task to continue // other helpers - log_file m_log; ///< Log file where task information will be stored +#pragma warning(push) +#pragma warning(disable: 4251) + TLogger m_log; ///< Log file where task information will be stored +#pragma warning(pop) /// Thread controlling object TWorkerThreadController m_workerThread; @@ -181,8 +188,6 @@ friend class TTaskManager; }; - - typedef std::shared_ptr TTaskPtr; } #endif Index: src/libchcore/TTaskBaseData.h =================================================================== diff -u -re96806b7f8ff7ca7e9f4afbea603e6351a3dc3e3 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/libchcore/TTaskBaseData.h (.../TTaskBaseData.h) (revision e96806b7f8ff7ca7e9f4afbea603e6351a3dc3e3) +++ src/libchcore/TTaskBaseData.h (.../TTaskBaseData.h) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -29,9 +29,11 @@ { class LIBCHCORE_API TTaskBaseData { +/* private: TTaskBaseData(const TTaskBaseData&); TTaskBaseData& operator=(const TTaskBaseData&); +*/ public: TTaskBaseData(); Index: src/libchcore/TTaskConfigVerifier.cpp =================================================================== diff -u -rdcc6234ed612a75910b8900704c9d564096a037a -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/libchcore/TTaskConfigVerifier.cpp (.../TTaskConfigVerifier.cpp) (revision dcc6234ed612a75910b8900704c9d564096a037a) +++ src/libchcore/TTaskConfigVerifier.cpp (.../TTaskConfigVerifier.cpp) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -19,23 +19,22 @@ #include "stdafx.h" #include "TTaskConfigVerifier.h" #include "TTaskConfiguration.h" -#include "log.h" #include +#include "..\Common\TLogger.h" namespace chcore { - void TTaskConfigVerifier::VerifyAndUpdate(TConfig& rConfig, log_file* pLog) + void TTaskConfigVerifier::VerifyAndUpdate(TConfig& rConfig, TLogger* pLog) { TString strFirstFormat = GetTaskPropValue(rConfig); if(strFirstFormat.Find(L"%name") == TString::npos || strFirstFormat.Find(L"%ext") == TString::npos) { TString strDefaultFormat = TaskPropData::GetDefaultValue(); if(pLog) { - pLog->logw( - boost::str(boost::wformat(L"First alternate filename format string (%1%) does not contain %%name placeholder. Switching to default (%2%).") + LOG_WARNING(*pLog) << boost::str(boost::wformat(L"First alternate filename format string (%1%) does not contain %%name placeholder. Switching to default (%2%).") % strFirstFormat.c_str() - % strDefaultFormat.c_str()).c_str()); + % strDefaultFormat.c_str()).c_str(); } SetTaskPropValue(rConfig, strDefaultFormat); @@ -48,10 +47,10 @@ TString strDefaultFormat = TaskPropData::GetDefaultValue(); if(pLog) { - pLog->logw( + LOG_WARNING(*pLog) << boost::str(boost::wformat(L"Subsequent alternate filename format string (%1%) does not contain %%name or %%count placeholder. Switching to default (%2%).") % strSubsequentFormat.c_str() - % strDefaultFormat.c_str()).c_str()); + % strDefaultFormat.c_str()).c_str(); } SetTaskPropValue(rConfig, strDefaultFormat); Index: src/libchcore/TTaskConfigVerifier.h =================================================================== diff -u -rd18db617f4727a237c94b59af9b4328f829eda16 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/libchcore/TTaskConfigVerifier.h (.../TTaskConfigVerifier.h) (revision d18db617f4727a237c94b59af9b4328f829eda16) +++ src/libchcore/TTaskConfigVerifier.h (.../TTaskConfigVerifier.h) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -19,15 +19,16 @@ #ifndef __TTASKCONFIGVERIFIER_H__ #define __TTASKCONFIGVERIFIER_H__ +class TLogger; + namespace chcore { - class log_file; class TConfig; class TTaskConfigVerifier { public: - static void VerifyAndUpdate(TConfig& rConfig, log_file* pLog); + static void VerifyAndUpdate(TConfig& rConfig, TLogger* pLog); }; } Index: src/libchcore/TTaskManager.cpp =================================================================== diff -u -r4fe995b304ea342b50293f92d3c1992b43b820f7 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/libchcore/TTaskManager.cpp (.../TTaskManager.cpp) (revision 4fe995b304ea342b50293f92d3c1992b43b820f7) +++ src/libchcore/TTaskManager.cpp (.../TTaskManager.cpp) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -58,9 +58,7 @@ IFeedbackHandlerPtr spHandler = m_spFeedbackFactory->Create(); ISerializerPtr spSerializer = m_spSerializerFactory->CreateTaskSerializer(tTaskDefinition.GetTaskName()); - TTaskPtr spTask(new TTask(spSerializer, spHandler)); - spTask->SetLogPath(CreateTaskLogPath(tTaskDefinition.GetTaskName())); - spTask->SetTaskDefinition(tTaskDefinition); + TTaskPtr spTask(new TTask(spSerializer, spHandler, tTaskDefinition, CreateTaskLogPath(tTaskDefinition.GetTaskName()))); spTask->Store(true); @@ -524,8 +522,7 @@ if (!spSerializer) spSerializer = std::make_shared(rInfo.second); - TTaskPtr spTask(new TTask(spSerializer, spHandler)); - spTask->Load(); + TTaskPtr spTask = TTask::Load(spSerializer, spHandler); boost::unique_lock lock(m_lock); Index: src/libchcore/libchcore.vc140.vcxproj =================================================================== diff -u -rd18db617f4727a237c94b59af9b4328f829eda16 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/libchcore/libchcore.vc140.vcxproj (.../libchcore.vc140.vcxproj) (revision d18db617f4727a237c94b59af9b4328f829eda16) +++ src/libchcore/libchcore.vc140.vcxproj (.../libchcore.vc140.vcxproj) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -190,6 +190,7 @@ true ../../ext NoExtensions + 4512;4714 true @@ -213,6 +214,7 @@ true ..\..\ext\googletest\googletest\include;..\..\ext\googletest\googlemock\include;../../ext NoExtensions + 4512;4714 true @@ -253,7 +255,7 @@ Level4 false ProgramDatabase - 4996 + 4512;4714 false true ../../ext @@ -280,7 +282,7 @@ Level4 false ProgramDatabase - 4996 + 4512;4714 false true ..\..\ext\googletest\googletest\include;..\..\ext\googletest\googlemock\include;../../ext @@ -324,6 +326,7 @@ true ../../ext NoExtensions + 4512;4714 true @@ -349,6 +352,7 @@ true ..\..\ext\googletest\googletest\include;..\..\ext\googletest\googlemock\include;../../ext NoExtensions + 4512;4714 true @@ -393,6 +397,7 @@ ProgramDatabase true ../../ext + 4512;4714 true @@ -420,6 +425,7 @@ ProgramDatabase true ..\..\ext\googletest\googletest\include;..\..\ext\googletest\googlemock\include;../../ext + 4512;4714 true @@ -449,6 +455,8 @@ + + @@ -472,7 +480,6 @@ - @@ -482,6 +489,7 @@ + @@ -497,6 +505,7 @@ + @@ -562,7 +571,6 @@ - @@ -591,6 +599,8 @@ NotUsing NotUsing + + @@ -607,11 +617,11 @@ - + @@ -740,6 +750,7 @@ + @@ -799,7 +810,6 @@ - Index: src/libchcore/libchcore.vc140.vcxproj.filters =================================================================== diff -u -rd18db617f4727a237c94b59af9b4328f829eda16 -r6f8b891b60eb0f33199fd29db75d4d9f4a22c248 --- src/libchcore/libchcore.vc140.vcxproj.filters (.../libchcore.vc140.vcxproj.filters) (revision d18db617f4727a237c94b59af9b4328f829eda16) +++ src/libchcore/libchcore.vc140.vcxproj.filters (.../libchcore.vc140.vcxproj.filters) (revision 6f8b891b60eb0f33199fd29db75d4d9f4a22c248) @@ -78,12 +78,18 @@ {b5e932b3-5a5a-465b-8ade-3354c81e1996} - - {4a321c2c-525d-4a77-bad6-d01210bba74c} - {953a12ea-2aa5-4c7a-a310-a461ce8b962f} + + {0bd6a559-b992-4f1d-abe6-f8105a9d5f50} + + + {4a321c2c-525d-4a77-bad6-d01210bba74c} + + + {0e547635-8b67-4a9e-9ade-40d3d7ffc5fc} + @@ -452,18 +458,24 @@ Source Files\Feedback - - Source Files\Tools\Logging - - - Source Files\Tools\Logging - Source Files\SubTasks Source Files\Task Config + + Source Files\Shared\Logging + + + Source Files\Shared\Logging + + + Source Files\Tools\Logging + + + Source Files\Library files + @@ -832,12 +844,6 @@ Source Files\Feedback - - Source Files\Tools\Logging - - - Source Files\Tools\Logging - Source Files\SubTasks @@ -850,5 +856,17 @@ Tests\TaskConfig + + Source Files\Shared\Logging + + + Source Files\Shared\Logging + + + Source Files\Tools\Logging + + + Source Files + \ No newline at end of file Fisheye: Tag 6f8b891b60eb0f33199fd29db75d4d9f4a22c248 refers to a dead (removed) revision in file `src/libchcore/log.cpp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 6f8b891b60eb0f33199fd29db75d4d9f4a22c248 refers to a dead (removed) revision in file `src/libchcore/log.h'. Fisheye: No comparison available. Pass `N' to diff?