Clone
ixen <ixen@copyhandler.com>
committed
on 08 Dec 16
Introduced engine-wide logging (with task manager serialization included). Moved serialization logging from debug tracing to a normal log fi… Show more
Introduced engine-wide logging (with task manager serialization included). Moved serialization logging from debug tracing to a normal log file. (CH-114)

Show less

ch-1.40 + 2 more
src/ch/MainWnd.cpp (+8 -3)
26 26 #include "AboutDlg.h"
27 27 #include "../common/ipcstructs.h"
28 28 #include "UpdateChecker.h"
29 29 #include "UpdaterDlg.h"
30 30 #include "MiniviewDlg.h"
31 31 #include "StatusDlg.h"
32 32 #include "ClipboardMonitor.h"
33 33 #include <boost/shared_array.hpp>
34 34 #include "../common/TShellExtMenuConfig.h"
35 35 #include "../libchcore/TConfig.h"
36 36 #include "../libchcore/TCoreException.h"
37 37 #include "../libchcore/TTaskManagerStatsSnapshot.h"
38 38 #include "../libchcore/TSQLiteSerializerFactory.h"
39 39 #include "TRecentPathsTools.h"
40 40 #include "DirectoryChooser.h"
41 41 #include "FeedbackHandlerFactory.h"
42 42 #include "../libchcore/TTask.h"
43 43 #include "TTaskManagerWrapper.h"
44 44 #include "CfgProperties.h"
45 45 #include "resource.h"
  46 #include "../liblogger/TAsyncMultiLogger.h"
46 47
47 48 #ifdef _DEBUG
48 49 #define new DEBUG_NEW
49 50 #undef THIS_FILE
50 51 static char THIS_FILE[] = __FILE__;
51 52 #endif
52 53
53 54 #define CH_WNDCLASS_NAME   _T("Copy Handler Wnd Class")
54 55
55 56 #define WM_TRAYNOTIFY                   (WM_USER+0)
56 57
57 58 #define WM_ICON_NOTIFY                  WM_USER+4
58 59 #define WM_SHOWMINIVIEW                 WM_USER+3
59 60 #define WM_IDENTIFY                             WM_USER+11
60 61
61 62 #define TM_AUTOREMOVE                   1000
62 63 #define TM_ACCEPTING                    100
63 64
64 65 extern int iCount;
65 66 extern unsigned short msg[];
 
220 221         catch(...)
221 222         {
222 223                 bCaughtError = true;
223 224                 _snwprintf_s(szErrInfo.get(), stMaxErrInfo, _TRUNCATE, _T("Caught an unknown exception"));
224 225         }
225 226
226 227         if(bCaughtError)
227 228         {
228 229                 LOG_ERROR(m_spLog) << szErrInfo.get();
229 230                 return -1;
230 231         }
231 232         return 0;
232 233 }
233 234
234 235 bool CMainWnd::LoadTaskManager()
235 236 {
236 237         using namespace chcore;
237 238
238 239         CString strError;
239 240         CString strTasksDir = GetTasksDirectory();
240           TSQLiteSerializerFactoryPtr spSerializerFactory(new TSQLiteSerializerFactory(PathFromString(strTasksDir)));
  241         TSmartPath pathEngineLog = PathFromString(strTasksDir) + PathFromString(_T("engine.log"));
  242
  243         logger::TLogFileDataPtr spLogFileData = logger::TAsyncMultiLogger::GetInstance()->CreateLoggerData(pathEngineLog.ToString(), GetApp().GetEngineLoggerConfig());
  244
  245         TSQLiteSerializerFactoryPtr spSerializerFactory(new TSQLiteSerializerFactory(PathFromString(strTasksDir), spLogFileData));
241 246         IFeedbackHandlerFactoryPtr spFeedbackFactory(new CFeedbackHandlerFactory);
242 247
243 248         try
244 249         {
245                   m_spTasks.reset(new chcore::TTaskManager(spSerializerFactory, spFeedbackFactory, PathFromString(strTasksDir), GetApp().GetEngineLoggerConfig()));
  250                 m_spTasks.reset(new chcore::TTaskManager(spSerializerFactory, spFeedbackFactory, PathFromString(strTasksDir), GetApp().GetEngineLoggerConfig(), spLogFileData));
246 251         }
247 252         catch(const std::exception& e)
248 253         {
249 254                 strError = e.what();
250 255         }
251 256
252 257         if(!strError.IsEmpty())
253 258         {
254 259                 if(MsgBox(IDS_TASKMANAGER_LOAD_FAILED, MB_ICONERROR | MB_OKCANCEL) == IDOK)
255 260                 {
256                           m_spTasks.reset(new chcore::TTaskManager(spSerializerFactory, spFeedbackFactory, PathFromString(strTasksDir), GetApp().GetEngineLoggerConfig(), true));
  261                         m_spTasks.reset(new chcore::TTaskManager(spSerializerFactory, spFeedbackFactory, PathFromString(strTasksDir), GetApp().GetEngineLoggerConfig(), spLogFileData, true));
257 262                 }
258 263                 else
259 264                         return false;
260 265         }
261 266
262 267         // load last state
263 268         LOG_INFO(m_spLog) << _T("Loading existing tasks...");
264 269
265 270         // load tasks
266 271         m_spTasks->Load();
267 272
268 273         return true;
269 274 }
270 275
271 276 LRESULT CMainWnd::OnTrayNotification(WPARAM wParam, LPARAM lParam)
272 277 {
273 278         if (wParam != m_ctlTray.m_tnd.uID)
274 279                 return (LRESULT)FALSE;
275 280
276 281         switch(LOWORD(lParam))