merge the formfield patch from ooo-build
[ooovba.git] / comphelper / source / misc / uieventslogger.cxx
blob2a109dbce122e38a59b351df2de5059fb0f55226
1 /*************************************************************************
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3 *
4 * Copyright 2008 by Sun Microsystems, Inc.
6 * OpenOffice.org - a multi-platform office productivity suite
8 * $RCSfile: uieventslogger.cxx,v $
10 * $Revision: 1.3.20.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
28 ***********************************************************************/
30 // MARKER(update_precomp.py): autogen include statement, do not remove
31 #include "precompiled_comphelper.hxx"
33 #include <comphelper/uieventslogger.hxx>
34 #include <boost/shared_ptr.hpp>
35 #include <com/sun/star/frame/XDesktop.hpp>
36 #include <com/sun/star/frame/XTerminateListener.hpp>
37 #include <com/sun/star/lang/XEventListener.hpp>
38 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
39 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40 #include <com/sun/star/logging/LogLevel.hpp>
41 #include <com/sun/star/logging/XCsvLogFormatter.hpp>
42 #include <com/sun/star/logging/XLogHandler.hpp>
43 #include <com/sun/star/logging/XLogger.hpp>
44 #include <com/sun/star/logging/XLoggerPool.hpp>
45 #include <com/sun/star/oooimprovement/XCoreController.hpp>
46 #include <com/sun/star/uno/Sequence.hxx>
47 #include <com/sun/star/util/XStringSubstitution.hpp>
48 #include <comphelper/configurationhelper.hxx>
49 #include <comphelper/processfactory.hxx>
50 #include <map>
51 #include <osl/file.hxx>
52 #include <osl/mutex.hxx>
53 #include <osl/time.h>
54 #include <rtl/ustrbuf.hxx>
57 using namespace com::sun::star::beans;
58 using namespace com::sun::star::frame;
59 using namespace com::sun::star::lang;
60 using namespace com::sun::star::logging;
61 using namespace com::sun::star::oooimprovement;
62 using namespace com::sun::star::uno;
63 using namespace com::sun::star::util;
64 using namespace cppu;
65 using namespace osl;
66 using namespace rtl;
67 using namespace std;
70 namespace
72 static void lcl_SetupOriginAppAbbr(map<OUString, OUString>& abbrs)
74 abbrs[OUString::createFromAscii("com.sun.star.text.TextDocument")] = OUString::createFromAscii("W"); // Writer
75 abbrs[OUString::createFromAscii("com.sun.star.sheet.SpreadsheetDocument")] = OUString::createFromAscii("C"); // Calc
76 abbrs[OUString::createFromAscii("com.sun.star.presentation.PresentationDocument")] = OUString::createFromAscii("I"); // Impress
77 abbrs[OUString::createFromAscii("com.sun.star.drawing.DrawingDocument")] = OUString::createFromAscii("D"); // Draw
80 static void lcl_SetupOriginWidgetAbbr(map<OUString,OUString>& abbrs)
82 abbrs[OUString::createFromAscii("ButtonToolbarController")] = OUString::createFromAscii("0");
83 abbrs[OUString::createFromAscii("ComplexToolbarController")] = OUString::createFromAscii("1");
84 abbrs[OUString::createFromAscii("ControlMenuController")] = OUString::createFromAscii("2");
85 abbrs[OUString::createFromAscii("FontMenuController")] = OUString::createFromAscii("3");
86 abbrs[OUString::createFromAscii("FontSizeMenuController")] = OUString::createFromAscii("4");
87 abbrs[OUString::createFromAscii("FooterMenuController")] = OUString::createFromAscii("5");
88 abbrs[OUString::createFromAscii("GenericToolbarController")] = OUString::createFromAscii("6");
89 abbrs[OUString::createFromAscii("HeaderMenuController")] = OUString::createFromAscii("7");
90 abbrs[OUString::createFromAscii("LanguageSelectionMenuController")] = OUString::createFromAscii("8");
91 abbrs[OUString::createFromAscii("LangSelectionStatusbarController")] = OUString::createFromAscii("9");
92 abbrs[OUString::createFromAscii("MacrosMenuController")] = OUString::createFromAscii("10");
93 abbrs[OUString::createFromAscii("MenuBarManager")] = OUString::createFromAscii("11");
94 abbrs[OUString::createFromAscii("NewMenuController")] = OUString::createFromAscii("12");
95 abbrs[OUString::createFromAscii("ObjectMenuController")] = OUString::createFromAscii("13");
96 abbrs[OUString::createFromAscii("RecentFilesMenuController")] = OUString::createFromAscii("14");
97 abbrs[OUString::createFromAscii("ToolbarsMenuController")] = OUString::createFromAscii("15");
98 abbrs[OUString::createFromAscii("SfxToolBoxControl")] = OUString::createFromAscii("16");
99 abbrs[OUString::createFromAscii("SfxAsyncExec")] = OUString::createFromAscii("17");
100 abbrs[OUString::createFromAscii("AcceleratorExecute")] = OUString::createFromAscii("18");
104 namespace comphelper
106 // declaration of implementation
107 class UiEventsLogger_Impl;
108 class UiEventsLogger_Impl : public UiEventsLogger
110 private:
111 //typedefs and friends
112 friend class UiEventsLogger;
113 typedef UiEventsLogger_Impl* ptr;
115 // instance methods and data
116 UiEventsLogger_Impl();
117 void initializeLogger();
118 void logDispatch(const ::com::sun::star::util::URL& url,
119 const Sequence<PropertyValue>& args);
120 void logRotated();
121 void logVcl(const ::rtl::OUString& parent_id,
122 sal_Int32 window_type,
123 const ::rtl::OUString& id,
124 const ::rtl::OUString& method,
125 const ::rtl::OUString& param);
126 void rotate();
127 void hotRotate();
128 void prepareLogHandler();
129 void checkIdleTimeout();
130 OUString getCurrentPath();
131 OUString getRotatedPath();
132 void disposing();
134 bool m_Active;
135 TimeValue m_LastLogEventTime;
136 const OUString m_LogPath;
137 const TimeValue m_IdleTimeout;
138 sal_Int32 m_SessionLogEventCount;
139 Reference<XLogger> m_Logger;
140 Reference<XLogHandler> m_LogHandler;
141 Reference<XCsvLogFormatter> m_Formatter;
142 map<OUString, OUString> m_OriginAppAbbr;
143 map<OUString, OUString> m_OriginWidgetAbbr;
146 // static methods and data
147 static ptr getInstance();
148 static void prepareMutex();
149 static bool shouldActivate();
150 static bool getEnabledFromCoreController();
151 static bool getEnabledFromCfg();
152 static TimeValue getIdleTimeoutFromCfg();
153 static OUString getLogPathFromCfg();
154 static sal_Int32 findIdx(const Sequence<PropertyValue>& args, const OUString& key);
156 static ptr instance;
157 static Mutex * singleton_mutex;
158 static const sal_Int32 COLUMNS;
159 static const OUString CFG_ENABLED;
160 static const OUString CFG_IDLETIMEOUT;
161 static const OUString CFG_LOGGING;
162 static const OUString CFG_LOGPATH;
163 static const OUString CFG_OOOIMPROVEMENT;
164 static const OUString ETYPE_DISPATCH;
165 static const OUString ETYPE_ROTATED;
166 static const OUString ETYPE_VCL;
167 static const OUString CSSL_CSVFORMATTER;
168 static const OUString CSSL_FILEHANDLER;
169 static const OUString CSSL_LOGGERPOOL;
170 static const OUString CSSO_CORECONTROLLER;
171 static const OUString CSST_JOBEXECUTOR;
172 static const OUString CSSU_PATHSUB;
173 static const OUString LOGGERNAME;
174 static const OUString LOGORIGINAPP;
175 static const OUString LOGORIGINWIDGET;
176 static const OUString UNKNOWN_ORIGIN;
177 static const OUString FN_CURRENTLOG;
178 static const OUString FN_ROTATEDLOG;
179 static const OUString LOGROTATE_EVENTNAME;
180 static const OUString URL_UNO;
181 static const OUString URL_FILE;
185 namespace comphelper
187 // consts
188 const sal_Int32 UiEventsLogger_Impl::COLUMNS = 9;
189 const OUString UiEventsLogger_Impl::CFG_ENABLED = OUString::createFromAscii("EnablingAllowed");
190 const OUString UiEventsLogger_Impl::CFG_IDLETIMEOUT = OUString::createFromAscii("IdleTimeout");
191 const OUString UiEventsLogger_Impl::CFG_LOGGING = OUString::createFromAscii("/org.openoffice.Office.Logging");
192 const OUString UiEventsLogger_Impl::CFG_LOGPATH = OUString::createFromAscii("LogPath");
193 const OUString UiEventsLogger_Impl::CFG_OOOIMPROVEMENT = OUString::createFromAscii("OOoImprovement");
195 const OUString UiEventsLogger_Impl::CSSL_CSVFORMATTER = OUString::createFromAscii("com.sun.star.logging.CsvFormatter");
196 const OUString UiEventsLogger_Impl::CSSL_FILEHANDLER = OUString::createFromAscii("com.sun.star.logging.FileHandler");
197 const OUString UiEventsLogger_Impl::CSSL_LOGGERPOOL = OUString::createFromAscii("com.sun.star.logging.LoggerPool");
198 const OUString UiEventsLogger_Impl::CSSO_CORECONTROLLER = OUString::createFromAscii("com.sun.star.oooimprovement.CoreController");
199 const OUString UiEventsLogger_Impl::CSSU_PATHSUB = OUString::createFromAscii("com.sun.star.util.PathSubstitution");
201 const OUString UiEventsLogger_Impl::ETYPE_DISPATCH = OUString::createFromAscii("dispatch");
202 const OUString UiEventsLogger_Impl::ETYPE_ROTATED = OUString::createFromAscii("rotated");
203 const OUString UiEventsLogger_Impl::ETYPE_VCL = OUString::createFromAscii("vcl");
205 const OUString UiEventsLogger_Impl::LOGGERNAME = OUString::createFromAscii("org.openoffice.oooimprovement.Core.UiEventsLogger");
206 const OUString UiEventsLogger_Impl::LOGORIGINWIDGET = OUString::createFromAscii("comphelper.UiEventsLogger.LogOriginWidget");
207 const OUString UiEventsLogger_Impl::LOGORIGINAPP = OUString::createFromAscii("comphelper.UiEventsLogger.LogOriginApp");
209 const OUString UiEventsLogger_Impl::UNKNOWN_ORIGIN = OUString::createFromAscii("unknown origin");
210 const OUString UiEventsLogger_Impl::FN_CURRENTLOG = OUString::createFromAscii("Current");
211 const OUString UiEventsLogger_Impl::FN_ROTATEDLOG = OUString::createFromAscii("OOoImprove");
212 const OUString UiEventsLogger_Impl::LOGROTATE_EVENTNAME = OUString::createFromAscii("onOOoImprovementLogRotated");
214 const OUString UiEventsLogger_Impl::URL_UNO = OUString::createFromAscii(".uno:");
215 const OUString UiEventsLogger_Impl::URL_FILE = OUString::createFromAscii("file:");
218 // public UiEventsLogger interface
219 sal_Bool UiEventsLogger::isEnabled()
221 if ( UiEventsLogger_Impl::getEnabledFromCfg() )
223 try {
224 UiEventsLogger_Impl::prepareMutex();
225 Guard<Mutex> singleton_guard(UiEventsLogger_Impl::singleton_mutex);
226 return UiEventsLogger_Impl::getInstance()->m_Active;
227 } catch(...) { return false; } // never throws
228 } // if ( )
229 return sal_False;
232 sal_Int32 UiEventsLogger::getSessionLogEventCount()
234 try {
235 UiEventsLogger_Impl::prepareMutex();
236 Guard<Mutex> singleton_guard(UiEventsLogger_Impl::singleton_mutex);
237 return UiEventsLogger_Impl::getInstance()->m_SessionLogEventCount;
238 } catch(...) { return 0; } // never throws
241 void UiEventsLogger::appendDispatchOrigin(
242 Sequence<PropertyValue>& args,
243 const OUString& originapp,
244 const OUString& originwidget)
246 sal_Int32 old_length = args.getLength();
247 args.realloc(old_length+2);
248 args[old_length].Name = UiEventsLogger_Impl::LOGORIGINAPP;
249 args[old_length].Value = static_cast<Any>(originapp);
250 args[old_length+1].Name = UiEventsLogger_Impl::LOGORIGINWIDGET;
251 args[old_length+1].Value = static_cast<Any>(originwidget);
254 Sequence<PropertyValue> UiEventsLogger::purgeDispatchOrigin(
255 const Sequence<PropertyValue>& args)
257 Sequence<PropertyValue> result(args.getLength());
258 sal_Int32 target_idx=0;
259 for(sal_Int32 source_idx=0; source_idx<args.getLength(); source_idx++)
260 if(args[source_idx].Name != UiEventsLogger_Impl::LOGORIGINAPP
261 && args[source_idx].Name != UiEventsLogger_Impl::LOGORIGINWIDGET)
262 result[target_idx++] = args[source_idx];
263 result.realloc(target_idx);
264 return result;
267 void UiEventsLogger::logDispatch(
268 const URL& url,
269 const Sequence<PropertyValue>& args)
271 try {
272 UiEventsLogger_Impl::prepareMutex();
273 Guard<Mutex> singleton_guard(UiEventsLogger_Impl::singleton_mutex);
274 UiEventsLogger_Impl::getInstance()->logDispatch(url, args);
275 } catch(...) { } // never throws
278 void UiEventsLogger::logVcl(
279 const OUString& parent_id,
280 sal_Int32 window_type,
281 const OUString& id,
282 const OUString& method,
283 const OUString& param)
285 try {
286 UiEventsLogger_Impl::prepareMutex();
287 Guard<Mutex> singleton_guard(UiEventsLogger_Impl::singleton_mutex);
288 UiEventsLogger_Impl::getInstance()->logVcl(parent_id, window_type, id, method, param);
289 } catch(...) { } // never throws
292 void UiEventsLogger::logVcl(
293 const OUString& parent_id,
294 sal_Int32 window_type,
295 const OUString& id,
296 const OUString& method,
297 sal_Int32 param)
299 OUStringBuffer buf;
300 UiEventsLogger::logVcl(parent_id, window_type, id, method, buf.append(param).makeStringAndClear());
303 void UiEventsLogger::logVcl(
304 const OUString& parent_id,
305 sal_Int32 window_type,
306 const OUString& id,
307 const OUString& method)
309 OUString empty;
310 UiEventsLogger::logVcl(parent_id, window_type, id, method, empty);
313 void UiEventsLogger::disposing()
315 // we dont want to create an instance just to dispose it
316 UiEventsLogger_Impl::prepareMutex();
317 Guard<Mutex> singleton_guard(UiEventsLogger_Impl::singleton_mutex);
318 if(UiEventsLogger_Impl::instance!=UiEventsLogger_Impl::ptr())
319 UiEventsLogger_Impl::getInstance()->disposing();
322 void UiEventsLogger::reinit()
324 UiEventsLogger_Impl::prepareMutex();
325 Guard<Mutex> singleton_guard(UiEventsLogger_Impl::singleton_mutex);
326 if(UiEventsLogger_Impl::instance)
328 UiEventsLogger_Impl::instance->disposing();
329 delete UiEventsLogger_Impl::instance;
330 UiEventsLogger_Impl::instance = NULL;
334 // private UiEventsLogger_Impl methods
335 UiEventsLogger_Impl::UiEventsLogger_Impl()
336 : m_Active(UiEventsLogger_Impl::shouldActivate())
337 , m_LogPath(UiEventsLogger_Impl::getLogPathFromCfg())
338 , m_IdleTimeout(UiEventsLogger_Impl::getIdleTimeoutFromCfg())
339 , m_SessionLogEventCount(0)
341 lcl_SetupOriginAppAbbr(m_OriginAppAbbr);
342 lcl_SetupOriginWidgetAbbr(m_OriginWidgetAbbr);
343 m_LastLogEventTime.Seconds = m_LastLogEventTime.Nanosec = 0;
344 if(m_Active) rotate();
345 if(m_Active) initializeLogger();
348 void UiEventsLogger_Impl::logDispatch(
349 const URL& url,
350 const Sequence<PropertyValue>& args)
352 if(!m_Active) return;
353 if(!url.Complete.match(URL_UNO) && !url.Complete.match(URL_FILE)) return;
354 checkIdleTimeout();
356 Sequence<OUString> logdata = Sequence<OUString>(COLUMNS);
357 logdata[0] = ETYPE_DISPATCH;
358 sal_Int32 originapp_idx = findIdx(args, LOGORIGINAPP);
359 if(originapp_idx!=-1)
361 OUString app;
362 args[originapp_idx].Value >>= app;
363 map<OUString, OUString>::iterator abbr_it = m_OriginAppAbbr.find(app);
364 if(abbr_it != m_OriginAppAbbr.end())
365 app = abbr_it->second;
366 logdata[1] = app;
368 else
369 logdata[1] = UNKNOWN_ORIGIN;
370 sal_Int32 originwidget_idx = findIdx(args, LOGORIGINWIDGET);
371 if(originwidget_idx!=-1)
373 OUString widget;
374 args[originwidget_idx].Value >>= widget;
375 map<OUString, OUString>::iterator widget_it = m_OriginWidgetAbbr.find(widget);
376 if(widget_it != m_OriginWidgetAbbr.end())
377 widget = widget_it->second;
378 logdata[2] = widget;
380 else
381 logdata[2] = UNKNOWN_ORIGIN;
382 if(url.Complete.match(URL_FILE))
383 logdata[3] = URL_FILE;
384 else
385 logdata[3] = url.Main;
386 m_Logger->log(LogLevel::INFO, m_Formatter->formatMultiColumn(logdata));
387 m_SessionLogEventCount++;
390 void UiEventsLogger_Impl::logRotated()
392 Sequence<OUString> logdata = Sequence<OUString>(COLUMNS);
393 logdata[0] = ETYPE_ROTATED;
394 m_Logger->log(LogLevel::INFO, m_Formatter->formatMultiColumn(logdata));
397 void UiEventsLogger_Impl::logVcl(
398 const OUString& parent_id,
399 sal_Int32 window_type,
400 const OUString& id,
401 const OUString& method,
402 const OUString& param)
404 if(!m_Active) return;
405 checkIdleTimeout();
407 OUStringBuffer buf;
408 Sequence<OUString> logdata = Sequence<OUString>(COLUMNS);
409 logdata[0] = ETYPE_VCL;
410 logdata[4] = parent_id;
411 logdata[5] = buf.append(window_type).makeStringAndClear();
412 logdata[6] = id;
413 logdata[7] = method;
414 logdata[8] = param;
415 m_Logger->log(LogLevel::INFO, m_Formatter->formatMultiColumn(logdata));
416 m_SessionLogEventCount++;
419 void UiEventsLogger_Impl::rotate()
421 FileBase::RC result = File::move(getCurrentPath(), getRotatedPath());
422 if(result!=FileBase::E_None && result!=FileBase::E_NOENT)
423 m_Active = false;
426 void UiEventsLogger_Impl::hotRotate()
428 logRotated();
429 m_Logger->removeLogHandler(m_LogHandler);
430 m_LogHandler = NULL;
431 rotate();
432 prepareLogHandler();
433 if(m_Formatter.is() && m_LogHandler.is() && m_Logger.is())
435 m_LogHandler->setFormatter(Reference<XLogFormatter>(m_Formatter, UNO_QUERY));
436 m_LogHandler->setLevel(LogLevel::ALL);
437 m_Logger->addLogHandler(m_LogHandler);
439 else
440 m_Active = false;
443 void UiEventsLogger_Impl::prepareLogHandler()
445 Reference<XMultiServiceFactory> sm = getProcessServiceFactory();
447 Sequence<Any> init_args = Sequence<Any>(1);
448 init_args[0] = static_cast<Any>(getCurrentPath());
449 Reference< XInterface > temp =
450 sm->createInstanceWithArguments(CSSL_FILEHANDLER, init_args);
451 m_LogHandler = Reference<XLogHandler>(temp, UNO_QUERY);
454 void UiEventsLogger_Impl::checkIdleTimeout()
456 TimeValue now;
457 osl_getSystemTime(&now);
458 if(now.Seconds - m_LastLogEventTime.Seconds > m_IdleTimeout.Seconds && m_SessionLogEventCount>0)
459 hotRotate();
460 m_LastLogEventTime = now;
463 OUString UiEventsLogger_Impl::getCurrentPath()
465 OUStringBuffer current_path(m_LogPath);
466 current_path.appendAscii("/");
467 current_path.append(FN_CURRENTLOG);
468 current_path.appendAscii(".csv");
469 return current_path.makeStringAndClear();
472 OUString UiEventsLogger_Impl::getRotatedPath()
474 OUStringBuffer rotated_path(m_LogPath);
475 rotated_path.appendAscii("/");
476 rotated_path.append(FN_ROTATEDLOG);
477 rotated_path.appendAscii("-");
479 // ISO 8601
480 char tsrotated_pathfer[20];
481 oslDateTime now;
482 TimeValue now_tv;
483 osl_getSystemTime(&now_tv);
484 osl_getDateTimeFromTimeValue(&now_tv, &now);
485 const size_t rotated_pathfer_size = sizeof(tsrotated_pathfer);
486 snprintf(tsrotated_pathfer, rotated_pathfer_size, "%04i-%02i-%02iT%02i_%02i_%02i",
487 now.Year,
488 now.Month,
489 now.Day,
490 now.Hours,
491 now.Minutes,
492 now.Seconds);
493 rotated_path.appendAscii(tsrotated_pathfer);
494 rotated_path.appendAscii(".csv");
496 return rotated_path.makeStringAndClear();
499 void UiEventsLogger_Impl::initializeLogger()
501 Reference<XMultiServiceFactory> sm = getProcessServiceFactory();
503 // getting the Core Uno proxy object
504 // It will call disposing and make sure we clear all our references
506 Reference<XTerminateListener> xCore(
507 sm->createInstance(OUString::createFromAscii("com.sun.star.oooimprovement.Core")),
508 UNO_QUERY);
509 Reference<XDesktop> xDesktop(
510 sm->createInstance(OUString::createFromAscii("com.sun.star.frame.Desktop")),
511 UNO_QUERY);
512 if(!(xCore.is() && xDesktop.is()))
514 m_Active = false;
515 return;
517 xDesktop->addTerminateListener(xCore);
519 // getting the LoggerPool
520 Reference<XLoggerPool> pool;
522 Reference<XInterface> temp =
523 sm->createInstance(CSSL_LOGGERPOOL);
524 pool = Reference<XLoggerPool>(temp, UNO_QUERY);
527 // getting the Logger
528 m_Logger = pool->getNamedLogger(LOGGERNAME);
530 // getting the FileHandler
531 prepareLogHandler();
533 // getting the Formatter
535 Reference<XInterface> temp =
536 sm->createInstance(CSSL_CSVFORMATTER);
537 m_Formatter = Reference<XCsvLogFormatter>(temp, UNO_QUERY);
540 if(m_Formatter.is() && m_LogHandler.is() && m_Logger.is())
542 Sequence<OUString> columns = Sequence<OUString>(COLUMNS);
543 columns[0] = OUString::createFromAscii("eventtype");
544 columns[1] = OUString::createFromAscii("originapp");
545 columns[2] = OUString::createFromAscii("originwidget");
546 columns[3] = OUString::createFromAscii("uno url");
547 columns[4] = OUString::createFromAscii("parent id");
548 columns[5] = OUString::createFromAscii("window type");
549 columns[6] = OUString::createFromAscii("id");
550 columns[7] = OUString::createFromAscii("method");
551 columns[8] = OUString::createFromAscii("parameter");
552 m_Formatter->setColumnnames(columns);
553 m_LogHandler->setFormatter(Reference<XLogFormatter>(m_Formatter, UNO_QUERY));
554 m_Logger->setLevel(LogLevel::ALL);
555 m_LogHandler->setLevel(LogLevel::ALL);
556 m_Logger->addLogHandler(m_LogHandler);
558 else
559 m_Active = false;
562 // private static UiEventsLogger_Impl
563 bool UiEventsLogger_Impl::shouldActivate()
565 return getEnabledFromCfg() && getEnabledFromCoreController();
568 OUString UiEventsLogger_Impl::getLogPathFromCfg()
570 OUString result;
571 Reference<XMultiServiceFactory> sm = getProcessServiceFactory();
573 ConfigurationHelper::readDirectKey(
575 CFG_LOGGING, CFG_OOOIMPROVEMENT, CFG_LOGPATH,
576 ConfigurationHelper::E_READONLY
577 ) >>= result;
579 Reference<XStringSubstitution> path_sub(
580 sm->createInstance(CSSU_PATHSUB),
581 UNO_QUERY);
582 if(path_sub.is())
583 result = path_sub->substituteVariables(result, sal_False);
584 return result;
587 TimeValue UiEventsLogger_Impl::getIdleTimeoutFromCfg()
589 sal_Int32 timeoutminutes = 360;
590 Reference<XMultiServiceFactory> sm = getProcessServiceFactory();
592 ConfigurationHelper::readDirectKey(
594 CFG_LOGGING, CFG_OOOIMPROVEMENT, CFG_IDLETIMEOUT,
595 ConfigurationHelper::E_READONLY
596 ) >>= timeoutminutes;
597 TimeValue result;
598 result.Seconds = static_cast<sal_uInt32>(timeoutminutes)*60;
599 result.Nanosec = 0;
600 return result;
603 bool UiEventsLogger_Impl::getEnabledFromCfg()
605 sal_Bool result = false;
606 Reference<XMultiServiceFactory> sm = getProcessServiceFactory();
607 ConfigurationHelper::readDirectKey(
609 CFG_LOGGING, CFG_OOOIMPROVEMENT, CFG_ENABLED,
610 ::comphelper::ConfigurationHelper::E_READONLY
611 ) >>= result;
612 return result;
615 bool UiEventsLogger_Impl::getEnabledFromCoreController()
617 Reference<XMultiServiceFactory> sm = getProcessServiceFactory();
618 Reference<XCoreController> core_c(
619 sm->createInstance(OUString::createFromAscii("com.sun.star.oooimprovement.CoreController")),
620 UNO_QUERY);
621 if(!core_c.is()) return false;
622 return core_c->enablingUiEventsLoggerAllowed(1);
625 UiEventsLogger_Impl::ptr UiEventsLogger_Impl::instance = UiEventsLogger_Impl::ptr();
626 UiEventsLogger_Impl::ptr UiEventsLogger_Impl::getInstance()
628 if(instance == NULL)
629 instance = UiEventsLogger_Impl::ptr(new UiEventsLogger_Impl());
630 return instance;
633 Mutex * UiEventsLogger_Impl::singleton_mutex = NULL;
634 void UiEventsLogger_Impl::prepareMutex()
636 if(singleton_mutex == NULL)
638 Guard<Mutex> global_guard(Mutex::getGlobalMutex());
639 if(singleton_mutex == NULL)
640 singleton_mutex = new Mutex();
644 sal_Int32 UiEventsLogger_Impl::findIdx(const Sequence<PropertyValue>& args, const OUString& key)
646 for(sal_Int32 i=0; i<args.getLength(); i++)
647 if(args[i].Name == key)
648 return i;
649 return -1;
652 void UiEventsLogger_Impl::disposing()
654 m_Active = false;
655 m_Logger.clear() ;
656 m_LogHandler.clear();
657 m_Formatter.clear();