@@ -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
+ mCoreLogger = std::make_unique<LogTarget>(minLogLevel, useSyslog);
408
374
#endif
409
375
410
376
s_Core = this ;
@@ -487,33 +453,16 @@ Core::Core(bool useSyslog, bool minLogLevelSet, int minLogLevel, const QStringLi
487
453
if (!minLogLevelSet)
488
454
{
489
455
iniValue = settings.value (/* General/ */ QStringLiteral (" LogLevel" )).toString ();
490
- if (!iniValue.isEmpty ())
456
+ auto lvl = LogTarget::levelFromStr (qPrintable (iniValue));
457
+ if (lvl >= 0 )
491
458
{
459
+ mCoreLogger ->mMinLogLevel = lvl;
492
460
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
- }
461
+ }
462
+ else
463
+ {
464
+ auto lvlStr = LogTarget::strLevel (mCoreLogger ->mMinLogLevel );
465
+ qInfo (" no loglevel configured in %s (result = %d); current loglevel: %s" , qUtf8Printable (settings.fileName ()), lvl, lvlStr);
517
466
}
518
467
}
519
468
@@ -681,7 +630,7 @@ Core::Core(bool useSyslog, bool minLogLevelSet, int minLogLevel, const QStringLi
681
630
log (LOG_DEBUG, " Config file: %s" , qPrintable (configs[0 ]));
682
631
}
683
632
684
- log (LOG_DEBUG, " MinLogLevel: %s" , strLevel (mMinLogLevel ));
633
+ log (LOG_DEBUG, " MinLogLevel: %s" , LogTarget:: strLevel (mCoreLogger -> mMinLogLevel ));
685
634
switch (mMultipleActionsBehaviour )
686
635
{
687
636
case MULTIPLE_ACTIONS_BEHAVIOUR_FIRST:
@@ -882,28 +831,6 @@ void Core::unixSignalHandler(int signalNumber)
882
831
qApp->quit ();
883
832
}
884
833
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
834
int Core::x11ErrorHandler (Display */*display*/, XErrorEvent *errorEvent)
908
835
{
909
836
if (error_t error = writeAll (mX11ErrorPipe [STDOUT_FILENO], errorEvent, sizeof (XErrorEvent)))
@@ -2067,7 +1994,7 @@ QPair<QString, qulonglong> Core::addOrRegisterClientAction(const QString &shortc
2067
1994
}
2068
1995
2069
1996
mIdByClientPath [path] = id;
2070
- auto clientAction = sender.isEmpty () ? new ClientAction (this , path, description) : new ClientAction (this , QDBusConnection::sessionBus (), sender, path, description);
1997
+ auto clientAction = sender.isEmpty () ? new ClientAction (mCoreLogger . get () , path, description) : new ClientAction (mCoreLogger . get () , QDBusConnection::sessionBus (), sender, path, description);
2071
1998
mShortcutAndActionById [id] = qMakePair<QString, BaseAction *>(newShortcut, clientAction);
2072
1999
2073
2000
log (LOG_INFO, " addClientAction shortcut:'%s' id:%llu" , qPrintable (newShortcut), id);
@@ -2152,7 +2079,7 @@ void Core::addMethodAction(QPair<QString, qulonglong> &result, const QString &sh
2152
2079
qulonglong id = ++mLastId ;
2153
2080
2154
2081
mIdsByShortcut [newShortcut].insert (id);
2155
- mShortcutAndActionById [id] = qMakePair<QString, BaseAction *>(newShortcut, new MethodAction (this , QDBusConnection::sessionBus (), service, path, interface, method, description));
2082
+ mShortcutAndActionById [id] = qMakePair<QString, BaseAction *>(newShortcut, new MethodAction (mCoreLogger . get () , QDBusConnection::sessionBus (), service, path, interface, method, description));
2156
2083
2157
2084
log (LOG_INFO, " addMethodAction shortcut:'%s' id:%llu" , qPrintable (newShortcut), id);
2158
2085
@@ -2193,7 +2120,7 @@ void Core::addCommandAction(QPair<QString, qulonglong> &result, const QString &s
2193
2120
qulonglong id = ++mLastId ;
2194
2121
2195
2122
mIdsByShortcut [newShortcut].insert (id);
2196
- mShortcutAndActionById [id] = qMakePair<QString, BaseAction *>(newShortcut, new CommandAction (this , command, arguments, description));
2123
+ mShortcutAndActionById [id] = qMakePair<QString, BaseAction *>(newShortcut, new CommandAction (mCoreLogger . get () , command, arguments, description));
2197
2124
2198
2125
log (LOG_INFO, " addCommandAction shortcut:'%s' id:%llu" , qPrintable (newShortcut), id);
2199
2126
@@ -2304,7 +2231,7 @@ void Core::modifyMethodAction(bool &result, const qulonglong &id, const QString
2304
2231
2305
2232
bool isEnabled = action->isEnabled ();
2306
2233
delete action;
2307
- MethodAction * newAction = new MethodAction (this , QDBusConnection::sessionBus (), service, path, interface, method, description);
2234
+ auto newAction = new MethodAction (mCoreLogger . get () , QDBusConnection::sessionBus (), service, path, interface, method, description);
2308
2235
newAction->setEnabled (isEnabled);
2309
2236
shortcutAndActionById.value ().second = newAction;
2310
2237
@@ -2338,7 +2265,7 @@ void Core::modifyCommandAction(bool &result, const qulonglong &id, const QString
2338
2265
2339
2266
bool isEnabled = action->isEnabled ();
2340
2267
delete action;
2341
- CommandAction * newAction = new CommandAction (this , command, arguments, description);
2268
+ auto newAction = new CommandAction (mCoreLogger . get () , command, arguments, description);
2342
2269
newAction->setEnabled (isEnabled);
2343
2270
shortcutAndActionById.value ().second = newAction;
2344
2271
0 commit comments