diff options
| author | Tom Englund <tomenglund26@gmail.com> | 2024-08-15 18:16:18 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-15 17:16:18 +0100 |
| commit | 12d9901472c6f9128fa8b16c25b3a879d1859e60 (patch) | |
| tree | dabd4f190454d95c5a20ad8e9c840d116e790157 /src/protocols/WaylandProtocol.hpp | |
| parent | 15f942000ef53776852d6d9dfd303e691aed73e3 (diff) | |
protocols: refactor protocol logging to a macro (#7324)
this avoids the usage of the unique_ptr PROTO::protocol before it has
been constructed incase one wants to log something inside the
constructor itself, move the logging to macros and print file:linenumber
on ERR,CRIT,WARN and classname on the rest of the levels.
Diffstat (limited to 'src/protocols/WaylandProtocol.hpp')
| -rw-r--r-- | src/protocols/WaylandProtocol.hpp | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/src/protocols/WaylandProtocol.hpp b/src/protocols/WaylandProtocol.hpp index 4d4e7925..0fa8daab 100644 --- a/src/protocols/WaylandProtocol.hpp +++ b/src/protocols/WaylandProtocol.hpp @@ -11,6 +11,35 @@ #define PROTO NProtocols +#define EXTRACT_CLASS_NAME() \ + []() constexpr -> std::string_view { \ + constexpr std::string_view prettyFunction = __PRETTY_FUNCTION__; \ + constexpr size_t colons = prettyFunction.find("::"); \ + if (colons != std::string_view::npos) { \ + constexpr size_t begin = prettyFunction.substr(0, colons).rfind(' ') + 1; \ + constexpr size_t end = colons - begin; \ + return prettyFunction.substr(begin, end); \ + } else { \ + return "Global"; \ + } \ + }() + +#define LOGM(level, ...) \ + do { \ + std::ostringstream oss; \ + if (level == WARN || level == ERR || level == CRIT) { \ + oss << "[" << __FILE__ << ":" << __LINE__ << "] "; \ + } else if (level == LOG || level == INFO || level == TRACE) { \ + oss << "[" << EXTRACT_CLASS_NAME() << "] "; \ + } \ + if constexpr (std::is_same_v<decltype(__VA_ARGS__), std::string>) { \ + oss << __VA_ARGS__; \ + Debug::log(level, oss.str()); \ + } else { \ + Debug::log(level, std::format("{}{}", oss.str(), std::format(__VA_ARGS__))); \ + } \ + } while (0) + class IWaylandProtocol; struct IWaylandProtocolDestroyWrapper { wl_listener listener; @@ -22,15 +51,10 @@ class IWaylandProtocol { IWaylandProtocol(const wl_interface* iface, const int& ver, const std::string& name); virtual ~IWaylandProtocol(); - virtual void onDisplayDestroy(); - virtual void removeGlobal(); - - virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) = 0; + virtual void onDisplayDestroy(); + virtual void removeGlobal(); - template <typename... Args> - void protoLog(LogLevel level, std::format_string<Args...> fmt, Args&&... args) { - Debug::log(level, std::format("[{}] ", m_szName) + std::vformat(fmt.get(), std::make_format_args(args...))); - }; + virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) = 0; IWaylandProtocolDestroyWrapper m_liDisplayDestroy; |
