| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | #ifndef BASE_CONSOLE_H
|
| | #define BASE_CONSOLE_H
|
| |
|
| |
|
| | #include <array>
|
| | #include <cassert>
|
| | #include <chrono>
|
| | #include <map>
|
| | #include <set>
|
| | #include <string>
|
| | #include <sstream>
|
| | #include <FCGlobal.h>
|
| |
|
| | #include <fmt/printf.h>
|
| |
|
| |
|
| | using PyObject = struct _object;
|
| | using PyMethodDef = struct PyMethodDef;
|
| |
|
| |
|
| | #if defined(__clang__)
|
| | # pragma clang diagnostic push
|
| | # pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
|
| | #endif
|
| |
|
| |
|
| |
|
| |
|
| | #ifdef FC_DEBUG
|
| |
|
| | # undef FC_LOGPYOBJECTS
|
| |
|
| | # define FC_LOGFEATUREUPDATE
|
| |
|
| | # undef FC_LOGUPDATECHAIN
|
| | #endif
|
| |
|
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| |
|
| |
|
| | #define FC_LOGLEVEL_DEFAULT -1
|
| | #define FC_LOGLEVEL_ERR 0
|
| | #define FC_LOGLEVEL_WARN 1
|
| | #define FC_LOGLEVEL_MSG 2
|
| | #define FC_LOGLEVEL_LOG 3
|
| | #define FC_LOGLEVEL_TRACE 4
|
| |
|
| | #define _FC_LOG_LEVEL_INIT(_name, _tag, ...) static Base::LogLevel _name(_tag, ##__VA_ARGS__);
|
| |
|
| | #ifndef FC_LOG_INSTANCE
|
| | #define FC_LOG_INSTANCE _s_fclvl
|
| | #endif
|
| |
|
| | #define FC_LOG_LEVEL_INIT(_tag, ...) _FC_LOG_LEVEL_INIT(FC_LOG_INSTANCE, _tag, ##__VA_ARGS__)
|
| |
|
| | #define __FC_PRINT(_instance, _l, _func, _notifier, _msg, _file, _line) \
|
| | do { \
|
| | if (_instance.isEnabled(_l)) { \
|
| | std::stringstream _str; \
|
| | _instance.prefix(_str, _file, _line) << _msg; \
|
| | if (_instance.add_eol) \
|
| | _str << '\n'; \
|
| | Base::Console()._func(_notifier, _str.str().c_str()); \
|
| | if (_instance.refresh) \
|
| | Base::Console().refresh(); \
|
| | } \
|
| | } while (0)
|
| |
|
| | #define _FC_PRINT(_instance, _l, _func, _msg) \
|
| | __FC_PRINT(_instance, _l, _func, std::string(), _msg, __FILE__, __LINE__)
|
| |
|
| | #define FC_MSG(_msg) _FC_PRINT(FC_LOG_INSTANCE, FC_LOGLEVEL_MSG, message, _msg)
|
| | #define FC_WARN(_msg) _FC_PRINT(FC_LOG_INSTANCE, FC_LOGLEVEL_WARN, developerWarning, _msg)
|
| | #define FC_ERR(_msg) _FC_PRINT(FC_LOG_INSTANCE, FC_LOGLEVEL_ERR, developerError, _msg)
|
| | #define FC_LOG(_msg) _FC_PRINT(FC_LOG_INSTANCE, FC_LOGLEVEL_LOG, log, _msg)
|
| | #define FC_TRACE(_msg) _FC_PRINT(FC_LOG_INSTANCE, FC_LOGLEVEL_TRACE, log, _msg)
|
| |
|
| | #define _FC_MSG(_file, _line, _msg) \
|
| | __FC_PRINT(FC_LOG_INSTANCE, FC_LOGLEVEL_MSG, message, std::string(), _msg, _file, _line)
|
| | #define _FC_WARN(_file, _line, _msg) \
|
| | __FC_PRINT(FC_LOG_INSTANCE, FC_LOGLEVEL_WARN, developerWarning, std::string(), _msg, _file, _line)
|
| | #define _FC_ERR(_file, _line, _msg) \
|
| | __FC_PRINT(FC_LOG_INSTANCE, FC_LOGLEVEL_ERR, developerError, std::string(), _msg, _file, _line)
|
| | #define _FC_LOG(_file, _line, _msg) \
|
| | __FC_PRINT(FC_LOG_INSTANCE, FC_LOGLEVEL_LOG, log, std::string(), _msg, _file, _line)
|
| | #define _FC_TRACE(_file, _line, _msg) \
|
| | __FC_PRINT(FC_LOG_INSTANCE, FC_LOGLEVEL_TRACE, log, std::string(), _msg, _file, _line)
|
| |
|
| | #define FC_XYZ(_pt) '(' << (_pt).X() << ", " << (_pt).Y() << ", " << (_pt).Z() << ')'
|
| | #define FC_xy(_pt) '(' << (_pt).x << ", " << (_pt).y << ')'
|
| | #define FC_xyz(_pt) '(' << (_pt).x << ", " << (_pt).y << ", " << (_pt).z << ')'
|
| |
|
| | #ifndef FC_LOG_NO_TIMING
|
| | #define FC_TIME_CLOCK high_resolution_clock
|
| | #define FC_TIME_POINT std::chrono::FC_TIME_CLOCK::time_point
|
| | #define FC_DURATION std::chrono::duration<double>
|
| |
|
| | #define _FC_TIME_INIT(_t) _t = std::chrono::FC_TIME_CLOCK::now()
|
| | #define FC_TIME_INIT(_t) FC_TIME_POINT _FC_TIME_INIT(_t)
|
| | #define FC_TIME_INIT2(_t1, _t2) FC_TIME_INIT(_t1), _t2 = _t1
|
| | #define FC_TIME_INIT3(_t1, _t2, _t3) FC_TIME_INIT(_t1), _t2 = _t1, _t3 = _t1
|
| |
|
| | #define _FC_DURATION_PRINT(_l, _d, _msg) FC_##_l(_msg << " time: " << _d.count() << 's');
|
| |
|
| | #define FC_DURATION_MSG(_d, _msg) _FC_DURATION_PRINT(MSG, _d, _msg)
|
| | #define FC_DURATION_LOG(_d, _msg) _FC_DURATION_PRINT(LOG, _d, _msg)
|
| | #define FC_DURATION_TRACE(_d, _msg) _FC_DURATION_PRINT(TRACE, _d, _msg)
|
| |
|
| | #define _FC_TIME_PRINT(_l, _t, _msg) _FC_DURATION_PRINT(_l, Base::GetDuration(_t), _msg);
|
| |
|
| | #define FC_TIME_MSG(_t, _msg) _FC_TIME_PRINT(MSG, _t, _msg)
|
| | #define FC_TIME_LOG(_t, _msg) _FC_TIME_PRINT(LOG, _t, _msg)
|
| | #define FC_TIME_TRACE(_t, _msg) _FC_TIME_PRINT(TRACE, _t, _msg)
|
| |
|
| | #define FC_DURATION_DECLARE(_d) FC_DURATION _d
|
| | #define FC_DURATION_DECLARE2(_d, _d1) FC_DURATION_DECLARE(_d), _d1
|
| | #define FC_DURATION_DECLARE3(_d, _d1) FC_DURATION_DECLARE2(_d, _d1), _d2
|
| |
|
| | #define FC_DURATION_INIT(_d) _d = FC_DURATION(0)
|
| | #define FC_DURATION_INIT2(_d, _d1) _d = _d1 = FC_DURATION(0)
|
| | #define FC_DURATION_INIT3(_d, _d1, _d2) _d = _d1 = _d2 = FC_DURATION(0)
|
| |
|
| | #define FC_DURATION_DECL_INIT(_d) FC_DURATION _d(0)
|
| | #define FC_DURATION_DECL_INIT2(_d, _d1) FC_DURATION_DECL_INIT(_d), _d1(0)
|
| | #define FC_DURATION_DECL_INIT3(_d, _d1) FC_DURATION_DECL_INIT2(_d, _d1), _d3(0)
|
| |
|
| | #define FC_DURATION_PLUS(_d, _t) _d += Base::GetDuration(_t)
|
| |
|
| | #else
|
| | #define FC_TIME_POINT
|
| | #define _FC_TIME_INIT(...) \
|
| | do { \
|
| | } while (0)
|
| | #define FC_TIME_INIT(...) \
|
| | do { \
|
| | } while (0)
|
| | #define FC_TIME_INIT2(...) \
|
| | do { \
|
| | } while (0)
|
| | #define FC_TIME_INIT3(...) \
|
| | do { \
|
| | } while (0)
|
| | #define _FC_DURATION_PRINT(...) \
|
| | do { \
|
| | } while (0)
|
| | #define _FC_TIME(_t) \
|
| | do { \
|
| | } while (0)
|
| | #define FC_DURATION_PRINT(...) \
|
| | do { \
|
| | } while (0)
|
| | #define FC_DURATION
|
| | #define FC_DURATION_INIT(...) \
|
| | do { \
|
| | } while (0)
|
| | #define FC_DURATION_INIT1(...) \
|
| | do { \
|
| | } while (0)
|
| | #define FC_DURATION_INIT2(...) \
|
| | do { \
|
| | } while (0)
|
| | #define FC_DURATION_DECLARE(...)
|
| | #define FC_DURATION_DECLARE1(...)
|
| | #define FC_DURATION_DECLARE2(...)
|
| | #define FC_DURATION_DECL_INIT(...) \
|
| | do { \
|
| | } while (0)
|
| | #define FC_DURATION_DECL_INIT2(...) \
|
| | do { \
|
| | } while (0)
|
| | #define FC_DURATION_DECL_INIT3(...) \
|
| | do { \
|
| | } while (0)
|
| | #define FC_DURATION_PLUS(...) \
|
| | do { \
|
| | } while (0)
|
| |
|
| | #endif
|
| |
|
| |
|
| |
|
| | using ConsoleMsgFlags = unsigned int;
|
| |
|
| | namespace Base
|
| | {
|
| |
|
| | #ifndef FC_LOG_NO_TIMING
|
| | inline FC_DURATION GetDuration(FC_TIME_POINT& tp)
|
| | {
|
| | const auto tnow = std::chrono::FC_TIME_CLOCK::now();
|
| | const auto dc = std::chrono::duration_cast<FC_DURATION>(tnow - tp);
|
| | tp = tnow;
|
| | return dc;
|
| | }
|
| | #endif
|
| |
|
| |
|
| | enum class LogStyle
|
| | {
|
| | Warning,
|
| | Message,
|
| | Error,
|
| | Log,
|
| | Critical,
|
| | Notification,
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | enum class IntendedRecipient
|
| | {
|
| | All,
|
| | User,
|
| | Developer,
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | enum class ContentType
|
| | {
|
| | Untranslated,
|
| | Translated,
|
| | Untranslatable,
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | class BaseExport ILogger
|
| | {
|
| | public:
|
| | ILogger() = default;
|
| | ILogger(const ILogger&) = delete;
|
| | ILogger(ILogger&&) = delete;
|
| | ILogger& operator=(const ILogger&) = delete;
|
| | ILogger& operator=(ILogger&&) = delete;
|
| | virtual ~ILogger() = 0;
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | virtual void sendLog(
|
| | const std::string& notifiername,
|
| | const std::string& msg,
|
| | LogStyle level,
|
| | IntendedRecipient recipient,
|
| | ContentType content
|
| | ) = 0;
|
| |
|
| | |
| | |
| |
|
| | bool isActive(const LogStyle category) const
|
| | {
|
| | switch (category) {
|
| | case LogStyle::Log:
|
| | return bLog;
|
| | case LogStyle::Warning:
|
| | return bWrn;
|
| | case LogStyle::Error:
|
| | return bErr;
|
| | case LogStyle::Message:
|
| | return bMsg;
|
| | case LogStyle::Critical:
|
| | return bCritical;
|
| | case LogStyle::Notification:
|
| | return bNotification;
|
| | }
|
| |
|
| | return false;
|
| | }
|
| |
|
| | virtual const char* name()
|
| | {
|
| | return nullptr;
|
| | }
|
| | bool bErr {true};
|
| | bool bMsg {true};
|
| | bool bLog {true};
|
| | bool bWrn {true};
|
| | bool bCritical {true};
|
| | bool bNotification {false};
|
| | };
|
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | class BaseExport ConsoleSingleton
|
| | {
|
| | public:
|
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| |
|
| | template<LogStyle, IntendedRecipient = IntendedRecipient::All, ContentType = ContentType::Untranslated, typename... Args>
|
| | void send(const std::string& notifiername, const char* pMsg, Args&&... args);
|
| |
|
| |
|
| | template<typename... Args>
|
| | void message(const char* pMsg, Args&&... args);
|
| |
|
| | template<typename... Args>
|
| | void warning(const char* pMsg, Args&&... args);
|
| |
|
| | template<typename... Args>
|
| | void error(const char* pMsg, Args&&... args);
|
| |
|
| | template<typename... Args>
|
| | void log(const char* pMsg, Args&&... args);
|
| |
|
| | template<typename... Args>
|
| | void critical(const char* pMsg, Args&&... args);
|
| |
|
| | template<typename... Args>
|
| | void userNotification(const char* pMsg, Args&&... args);
|
| |
|
| | template<typename... Args>
|
| | void userTranslatedNotification(const char* pMsg, Args&&... args);
|
| |
|
| |
|
| |
|
| | template<typename... Args>
|
| | void message(const std::string& notifier, const char* pMsg, Args&&... args);
|
| |
|
| | template<typename... Args>
|
| | void warning(const std::string& notifier, const char* pMsg, Args&&... args);
|
| | template<typename... Args>
|
| | void developerWarning(const std::string& notifier, const char* pMsg, Args&&... args);
|
| | template<typename... Args>
|
| | void userWarning(const std::string& notifier, const char* pMsg, Args&&... args);
|
| | template<typename... Args>
|
| | void translatedUserWarning(const std::string& notifier, const char* pMsg, Args&&... args);
|
| |
|
| | template<typename... Args>
|
| | void error(const std::string& notifier, const char* pMsg, Args&&... args);
|
| | template<typename... Args>
|
| | void developerError(const std::string& notifier, const char* pMsg, Args&&... args);
|
| | template<typename... Args>
|
| |
|
| |
|
| | void destructorError(const std::string& notifier, const char* pMsg, Args&&... args) noexcept;
|
| | template<typename... Args>
|
| | void userError(const std::string& notifier, const char* pMsg, Args&&... args);
|
| | template<typename... Args>
|
| | void translatedUserError(const std::string& notifier, const char* pMsg, Args&&... args);
|
| |
|
| | template<typename... Args>
|
| | void log(const std::string& notifier, const char* pMsg, Args&&... args);
|
| |
|
| | template<typename... Args>
|
| | void critical(const std::string& notifier, const char* pMsg, Args&&... args);
|
| |
|
| | template<typename... Args>
|
| | void userNotification(const std::string& notifier, const char* pMsg, Args&&... args);
|
| |
|
| | template<typename... Args>
|
| | void userTranslatedNotification(const std::string& notifier, const char* pMsg, Args&&... args);
|
| |
|
| |
|
| | template<LogStyle, IntendedRecipient = IntendedRecipient::All, ContentType = ContentType::Untranslated>
|
| | void notify(const std::string& notifiername, const std::string& msg);
|
| |
|
| |
|
| | void attachObserver(ILogger* pcObserver);
|
| |
|
| | void detachObserver(ILogger* pcObserver);
|
| |
|
| |
|
| | enum ConsoleMode
|
| | {
|
| | Verbose = 1,
|
| | };
|
| | enum ConnectionMode
|
| | {
|
| | Direct = 0,
|
| | Queued = 1
|
| | };
|
| |
|
| | enum FreeCAD_ConsoleMsgType
|
| | {
|
| | MsgType_Txt = 1,
|
| | MsgType_Log = 2,
|
| | MsgType_Wrn = 4,
|
| | MsgType_Err = 8,
|
| | MsgType_Critical = 16,
|
| | MsgType_Notification = 32,
|
| | };
|
| |
|
| |
|
| | ConsoleMsgFlags setEnabledMsgType(const char* sObs, ConsoleMsgFlags type, bool on) const;
|
| |
|
| | bool isMsgTypeEnabled(const char* sObs, FreeCAD_ConsoleMsgType type) const;
|
| | void setConnectionMode(ConnectionMode mode);
|
| |
|
| | int* getLogLevel(const char* tag, bool create = true);
|
| |
|
| | void setDefaultLogLevel(const int level)
|
| | {
|
| | _defaultLogLevel = level;
|
| | }
|
| |
|
| | int logLevel(const int level) const
|
| | {
|
| | return level < 0 ? _defaultLogLevel : level;
|
| | }
|
| |
|
| |
|
| | static ConsoleSingleton& instance();
|
| |
|
| |
|
| | ILogger* get(const char* Name) const;
|
| |
|
| | static PyMethodDef Methods[];
|
| |
|
| | void refresh() const;
|
| | void enableRefresh(bool enable);
|
| |
|
| | constexpr FreeCAD_ConsoleMsgType getConsoleMsg(LogStyle style);
|
| |
|
| | private:
|
| |
|
| |
|
| | static PyObject* sPyLog(PyObject* self, PyObject* args);
|
| | static PyObject* sPyMessage(PyObject* self, PyObject* args);
|
| | static PyObject* sPyWarning(PyObject* self, PyObject* args);
|
| | static PyObject* sPyDeveloperWarning(PyObject* self, PyObject* args);
|
| | static PyObject* sPyUserWarning(PyObject* self, PyObject* args);
|
| | static PyObject* sPyTranslatedUserWarning(PyObject* self, PyObject* args);
|
| | static PyObject* sPyError(PyObject* self, PyObject* args);
|
| | static PyObject* sPyDeveloperError(PyObject* self, PyObject* args);
|
| | static PyObject* sPyUserError(PyObject* self, PyObject* args);
|
| | static PyObject* sPyTranslatedUserError(PyObject* self, PyObject* args);
|
| | static PyObject* sPyCritical(PyObject* self, PyObject* args);
|
| | static PyObject* sPyNotification(PyObject* self, PyObject* args);
|
| | static PyObject* sPyTranslatedNotification(PyObject* self, PyObject* args);
|
| | static PyObject* sPySetStatus(PyObject* self, PyObject* args);
|
| | static PyObject* sPyGetStatus(PyObject* self, PyObject* args);
|
| | static PyObject* sPyGetObservers(PyObject* self, PyObject* args);
|
| |
|
| | bool _bCanRefresh {true};
|
| | ConnectionMode connectionMode {Direct};
|
| |
|
| |
|
| | ConsoleSingleton();
|
| | ~ConsoleSingleton();
|
| |
|
| | public:
|
| | ConsoleSingleton(const ConsoleSingleton&) = delete;
|
| | ConsoleSingleton(ConsoleSingleton&&) = delete;
|
| | ConsoleSingleton& operator=(const ConsoleSingleton&) = delete;
|
| | ConsoleSingleton& operator=(ConsoleSingleton&&) = delete;
|
| |
|
| | private:
|
| | void postEvent(
|
| | FreeCAD_ConsoleMsgType type,
|
| | IntendedRecipient recipient,
|
| | ContentType content,
|
| | const std::string& notifiername,
|
| | const std::string& msg
|
| | );
|
| | void notifyPrivate(
|
| | LogStyle category,
|
| | IntendedRecipient recipient,
|
| | ContentType content,
|
| | const std::string& notifiername,
|
| | const std::string& msg
|
| | ) const;
|
| |
|
| |
|
| | static void Destruct();
|
| | static ConsoleSingleton* _pcSingleton;
|
| |
|
| |
|
| | std::set<ILogger*> _aclObservers;
|
| |
|
| | std::map<std::string, int> _logLevels;
|
| | int _defaultLogLevel;
|
| |
|
| | friend class ConsoleOutput;
|
| | };
|
| |
|
| | |
| | |
| | |
| |
|
| | inline ConsoleSingleton& Console()
|
| | {
|
| | return ConsoleSingleton::instance();
|
| | }
|
| |
|
| | constexpr ConsoleSingleton::FreeCAD_ConsoleMsgType ConsoleSingleton::getConsoleMsg(LogStyle style)
|
| | {
|
| | constexpr std::array msgTypes {
|
| |
|
| | MsgType_Wrn,
|
| | MsgType_Txt,
|
| | MsgType_Err,
|
| | MsgType_Log,
|
| | MsgType_Critical,
|
| | MsgType_Notification
|
| | };
|
| |
|
| | return msgTypes.at(static_cast<std::size_t>(style));
|
| | }
|
| |
|
| | class BaseExport ConsoleRefreshDisabler
|
| | {
|
| | public:
|
| | ConsoleRefreshDisabler()
|
| | {
|
| | Console().enableRefresh(false);
|
| | }
|
| |
|
| | ~ConsoleRefreshDisabler()
|
| | {
|
| | Console().enableRefresh(true);
|
| | }
|
| |
|
| | ConsoleRefreshDisabler(const ConsoleRefreshDisabler&) = delete;
|
| | ConsoleRefreshDisabler(ConsoleRefreshDisabler&&) = delete;
|
| | ConsoleRefreshDisabler& operator=(const ConsoleRefreshDisabler&) = delete;
|
| | ConsoleRefreshDisabler& operator=(ConsoleRefreshDisabler&&) = delete;
|
| | };
|
| |
|
| |
|
| |
|
| | class BaseExport LogLevel
|
| | {
|
| | public:
|
| | std::string tag;
|
| | int& lvl;
|
| | bool print_tag;
|
| | int print_src;
|
| | bool print_time;
|
| | bool add_eol;
|
| | bool refresh;
|
| |
|
| | LogLevel(
|
| | const char* tag,
|
| | const bool print_tag = true,
|
| | const int print_src = 0,
|
| | const bool print_time = false,
|
| | const bool add_eol = true,
|
| | const bool refresh = false
|
| | )
|
| | : tag(tag)
|
| | , lvl(*Console().getLogLevel(tag))
|
| | , print_tag(print_tag)
|
| | , print_src(print_src)
|
| | , print_time(print_time)
|
| | , add_eol(add_eol)
|
| | , refresh(refresh)
|
| | {}
|
| |
|
| | bool isEnabled(const int lev) const
|
| | {
|
| | return lev <= level();
|
| | }
|
| |
|
| | int level() const
|
| | {
|
| | return Console().logLevel(lvl);
|
| | }
|
| |
|
| | std::stringstream& prefix(std::stringstream& str, const char* src, int line);
|
| | };
|
| | }
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | template<typename... Args>
|
| | void Base::ConsoleSingleton::message(const char* pMsg, Args&&... args)
|
| | {
|
| | message(std::string(""), pMsg, std::forward<Args>(args)...);
|
| | }
|
| |
|
| | template<typename... Args>
|
| | void Base::ConsoleSingleton::message(const std::string& notifier, const char* pMsg, Args&&... args)
|
| | {
|
| | send<LogStyle::Message>(notifier, pMsg, std::forward<Args>(args)...);
|
| | }
|
| |
|
| | template<typename... Args>
|
| | void Base::ConsoleSingleton::warning(const char* pMsg, Args&&... args)
|
| | {
|
| | warning(std::string(""), pMsg, std::forward<Args>(args)...);
|
| | }
|
| |
|
| | template<typename... Args>
|
| | void Base::ConsoleSingleton::warning(const std::string& notifier, const char* pMsg, Args&&... args)
|
| | {
|
| | send<LogStyle::Warning>(notifier, pMsg, std::forward<Args>(args)...);
|
| | }
|
| |
|
| | template<typename... Args>
|
| | void Base::ConsoleSingleton::developerWarning(const std::string& notifier, const char* pMsg, Args&&... args)
|
| | {
|
| | send<LogStyle::Warning, IntendedRecipient::Developer, ContentType::Untranslatable>(
|
| | notifier,
|
| | pMsg,
|
| | std::forward<Args>(args)...
|
| | );
|
| | }
|
| |
|
| | template<typename... Args>
|
| | void Base::ConsoleSingleton::userWarning(const std::string& notifier, const char* pMsg, Args&&... args)
|
| | {
|
| | send<LogStyle::Warning, IntendedRecipient::User, ContentType::Untranslated>(
|
| | notifier,
|
| | pMsg,
|
| | std::forward<Args>(args)...
|
| | );
|
| | }
|
| |
|
| | template<typename... Args>
|
| | void Base::ConsoleSingleton::translatedUserWarning(
|
| | const std::string& notifier,
|
| | const char* pMsg,
|
| | Args&&... args
|
| | )
|
| | {
|
| | send<LogStyle::Warning, IntendedRecipient::User, ContentType::Translated>(
|
| | notifier,
|
| | pMsg,
|
| | std::forward<Args>(args)...
|
| | );
|
| | }
|
| |
|
| | template<typename... Args>
|
| | void Base::ConsoleSingleton::error(const char* pMsg, Args&&... args)
|
| | {
|
| | error(std::string(""), pMsg, std::forward<Args>(args)...);
|
| | }
|
| |
|
| | template<typename... Args>
|
| | void Base::ConsoleSingleton::error(const std::string& notifier, const char* pMsg, Args&&... args)
|
| | {
|
| | send<LogStyle::Error>(notifier, pMsg, std::forward<Args>(args)...);
|
| | }
|
| |
|
| | template<typename... Args>
|
| | void Base::ConsoleSingleton::developerError(const std::string& notifier, const char* pMsg, Args&&... args)
|
| | {
|
| | send<LogStyle::Error, IntendedRecipient::Developer, ContentType::Untranslatable>(
|
| | notifier,
|
| | pMsg,
|
| | std::forward<Args>(args)...
|
| | );
|
| | }
|
| |
|
| | template<typename... Args>
|
| | void Base::ConsoleSingleton::destructorError(
|
| | const std::string& notifier,
|
| | const char* pMsg,
|
| | Args&&... args
|
| | ) noexcept
|
| | {
|
| | try {
|
| | send<LogStyle::Error, IntendedRecipient::Developer, ContentType::Untranslatable>(
|
| | notifier,
|
| | pMsg,
|
| | std::forward<Args>(args)...
|
| | );
|
| | }
|
| | catch (...) {
|
| | assert("An exception was thrown while attempting console output in a destructor" && false);
|
| | }
|
| | }
|
| |
|
| | template<typename... Args>
|
| | void Base::ConsoleSingleton::userError(const std::string& notifier, const char* pMsg, Args&&... args)
|
| | {
|
| | send<LogStyle::Error, IntendedRecipient::User, ContentType::Untranslated>(
|
| | notifier,
|
| | pMsg,
|
| | std::forward<Args>(args)...
|
| | );
|
| | }
|
| |
|
| | template<typename... Args>
|
| | void Base::ConsoleSingleton::translatedUserError(
|
| | const std::string& notifier,
|
| | const char* pMsg,
|
| | Args&&... args
|
| | )
|
| | {
|
| | send<LogStyle::Error, IntendedRecipient::User, ContentType::Translated>(
|
| | notifier,
|
| | pMsg,
|
| | std::forward<Args>(args)...
|
| | );
|
| | }
|
| |
|
| | template<typename... Args>
|
| | void Base::ConsoleSingleton::critical(const char* pMsg, Args&&... args)
|
| | {
|
| | critical(std::string(""), pMsg, std::forward<Args>(args)...);
|
| | }
|
| |
|
| | template<typename... Args>
|
| | void Base::ConsoleSingleton::critical(const std::string& notifier, const char* pMsg, Args&&... args)
|
| | {
|
| | send<LogStyle::Critical>(notifier, pMsg, std::forward<Args>(args)...);
|
| | }
|
| |
|
| | template<typename... Args>
|
| | void Base::ConsoleSingleton::userNotification(const char* pMsg, Args&&... args)
|
| | {
|
| | userNotification(std::string(""), pMsg, std::forward<Args>(args)...);
|
| | }
|
| |
|
| | template<typename... Args>
|
| | void Base::ConsoleSingleton::userNotification(const std::string& notifier, const char* pMsg, Args&&... args)
|
| | {
|
| | send<LogStyle::Notification, IntendedRecipient::User, ContentType::Untranslated>(
|
| | notifier,
|
| | pMsg,
|
| | std::forward<Args>(args)...
|
| | );
|
| | }
|
| |
|
| | template<typename... Args>
|
| | void Base::ConsoleSingleton::userTranslatedNotification(const char* pMsg, Args&&... args)
|
| | {
|
| | userTranslatedNotification(std::string(""), pMsg, std::forward<Args>(args)...);
|
| | }
|
| |
|
| | template<typename... Args>
|
| | void Base::ConsoleSingleton::userTranslatedNotification(
|
| | const std::string& notifier,
|
| | const char* pMsg,
|
| | Args&&... args
|
| | )
|
| | {
|
| | send<LogStyle::Notification, IntendedRecipient::User, ContentType::Translated>(
|
| | notifier,
|
| | pMsg,
|
| | std::forward<Args>(args)...
|
| | );
|
| | }
|
| |
|
| | template<typename... Args>
|
| | void Base::ConsoleSingleton::log(const char* pMsg, Args&&... args)
|
| | {
|
| | log(std::string(""), pMsg, std::forward<Args>(args)...);
|
| | }
|
| |
|
| | template<typename... Args>
|
| | void Base::ConsoleSingleton::log(const std::string& notifier, const char* pMsg, Args&&... args)
|
| | {
|
| | send<LogStyle::Log>(notifier, pMsg, std::forward<Args>(args)...);
|
| | }
|
| |
|
| | template<
|
| | Base::LogStyle category,
|
| | Base::IntendedRecipient recipient ,
|
| | Base::ContentType contenttype ,
|
| | typename... Args>
|
| | void Base::ConsoleSingleton::send(const std::string& notifiername, const char* pMsg, Args&&... args)
|
| | {
|
| | std::string format;
|
| | try {
|
| | format = fmt::sprintf(pMsg, args...);
|
| | }
|
| | catch (fmt::format_error& e) {
|
| |
|
| |
|
| |
|
| | format = std::string("ERROR: Invalid format string or arguments provided.\n");
|
| | format += e.what();
|
| | }
|
| |
|
| | if (connectionMode == Direct) {
|
| | notify<category, recipient, contenttype>(notifiername, format);
|
| | }
|
| | else {
|
| |
|
| | const auto type = getConsoleMsg(category);
|
| |
|
| | postEvent(type, recipient, contenttype, notifiername, format);
|
| | }
|
| | }
|
| |
|
| | template<
|
| | Base::LogStyle category,
|
| | Base::IntendedRecipient recipient ,
|
| | Base::ContentType contenttype >
|
| | void Base::ConsoleSingleton::notify(const std::string& notifiername, const std::string& msg)
|
| | {
|
| | notifyPrivate(category, recipient, contenttype, notifiername, msg);
|
| | }
|
| |
|
| | #if defined(__clang__)
|
| | # pragma clang diagnostic pop
|
| | #endif
|
| |
|
| | #endif
|
| |
|