@@ -343,46 +343,9 @@ const char *x11opcodeToString(unsigned char opcode)
343
343
return " " ;
344
344
}
345
345
346
- static const char *strLevel (int level)
347
- {
348
- switch (level)
349
- {
350
- case LOG_EMERG:
351
- return " Emergency" ;
352
-
353
- case LOG_ALERT:
354
- return " Alert" ;
355
-
356
- case LOG_CRIT:
357
- return " Critical" ;
358
-
359
- case LOG_ERR:
360
- return " Error" ;
361
-
362
- case LOG_WARNING:
363
- return " Warning" ;
364
-
365
- case LOG_NOTICE:
366
- return " Notice" ;
367
-
368
- case LOG_INFO:
369
- return " Info" ;
370
-
371
- case LOG_DEBUG:
372
- return " Debug" ;
373
-
374
- default :
375
- return " " ;
376
- }
377
- }
378
-
379
-
380
346
Core::Core (bool useSyslog, bool minLogLevelSet, int minLogLevel, const QStringList &configFiles, bool multipleActionsBehaviourSet, MultipleActionsBehaviour multipleActionsBehaviour, QObject *parent)
381
347
: QThread(parent)
382
- , LogTarget()
383
348
, mReady(false )
384
- , mUseSyslog(useSyslog)
385
- , mMinLogLevel(minLogLevel)
386
349
, mDisplay(nullptr )
387
350
, mInterClientCommunicationWindow(0 )
388
351
, mServiceWatcher{new QDBusServiceWatcher{this }}
@@ -403,8 +366,11 @@ Core::Core(bool useSyslog, bool minLogLevelSet, int minLogLevel, const QStringLi
403
366
{
404
367
#if 0
405
368
// debugging
406
- mUseSyslog = false;
407
- mMinLogLevel = 7;
369
+ Q_UNUSED(minLogLevel);
370
+ Q_UNUSED(useSyslog);
371
+ mCoreLogger = std::make_unique<LogTarget>(LOG_DEBUG, false);
372
+ #else
373
+ s_CoreLogTarget = std::make_unique<LogTarget>(minLogLevel, useSyslog);
408
374
#endif
409
375
410
376
s_Core = this ;
@@ -489,31 +455,8 @@ Core::Core(bool useSyslog, bool minLogLevelSet, int minLogLevel, const QStringLi
489
455
iniValue = settings.value (/* General/ */ QStringLiteral (" LogLevel" )).toString ();
490
456
if (!iniValue.isEmpty ())
491
457
{
492
- minLogLevelSet = true ;
493
- if (iniValue == QLatin1String (" error" ))
494
- {
495
- mMinLogLevel = LOG_ERR;
496
- }
497
- else if (iniValue == QLatin1String (" warning" ))
498
- {
499
- mMinLogLevel = LOG_WARNING;
500
- }
501
- else if (iniValue == QLatin1String (" notice" ))
502
- {
503
- mMinLogLevel = LOG_NOTICE;
504
- }
505
- else if (iniValue == QLatin1String (" info" ))
506
- {
507
- mMinLogLevel = LOG_INFO;
508
- }
509
- else if (iniValue == QLatin1String (" debug" ))
510
- {
511
- mMinLogLevel = LOG_DEBUG;
512
- }
513
- else
514
- {
515
- minLogLevelSet = false ;
516
- }
458
+ auto lvl = LogTarget::levelFromStr (qPrintable (iniValue));
459
+ minLogLevelSet = strlen (LogTarget::strLevel (lvl)) > 0 ;
517
460
}
518
461
}
519
462
@@ -681,7 +624,7 @@ Core::Core(bool useSyslog, bool minLogLevelSet, int minLogLevel, const QStringLi
681
624
log (LOG_DEBUG, " Config file: %s" , qPrintable (configs[0 ]));
682
625
}
683
626
684
- log (LOG_DEBUG, " MinLogLevel: %s" , strLevel (mMinLogLevel ));
627
+ log (LOG_DEBUG, " MinLogLevel: %s" , LogTarget:: strLevel (mCoreLogger -> mMinLogLevel ));
685
628
switch (mMultipleActionsBehaviour )
686
629
{
687
630
case MULTIPLE_ACTIONS_BEHAVIOUR_FIRST:
@@ -882,28 +825,6 @@ void Core::unixSignalHandler(int signalNumber)
882
825
qApp->quit ();
883
826
}
884
827
885
- void Core::log (int level, const char *format, ...) const
886
- {
887
- if (level > mMinLogLevel )
888
- {
889
- return ;
890
- }
891
-
892
- va_list ap;
893
- va_start (ap, format);
894
- if (mUseSyslog )
895
- {
896
- vsyslog (LOG_MAKEPRI (LOG_USER, level), format, ap);
897
- }
898
- else
899
- {
900
- fprintf (stderr, " [%s] " , strLevel (level));
901
- vfprintf (stderr, format, ap);
902
- fprintf (stderr, " \n " );
903
- }
904
- va_end (ap);
905
- }
906
-
907
828
int Core::x11ErrorHandler (Display */*display*/, XErrorEvent *errorEvent)
908
829
{
909
830
if (error_t error = writeAll (mX11ErrorPipe [STDOUT_FILENO], errorEvent, sizeof (XErrorEvent)))
@@ -2067,7 +1988,7 @@ QPair<QString, qulonglong> Core::addOrRegisterClientAction(const QString &shortc
2067
1988
}
2068
1989
2069
1990
mIdByClientPath [path] = id;
2070
- auto clientAction = sender.isEmpty () ? new ClientAction (this , path, description) : new ClientAction (this , QDBusConnection::sessionBus (), sender, path, description);
1991
+ auto clientAction = sender.isEmpty () ? new ClientAction (mCoreLogger . get () , path, description) : new ClientAction (mCoreLogger . get () , QDBusConnection::sessionBus (), sender, path, description);
2071
1992
mShortcutAndActionById [id] = qMakePair<QString, BaseAction *>(newShortcut, clientAction);
2072
1993
2073
1994
log (LOG_INFO, " addClientAction shortcut:'%s' id:%llu" , qPrintable (newShortcut), id);
@@ -2152,7 +2073,7 @@ void Core::addMethodAction(QPair<QString, qulonglong> &result, const QString &sh
2152
2073
qulonglong id = ++mLastId ;
2153
2074
2154
2075
mIdsByShortcut [newShortcut].insert (id);
2155
- mShortcutAndActionById [id] = qMakePair<QString, BaseAction *>(newShortcut, new MethodAction (this , QDBusConnection::sessionBus (), service, path, interface, method, description));
2076
+ mShortcutAndActionById [id] = qMakePair<QString, BaseAction *>(newShortcut, new MethodAction (mCoreLogger . get () , QDBusConnection::sessionBus (), service, path, interface, method, description));
2156
2077
2157
2078
log (LOG_INFO, " addMethodAction shortcut:'%s' id:%llu" , qPrintable (newShortcut), id);
2158
2079
@@ -2193,7 +2114,7 @@ void Core::addCommandAction(QPair<QString, qulonglong> &result, const QString &s
2193
2114
qulonglong id = ++mLastId ;
2194
2115
2195
2116
mIdsByShortcut [newShortcut].insert (id);
2196
- mShortcutAndActionById [id] = qMakePair<QString, BaseAction *>(newShortcut, new CommandAction (this , command, arguments, description));
2117
+ mShortcutAndActionById [id] = qMakePair<QString, BaseAction *>(newShortcut, new CommandAction (mCoreLogger . get () , command, arguments, description));
2197
2118
2198
2119
log (LOG_INFO, " addCommandAction shortcut:'%s' id:%llu" , qPrintable (newShortcut), id);
2199
2120
@@ -2304,7 +2225,7 @@ void Core::modifyMethodAction(bool &result, const qulonglong &id, const QString
2304
2225
2305
2226
bool isEnabled = action->isEnabled ();
2306
2227
delete action;
2307
- MethodAction * newAction = new MethodAction (this , QDBusConnection::sessionBus (), service, path, interface, method, description);
2228
+ auto newAction = new MethodAction (mCoreLogger . get () , QDBusConnection::sessionBus (), service, path, interface, method, description);
2308
2229
newAction->setEnabled (isEnabled);
2309
2230
shortcutAndActionById.value ().second = newAction;
2310
2231
@@ -2338,7 +2259,7 @@ void Core::modifyCommandAction(bool &result, const qulonglong &id, const QString
2338
2259
2339
2260
bool isEnabled = action->isEnabled ();
2340
2261
delete action;
2341
- CommandAction * newAction = new CommandAction (this , command, arguments, description);
2262
+ auto newAction = new CommandAction (mCoreLogger . get () , command, arguments, description);
2342
2263
newAction->setEnabled (isEnabled);
2343
2264
shortcutAndActionById.value ().second = newAction;
2344
2265
0 commit comments