aboutsummaryrefslogtreecommitdiff
path: root/src/internal/noscrypt_logger.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/internal/noscrypt_logger.hpp')
-rw-r--r--src/internal/noscrypt_logger.hpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/internal/noscrypt_logger.hpp b/src/internal/noscrypt_logger.hpp
new file mode 100644
index 0000000..b767b81
--- /dev/null
+++ b/src/internal/noscrypt_logger.hpp
@@ -0,0 +1,43 @@
+#pragma once
+
+#include <plog/Log.h>
+#include <noscrypt.h>
+
+/*
+* @brief Logs an error message with the function name and line number where the
+* error occurred. This is useful for debugging and logging errors in the Noscrypt
+* library.
+*/
+#define NC_LOG_ERROR(result) _printNoscryptError(result, __func__, __LINE__)
+
+static inline void _printNoscryptError(NCResult result, const std::string funcName, int lineNum)
+{
+ uint8_t argPosition;
+
+ switch (NCParseErrorCode(result, &argPosition))
+ {
+ case E_NULL_PTR:
+ PLOG_ERROR << "noscrypt - error: A null pointer was passed in " << funcName << "(" << argPosition << ") at line " << lineNum;
+ break;
+
+ case E_INVALID_ARG:
+ PLOG_ERROR << "noscrypt - error: An invalid argument was passed in " << funcName << "(" << argPosition << ") at line " << lineNum;
+ break;
+
+ case E_INVALID_CONTEXT:
+ PLOG_ERROR << "noscrypt - error: An invalid context was passed in " << funcName << "(" << argPosition << ") on line " << lineNum;
+ break;
+
+ case E_ARGUMENT_OUT_OF_RANGE:
+ PLOG_ERROR << "noscrypt - error: An argument was out of range in " << funcName << "(" << argPosition << ") at line " << lineNum;
+ break;
+
+ case E_OPERATION_FAILED:
+ PLOG_ERROR << "noscrypt - error: An operation failed in " << funcName << "(" << argPosition << ") at line " << lineNum;
+ break;
+
+ default:
+ PLOG_ERROR << "noscrypt - error: An unknown error " << result << " occurred in " << funcName << "(" << argPosition << ") at line " << lineNum;
+ break;
+ }
+}