summary refs log tree commit diff
path: root/src/Logger.h
diff options
context:
space:
mode:
authorWlodekM <[email protected]>2024-06-16 10:35:45 +0300
committerWlodekM <[email protected]>2024-06-16 10:35:45 +0300
commitabef6da56913f1c55528103e60a50451a39628b1 (patch)
treeb3c8092471ecbb73e568cd0d336efa0e7871ee8d /src/Logger.h
initial commit
Diffstat (limited to 'src/Logger.h')
-rw-r--r--src/Logger.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/Logger.h b/src/Logger.h
new file mode 100644
index 0000000..cea1b84
--- /dev/null
+++ b/src/Logger.h
@@ -0,0 +1,58 @@
+#ifndef CC_LOGGER_H
+#define CC_LOGGER_H
+#include "Core.h"
+/* 
+Logs warnings/errors and also abstracts platform specific logging for fatal errors
+Copyright 2014-2023 ClassiCube | Licensed under BSD-3
+*/
+
+typedef cc_bool (*Logger_DescribeError)(cc_result res, cc_string* dst);
+typedef void (*Logger_DoWarn)(const cc_string* msg);
+/* Informs the user about a non-fatal error. */
+/*  By default this shows a message box, but changes to in-game chat when game is running. */
+extern Logger_DoWarn Logger_WarnFunc;
+/* The title shown for warning dialogs. */
+extern const char* Logger_DialogTitle;
+/* Shows a warning message box with the given message. */
+void Logger_DialogWarn(const cc_string* msg);
+
+/* Format: "Error [result] when [action]  \n  Error meaning: [desc]" */
+/* If describeErr returns false, then 'Error meaning' line is omitted. */
+void Logger_FormatWarn(cc_string* msg, cc_result res, const char* action, Logger_DescribeError describeErr);
+/* Format: "Error [result] when [action] '[path]'  \n  Error meaning: [desc]" */
+/* If describeErr returns false, then 'Error meaning' line is omitted. */
+void Logger_FormatWarn2(cc_string* msg, cc_result res, const char* action, const cc_string* path, Logger_DescribeError describeErr);
+/* Informs the user about a non-fatal error, with an optional meaning message. */
+void Logger_Warn(cc_result res, const char* action, Logger_DescribeError describeErr);
+/* Informs the user about a non-fatal error, with an optional meaning message. */
+void Logger_Warn2(cc_result res, const char* action, const cc_string* path, Logger_DescribeError describeErr);
+
+/* Shortcut for Logger_Warn with no error describer function */
+void Logger_SimpleWarn(cc_result res, const char* action);
+/* Shorthand for Logger_Warn2 with no error describer function */
+void Logger_SimpleWarn2(cc_result res, const char* action, const cc_string* path);
+/* Shows a warning for a failed DynamicLib_Load2/Get2 call. */
+/* Format: "Error [action] '[path]'  \n  Error meaning: [desc]" */
+void Logger_DynamicLibWarn(const char* action, const cc_string* path);
+/* Shortcut for Logger_Warn with Platform_DescribeError */
+void Logger_SysWarn(cc_result res, const char* action);
+/* Shortcut for Logger_Warn2 with Platform_DescribeError */
+void Logger_SysWarn2(cc_result res, const char* action, const cc_string* path);
+
+/* Hooks the operating system's unhandled error callback/signal. */
+/* This is used to attempt to log some information about a crash due to invalid memory read, etc. */
+void Logger_Hook(void);
+/* Generates a backtrace based on the platform-specific CPU context. */
+/* NOTE: The provided CPU context may be modified (e.g on Windows) */
+void Logger_Backtrace(cc_string* trace, void* ctx);
+/* Logs a message to client.log on disc. */
+/* NOTE: The message is written raw, it is NOT converted to unicode (unlike Stream_WriteLine) */
+void Logger_Log(const cc_string* msg);
+/* Displays a message box with raw_msg body, logs state to disc, then immediately terminates/quits. */
+/* Typically used to abort due to an unrecoverable error. (e.g. out of memory) */
+void Logger_Abort(const char* raw_msg);
+/* Displays a message box with raw_msg body, logs state to disc, then immediately terminates/quits. */
+/* Typically used to abort due to an unrecoverable error. (e.g. out of memory) */
+CC_NOINLINE void Logger_Abort2(cc_result result, const char* raw_msg);
+void Logger_FailToStart(const char* raw_msg);
+#endif