summaryrefslogtreecommitdiff
path: root/src/helpers/MiscFunctions.hpp
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2023-09-06 12:51:36 +0200
committerGitHub <noreply@github.com>2023-09-06 12:51:36 +0200
commit61a71c65ace5124cb26a074715280537e6e34d00 (patch)
treeb54cf4d7a0f8477b2958619384982d31663f128f /src/helpers/MiscFunctions.hpp
parentc3a83daa1e61285a418c39a1d9f29427c2c9a2c3 (diff)
internal: Formatter rework (#3186)
Diffstat (limited to 'src/helpers/MiscFunctions.hpp')
-rw-r--r--src/helpers/MiscFunctions.hpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/helpers/MiscFunctions.hpp b/src/helpers/MiscFunctions.hpp
index 88598390..592964c9 100644
--- a/src/helpers/MiscFunctions.hpp
+++ b/src/helpers/MiscFunctions.hpp
@@ -5,6 +5,7 @@
#include <wlr/util/box.h>
#include "Vector2D.hpp"
#include <vector>
+#include <format>
struct SCallstackFrameInfo {
void* adr = nullptr;
@@ -13,7 +14,6 @@ struct SCallstackFrameInfo {
std::string absolutePath(const std::string&, const std::string&);
void addWLSignal(wl_signal*, wl_listener*, void* pOwner, const std::string& ownerString);
-std::string getFormat(const char* fmt, ...); // Basically Debug::log to a string
std::string escapeJSONStrings(const std::string& str);
void scaleBox(wlr_box*, float);
std::string removeBeginEndSpacesTabs(std::string);
@@ -30,4 +30,28 @@ void matrixProjection(float mat[9], int w, int h, wl
double normalizeAngleRad(double ang);
std::string replaceInString(std::string subject, const std::string& search, const std::string& replace);
std::vector<SCallstackFrameInfo> getBacktrace();
-void throwError(const std::string& err); \ No newline at end of file
+void throwError(const std::string& err);
+
+// why, C++.
+std::string sendToLog(uint8_t, const std::string&);
+template <typename... Args>
+std::string getFormat(const std::string& fmt, Args&&... args) {
+ std::string fmtdMsg;
+
+ try {
+ fmtdMsg += std::vformat(fmt, std::make_format_args(args...));
+ } catch (std::exception& e) {
+ std::string exceptionMsg = e.what();
+ sendToLog(2, std::format("caught exception in getFormat: {}", exceptionMsg));
+
+ const auto CALLSTACK = getBacktrace();
+
+ sendToLog(0, "stacktrace:");
+
+ for (size_t i = 0; i < CALLSTACK.size(); ++i) {
+ sendToLog(1, std::format("\t #{} | {}", i, CALLSTACK[i].desc));
+ }
+ }
+
+ return fmtdMsg;
+} \ No newline at end of file