Debian Codegraph @

src/Base/Console.cpp

raw
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2
3 /***************************************************************************
4 * Copyright (c) 2002 Jürgen Riegel <[email protected]> *
5 * *
6 * This file is part of the FreeCAD CAx development system. *
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Library General Public License (LGPL) *
10 * as published by the Free Software Foundation; either version 2 of *
11 * the License, or (at your option) any later version. *
12 * for detail see the LICENCE text file. *
13 * *
14 * FreeCAD is distributed in the hope that it will be useful, *
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17 * GNU Library General Public License for more details. *
18 * *
19 * You should have received a copy of the GNU Library General Public *
20 * License along with FreeCAD; if not, write to the Free Software *
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
22 * USA *
23 * *
24 ***************************************************************************/
25
26 #include <FCConfig.h>
27
28 #if defined(FC_OS_WIN32)
29 # include <windows.h>
30 #elif defined(FC_OS_LINUX) || defined(FC_OS_MACOSX)
31 # include <unistd.h>
32 #endif
33 #include <cstring>
34 #include <functional>
35
36 #include "Console.h"
37 #include "PyObjectBase.h"
38 #include <QCoreApplication>
39
40
41 using namespace Base;
42
43
44 //=========================================================================
45
46 namespace Base
47 {
48
49 class ConsoleEvent: public QEvent
50 {
51 public:
52 ConsoleSingleton::FreeCAD_ConsoleMsgType msgtype;
53 IntendedRecipient recipient;
54 ContentType content;
55 std::string notifier;
56 std::string msg;
57
58 ConsoleEvent(
59 const ConsoleSingleton::FreeCAD_ConsoleMsgType type,
60 const IntendedRecipient recipient,
61 const ContentType content,
62 const std::string& notifier,
63 const std::string& msg
64 )
65 : QEvent(QEvent::User) // NOLINT
66 , msgtype(type)
67 , recipient(recipient)
68 , content(content)
69 , notifier(notifier)
70 , msg(msg)
71 {}
72 };
73
74 class ConsoleOutput: public QObject // clazy:exclude=missing-qobject-macro
75 {
76 public:
77 static ConsoleOutput* getInstance()
78 {
79 if (!instance) {
80 instance = new ConsoleOutput;
81 }
82 return instance;
83 }
84 static void destruct()
85 {
86 delete instance;
87 instance = nullptr;
88 }
89
90 void customEvent(QEvent* ev) override
91 {
92 if (ev->type() == QEvent::User) {
93 switch (const auto ce = static_cast<ConsoleEvent*>(ev); ce->msgtype) {
94 case ConsoleSingleton::MsgType_Txt:
95 Console().notifyPrivate(
96 LogStyle::Message,
97 ce->recipient,
98 ce->content,
99 ce->notifier,
100 ce->msg
101 );
102 break;
103 case ConsoleSingleton::MsgType_Log:
104 Console().notifyPrivate(
105 LogStyle::Log,
106 ce->recipient,
107 ce->content,
108 ce->notifier,
109 ce->msg
110 );
111 break;
112 case ConsoleSingleton::MsgType_Wrn:
113 Console().notifyPrivate(
114 LogStyle::Warning,
115 ce->recipient,
116 ce->content,
117 ce->notifier,
118 ce->msg
119 );
120 break;
121 case ConsoleSingleton::MsgType_Err:
122 Console().notifyPrivate(
123 LogStyle::Error,
124 ce->recipient,
125 ce->content,
126 ce->notifier,
127 ce->msg
128 );
129 break;
130 case ConsoleSingleton::MsgType_Critical:
131 Console().notifyPrivate(
132 LogStyle::Critical,
133 ce->recipient,
134 ce->content,
135 ce->notifier,
136 ce->msg
137 );
138 break;
139 case ConsoleSingleton::MsgType_Notification:
140 Console().notifyPrivate(
141 LogStyle::Notification,
142 ce->recipient,
143 ce->content,
144 ce->notifier,
145 ce->msg
146 );
147 break;
148 }
149 }
150 }
151
152 private:
153 static ConsoleOutput* instance; // NOLINT
154 };
155
156 ConsoleOutput* ConsoleOutput::instance = nullptr; // NOLINT
157
158 } // namespace Base
159
160 //**************************************************************************
161 // Construction destruction
162
163
164 ConsoleSingleton::ConsoleSingleton()
165 #ifdef FC_DEBUG
166 : _defaultLogLevel(FC_LOGLEVEL_LOG)
167 #else
168 : _defaultLogLevel(FC_LOGLEVEL_MSG)
169 #endif
170 {}
171
172 ConsoleSingleton::~ConsoleSingleton()
173 {
174 ConsoleOutput::destruct();
175 for (ILogger* Iter : _aclObservers) { // NOLINT
176 delete Iter;
177 }
178 }
179
180
181 //**************************************************************************
182 // methods
183
184 /**
185 * \a type can be OR'ed with any of the FreeCAD_ConsoleMsgType flags to enable -- if \a b is true --
186 * or to disable -- if \a b is false -- a console observer with name \a sObs.
187 * The return value is an OR'ed value of all message types that have changed their state. For
188 * example
189 * @code
190 * // switch off warnings and error messages
191 * ConsoleMsgFlags ret = Base::Console().SetEnabledMsgType("myObs",
192 * Base:ConsoleSingleton::MsgType_Wrn|Base::ConsoleSingleton::MsgType_Err,
193 * false);
194 * // do something without notifying observer myObs
195 * ...
196 * // restore the former configuration again
197 * Base::Console().SetEnabledMsgType("myObs", ret, true);
198 * @endcode
199 * switches off warnings and error messages and restore the state before the modification.
200 * If the observer \a sObs doesn't exist then nothing happens.
201 */
202 ConsoleMsgFlags ConsoleSingleton::setEnabledMsgType(
203 const char* sObs,
204 const ConsoleMsgFlags type,
205 const bool on
206 ) const
207 {
208 if (ILogger* pObs = get(sObs)) {
209 ConsoleMsgFlags flags = 0;
210
211 if (type & MsgType_Err) {
212 if (pObs->bErr != on) {
213 flags |= MsgType_Err;
214 }
215 pObs->bErr = on;
216 }
217 if (type & MsgType_Wrn) {
218 if (pObs->bWrn != on) {
219 flags |= MsgType_Wrn;
220 }
221 pObs->bWrn = on;
222 }
223 if (type & MsgType_Txt) {
224 if (pObs->bMsg != on) {
225 flags |= MsgType_Txt;
226 }
227 pObs->bMsg = on;
228 }
229 if (type & MsgType_Log) {
230 if (pObs->bLog != on) {
231 flags |= MsgType_Log;
232 }
233 pObs->bLog = on;
234 }
235 if (type & MsgType_Critical) {
236 if (pObs->bCritical != on) {
237 flags |= MsgType_Critical;
238 }
239 pObs->bCritical = on;
240 }
241 if (type & MsgType_Notification) {
242 if (pObs->bNotification != on) {
243 flags |= MsgType_Notification;
244 }
245 pObs->bNotification = on;
246 }
247
248 return flags;
249 }
250
251 return 0;
252 }
253
254 bool ConsoleSingleton::isMsgTypeEnabled(const char* sObs, const FreeCAD_ConsoleMsgType type) const
255 {
256 if (const ILogger* pObs = get(sObs)) {
257 switch (type) {
258 case MsgType_Txt:
259 return pObs->bMsg;
260 case MsgType_Log:
261 return pObs->bLog;
262 case MsgType_Wrn:
263 return pObs->bWrn;
264 case MsgType_Err:
265 return pObs->bErr;
266 case MsgType_Critical:
267 return pObs->bCritical;
268 case MsgType_Notification:
269 return pObs->bNotification;
270 default:
271 return false;
272 }
273 }
274
275 return false;
276 }
277
278 void ConsoleSingleton::setConnectionMode(const ConnectionMode mode)
279 {
280 connectionMode = mode;
281
282 // make sure this method gets called from the main thread
283 if (connectionMode == Queued) {
284 ConsoleOutput::getInstance();
285 }
286 }
287
288 //**************************************************************************
289 // Observer stuff
290
291 /** Attaches an Observer to Console
292 * Use this method to attach a ILogger derived class to
293 * the Console. After the observer is attached all messages will also
294 * be forwarded to it.
295 * @see ILogger
296 */
297 void ConsoleSingleton::attachObserver(ILogger* pcObserver)
298 {
299 // double insert !!
300 assert(!_aclObservers.contains(pcObserver));
301
302 _aclObservers.insert(pcObserver);
303 }
304
305 /** Detaches an Observer from Console
306 * Use this method to detach a ILogger derived class.
307 * After detaching you can destruct the Observer or reinsert it later.
308 * @see ILogger
309 */
310 void ConsoleSingleton::detachObserver(ILogger* pcObserver)
311 {
312 _aclObservers.erase(pcObserver);
313 }
314
315 void ConsoleSingleton::notifyPrivate(
316 const LogStyle category,
317 const IntendedRecipient recipient,
318 const ContentType content,
319 const std::string& notifiername,
320 const std::string& msg
321 ) const
322 {
323 for (ILogger* Iter : _aclObservers) {
324 if (Iter->isActive(category)) {
325 Iter->sendLog(
326 notifiername,
327 msg,
328 category,
329 recipient,
330 content
331 ); // send string to the listener
332 }
333 }
334 }
335
336 void ConsoleSingleton::postEvent(
337 const FreeCAD_ConsoleMsgType type,
338 const IntendedRecipient recipient,
339 const ContentType content,
340 const std::string& notifiername,
341 const std::string& msg
342 )
343 {
344 QCoreApplication::postEvent(
345 ConsoleOutput::getInstance(),
346 new ConsoleEvent(type, recipient, content, notifiername, msg)
347 );
348 }
349
350 ILogger* ConsoleSingleton::get(const char* Name) const
351 {
352 const char* OName {};
353 for (ILogger* Iter : _aclObservers) {
354 OName = Iter->name(); // get the name
355 if (OName && strcmp(OName, Name) == 0) {
356 return Iter;
357 }
358 }
359 return nullptr;
360 }
361
362 int* ConsoleSingleton::getLogLevel(const char* tag, const bool create)
363 {
364 if (!tag) {
365 tag = "";
366 }
367 if (_logLevels.contains(tag)) {
368 return &_logLevels[tag];
369 }
370 if (!create) {
371 return nullptr;
372 }
373 int& ret = _logLevels[tag];
374 ret = -1;
375 return &ret;
376 }
377
378 void ConsoleSingleton::refresh() const
379 {
380 if (_bCanRefresh) {
381 qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
382 }
383 }
384
385 void ConsoleSingleton::enableRefresh(const bool enable)
386 {
387 _bCanRefresh = enable;
388 }
389
390 //**************************************************************************
391 // Singleton stuff
392
393 ConsoleSingleton* ConsoleSingleton::_pcSingleton = nullptr;
394
395 void ConsoleSingleton::Destruct()
396 {
397 // not initialized or double destructed!
398 assert(_pcSingleton);
399 delete _pcSingleton;
400 _pcSingleton = nullptr;
401 }
402
403 ConsoleSingleton& ConsoleSingleton::instance()
404 {
405 // not initialized?
406 if (!_pcSingleton) {
407 _pcSingleton = new ConsoleSingleton();
408 }
409 return *_pcSingleton;
410 }
411
412 //**************************************************************************
413 // Python stuff
414
415 // ConsoleSingleton Methods structure
416 PyMethodDef ConsoleSingleton::Methods[] = {
417 {"PrintMessage",
418 sPyMessage,
419 METH_VARARGS,
420 "PrintMessage(obj) -> None\n\n"
421 "Print a message to the output.\n\n"
422 "obj : object\n The string representation is printed."},
423 {"PrintLog",
424 sPyLog,
425 METH_VARARGS,
426 "PrintLog(obj) -> None\n\n"
427 "Print a log message to the output.\n\n"
428 "obj : object\n The string representation is printed."},
429 {"PrintError",
430 sPyError,
431 METH_VARARGS,
432 "PrintError(obj) -> None\n\n"
433 "Print an error message to the output.\n\n"
434 "obj : object\n The string representation is printed."},
435 {"PrintDeveloperError",
436 sPyDeveloperError,
437 METH_VARARGS,
438 "PrintDeveloperError(obj) -> None\n\n"
439 "Print an error message intended only for Developers to the output.\n\n"
440 "obj : object\n The string representation is printed."},
441 {"PrintUserError",
442 sPyUserError,
443 METH_VARARGS,
444 "PrintUserError(obj) -> None\n\n"
445 "Print an error message intended only for the User to the output.\n\n"
446 "obj : object\n The string representation is printed."},
447 {"PrintTranslatedUserError",
448 sPyTranslatedUserError,
449 METH_VARARGS,
450 "PrintTranslatedUserError(obj) -> None\n\n"
451 "Print an already translated error message intended only for the User to the output.\n\n"
452 "obj : object\n The string representation is printed."},
453 {"PrintWarning",
454 sPyWarning,
455 METH_VARARGS,
456 "PrintWarning(obj) -> None\n\n"
457 "Print a warning message to the output.\n\n"
458 "obj : object\n The string representation is printed."},
459 {"PrintDeveloperWarning",
460 sPyDeveloperWarning,
461 METH_VARARGS,
462 "PrintDeveloperWarning(obj) -> None\n\n"
463 "Print an warning message intended only for Developers to the output.\n\n"
464 "obj : object\n The string representation is printed."},
465 {"PrintUserWarning",
466 sPyUserWarning,
467 METH_VARARGS,
468 "PrintUserWarning(obj) -> None\n\n"
469 "Print a warning message intended only for the User to the output.\n\n"
470 "obj : object\n The string representation is printed."},
471 {"PrintTranslatedUserWarning",
472 sPyTranslatedUserWarning,
473 METH_VARARGS,
474 "PrintTranslatedUserWarning(obj) -> None\n\n"
475 "Print an already translated warning message intended only for the User to the output.\n\n"
476 "obj : object\n The string representation is printed."},
477 {"PrintCritical",
478 sPyCritical,
479 METH_VARARGS,
480 "PrintCritical(obj) -> None\n\n"
481 "Print a critical message to the output.\n\n"
482 "obj : object\n The string representation is printed."},
483 {"PrintNotification",
484 sPyNotification,
485 METH_VARARGS,
486 "PrintNotification(obj) -> None\n\n"
487 "Print a user notification to the output.\n\n"
488 "obj : object\n The string representation is printed."},
489 {"PrintTranslatedNotification",
490 sPyTranslatedNotification,
491 METH_VARARGS,
492 "PrintTranslatedNotification(obj) -> None\n\n"
493 "Print an already translated notification to the output.\n\n"
494 "obj : object\n The string representation is printed."},
495 {"SetStatus",
496 sPySetStatus,
497 METH_VARARGS,
498 "SetStatus(observer, type, status) -> None\n\n"
499 "Set the status for either 'Log', 'Msg', 'Wrn' or 'Error' for an observer.\n\n"
500 "observer : str\n Logging interface name.\n"
501 "type : str\n Message type.\n"
502 "status : bool"},
503 {"GetStatus",
504 sPyGetStatus,
505 METH_VARARGS,
506 "GetStatus(observer, type) -> bool or None\n\n"
507 "Get the status for either 'Log', 'Msg', 'Wrn' or 'Error' for an observer.\n"
508 "Returns None if the specified observer doesn't exist.\n\n"
509 "observer : str\n Logging interface name.\n"
510 "type : str\n Message type."},
511 {"GetObservers",
512 sPyGetObservers,
513 METH_VARARGS,
514 "GetObservers() -> list of str\n\n"
515 "Get the names of the current logging interfaces."},
516 {nullptr, nullptr, 0, nullptr} /* Sentinel */
517 };
518
519 namespace
520 {
521 PyObject* FC_PYCONSOLE_MSG(std::function<void(const char*, const char*)> func, PyObject* args)
522 {
523 PyObject* output {};
524 PyObject* notifier {};
525
526 auto notifierStr = "";
527
528 auto retrieveString = [](PyObject* pystr) {
529 PyObject* unicode = nullptr;
530
531 const char* outstr = nullptr;
532
533 if (PyUnicode_Check(pystr)) {
534 outstr = PyUnicode_AsUTF8(pystr);
535 }
536 else {
537 unicode = PyObject_Str(pystr);
538 if (unicode) {
539 outstr = PyUnicode_AsUTF8(unicode);
540 }
541 }
542
543 Py_XDECREF(unicode);
544
545 return outstr;
546 };
547
548
549 if (!PyArg_ParseTuple(args, "OO", &notifier, &output)) {
550 PyErr_Clear();
551 if (!PyArg_ParseTuple(args, "O", &output)) {
552 return nullptr;
553 }
554 }
555 else { // retrieve notifier
556 PY_TRY
557 {
558 notifierStr = retrieveString(notifier);
559 }
560 PY_CATCH
561 }
562
563 PY_TRY
564 {
565
566 if (const char* string = retrieveString(output)) {
567 func(notifierStr, string); /*process message*/
568 }
569 }
570 PY_CATCH
571 Py_Return;
572 }
573 } // namespace
574
575 PyObject* ConsoleSingleton::sPyMessage(PyObject* /*self*/, PyObject* args)
576 {
577 return FC_PYCONSOLE_MSG(
578 [](const std::string& notifier, const char* msg) {
579 instance().send<LogStyle::Message, IntendedRecipient::Developer, ContentType::Untranslatable>(
580 notifier,
581 "%s",
582 msg
583 );
584 },
585 args
586 );
587 }
588
589 PyObject* ConsoleSingleton::sPyWarning(PyObject* /*self*/, PyObject* args)
590 {
591 return FC_PYCONSOLE_MSG(
592 [](const std::string& notifier, const char* msg) { instance().warning(notifier, "%s", msg); },
593 args
594 );
595 }
596
597 PyObject* ConsoleSingleton::sPyDeveloperWarning(PyObject* /*self*/, PyObject* args)
598 {
599 return FC_PYCONSOLE_MSG(
600 [](const std::string& notifier, const char* msg) {
601 instance().send<LogStyle::Warning, IntendedRecipient::Developer, ContentType::Untranslatable>(
602 notifier,
603 "%s",
604 msg
605 );
606 },
607 args
608 );
609 }
610
611 PyObject* ConsoleSingleton::sPyUserWarning(PyObject* /*self*/, PyObject* args)
612 {
613 return FC_PYCONSOLE_MSG(
614 [](const std::string& notifier, const char* msg) {
615 instance().send<LogStyle::Warning, IntendedRecipient::User, ContentType::Untranslated>(
616 notifier,
617 "%s",
618 msg
619 );
620 },
621 args
622 );
623 }
624
625 PyObject* ConsoleSingleton::sPyTranslatedUserWarning(PyObject* /*self*/, PyObject* args)
626 {
627 return FC_PYCONSOLE_MSG(
628 [](const std::string& notifier, const char* msg) {
629 instance().send<LogStyle::Warning, IntendedRecipient::User, ContentType::Translated>(
630 notifier,
631 "%s",
632 msg
633 );
634 },
635 args
636 );
637 }
638
639 PyObject* ConsoleSingleton::sPyError(PyObject* /*self*/, PyObject* args)
640 {
641 return FC_PYCONSOLE_MSG(
642 [](const std::string& notifier, const char* msg) {
643 instance().send<LogStyle::Error, IntendedRecipient::All, ContentType::Untranslated>(
644 notifier,
645 "%s",
646 msg
647 );
648 },
649 args
650 );
651 }
652
653 PyObject* ConsoleSingleton::sPyDeveloperError(PyObject* /*self*/, PyObject* args)
654 {
655 return FC_PYCONSOLE_MSG(
656 [](const std::string& notifier, const char* msg) {
657 instance().send<LogStyle::Error, IntendedRecipient::Developer, ContentType::Untranslatable>(
658 notifier,
659 "%s",
660 msg
661 );
662 },
663 args
664 );
665 }
666
667 PyObject* ConsoleSingleton::sPyUserError(PyObject* /*self*/, PyObject* args)
668 {
669 return FC_PYCONSOLE_MSG(
670 [](const std::string& notifier, const char* msg) {
671 instance().send<LogStyle::Error, IntendedRecipient::User, ContentType::Untranslated>(
672 notifier,
673 "%s",
674 msg
675 );
676 },
677 args
678 );
679 }
680
681 PyObject* ConsoleSingleton::sPyTranslatedUserError(PyObject* /*self*/, PyObject* args)
682 {
683 return FC_PYCONSOLE_MSG(
684 [](const std::string& notifier, const char* msg) {
685 instance().send<LogStyle::Error, IntendedRecipient::User, ContentType::Translated>(
686 notifier,
687 "%s",
688 msg
689 );
690 },
691 args
692 );
693 }
694
695 PyObject* ConsoleSingleton::sPyLog(PyObject* /*self*/, PyObject* args)
696 {
697 return FC_PYCONSOLE_MSG(
698 [](const std::string& notifier, const char* msg) {
699 instance().send<LogStyle::Log, IntendedRecipient::Developer, ContentType::Untranslatable>(
700 notifier,
701 "%s",
702 msg
703 );
704 },
705 args
706 );
707 }
708
709 PyObject* ConsoleSingleton::sPyCritical(PyObject* /*self*/, PyObject* args)
710 {
711 return FC_PYCONSOLE_MSG(
712 [](const std::string& notifier, const char* msg) {
713 instance().send<LogStyle::Critical, IntendedRecipient::All, ContentType::Untranslated>(
714 notifier,
715 "%s",
716 msg
717 );
718 },
719 args
720 );
721 }
722
723 PyObject* ConsoleSingleton::sPyNotification(PyObject* /*self*/, PyObject* args)
724 {
725 return FC_PYCONSOLE_MSG(
726 [](const std::string& notifier, const char* msg) {
727 instance().send<LogStyle::Notification, IntendedRecipient::User, ContentType::Untranslated>(
728 notifier,
729 "%s",
730 msg
731 );
732 },
733 args
734 );
735 }
736
737 PyObject* ConsoleSingleton::sPyTranslatedNotification(PyObject* /*self*/, PyObject* args)
738 {
739 return FC_PYCONSOLE_MSG(
740 [](const std::string& notifier, const char* msg) {
741 instance().send<LogStyle::Notification, IntendedRecipient::User, ContentType::Translated>(
742 notifier,
743 "%s",
744 msg
745 );
746 },
747 args
748 );
749 }
750
751 PyObject* ConsoleSingleton::sPyGetStatus(PyObject* /*self*/, PyObject* args)
752 {
753 char* pstr1 {};
754 char* pstr2 {};
755 if (!PyArg_ParseTuple(args, "ss", &pstr1, &pstr2)) {
756 return nullptr;
757 }
758
759 PY_TRY
760 {
761 bool b = false;
762 const ILogger* pObs = instance().get(pstr1);
763 if (!pObs) {
764 Py_Return;
765 }
766
767 if (strcmp(pstr2, "Log") == 0) {
768 b = pObs->bLog;
769 }
770 else if (strcmp(pstr2, "Wrn") == 0) {
771 b = pObs->bWrn;
772 }
773 else if (strcmp(pstr2, "Msg") == 0) {
774 b = pObs->bMsg;
775 }
776 else if (strcmp(pstr2, "Err") == 0) {
777 b = pObs->bErr;
778 }
779 else if (strcmp(pstr2, "Critical") == 0) {
780 b = pObs->bCritical;
781 }
782 else if (strcmp(pstr2, "Notification") == 0) {
783 b = pObs->bNotification;
784 }
785 else {
786 Py_Error(
787 Base::PyExc_FC_GeneralError,
788 "Unknown message type (use 'Log', 'Err', 'Wrn', 'Msg', 'Critical' or "
789 "'Notification')"
790 );
791 }
792
793 return PyBool_FromLong(b ? 1 : 0);
794 }
795 PY_CATCH;
796 }
797
798 PyObject* ConsoleSingleton::sPySetStatus(PyObject* /*self*/, PyObject* args)
799 {
800 char* pstr1 {};
801 char* pstr2 {};
802 PyObject* pyStatus {};
803 if (!PyArg_ParseTuple(args, "ssO!", &pstr1, &pstr2, &PyBool_Type, &pyStatus)) {
804 return nullptr;
805 }
806
807 PY_TRY
808 {
809 const bool status = asBoolean(pyStatus);
810 if (ILogger* pObs = instance().get(pstr1)) {
811 if (strcmp(pstr2, "Log") == 0) {
812 pObs->bLog = status;
813 }
814 else if (strcmp(pstr2, "Wrn") == 0) {
815 pObs->bWrn = status;
816 }
817 else if (strcmp(pstr2, "Msg") == 0) {
818 pObs->bMsg = status;
819 }
820 else if (strcmp(pstr2, "Err") == 0) {
821 pObs->bErr = status;
822 }
823 else if (strcmp(pstr2, "Critical") == 0) {
824 pObs->bCritical = status;
825 }
826 else if (strcmp(pstr2, "Notification") == 0) {
827 pObs->bNotification = status;
828 }
829 else {
830 Py_Error(
831 Base::PyExc_FC_GeneralError,
832 "Unknown message type (use 'Log', 'Err', 'Wrn', 'Msg', 'Critical' or "
833 "'Notification')"
834 );
835 }
836
837 Py_Return;
838 }
839
840 Py_Error(Base::PyExc_FC_GeneralError, "Unknown logger type");
841 }
842 PY_CATCH;
843 }
844
845 PyObject* ConsoleSingleton::sPyGetObservers(PyObject* /*self*/, PyObject* args)
846 {
847 if (!PyArg_ParseTuple(args, "")) {
848 return nullptr;
849 }
850
851 PY_TRY
852 {
853 Py::List list;
854 for (const auto i : instance()._aclObservers) {
855 list.append(Py::String(i->name() ? i->name() : ""));
856 }
857
858 return new_reference_to(list);
859 }
860 PY_CATCH
861 }
862
863 ILogger::~ILogger() = default;