aboutsummaryrefslogtreecommitdiffstats
path: root/api/logger.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-11-04 12:24:46 +0100
committerSimon Rozman <simon@rozman.si>2020-11-04 13:21:43 +0100
commit9c349273f5d8f4aa836dda86d6e936c6b034928a (patch)
tree5bb5edb4d4ecfbbcf69a787450970aaaad27c846 /api/logger.c
parentapi: include the rundll32 helpers the MSVC-typical way (diff)
downloadwintun-9c349273f5d8f4aa836dda86d6e936c6b034928a.tar.xz
wintun-9c349273f5d8f4aa836dda86d6e936c6b034928a.zip
api: concatenate function name at runtime
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'api/logger.c')
-rw-r--r--api/logger.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/api/logger.c b/api/logger.c
index c954f6c..fc43706 100644
--- a/api/logger.c
+++ b/api/logger.c
@@ -25,7 +25,24 @@ WintunSetLogger(_In_ WINTUN_LOGGER_CALLBACK_FUNC NewLogger)
}
_Post_equals_last_error_ DWORD
-LoggerError(_In_z_ const WCHAR *Prefix, _In_ DWORD Error)
+LoggerLog(_In_ WINTUN_LOGGER_LEVEL Level, _In_z_ const WCHAR *Function, _In_z_ const WCHAR *LogLine)
+{
+ DWORD LastError = GetLastError();
+ if (Function)
+ {
+ WCHAR Combined[0x400];
+ if (_snwprintf_s(Combined, _countof(Combined), _TRUNCATE, L"%s: %s", Function, LogLine) == -1)
+ return LastError;
+ Logger(Level, Combined);
+ }
+ else
+ Logger(Level, LogLine);
+ SetLastError(LastError);
+ return LastError;
+}
+
+_Post_equals_last_error_ DWORD
+LoggerError(_In_z_ const WCHAR *Function, _In_z_ const WCHAR *Prefix, _In_ DWORD Error)
{
WCHAR *SystemMessage = NULL, *FormattedMessage = NULL;
FormatMessageW(
@@ -39,12 +56,12 @@ LoggerError(_In_z_ const WCHAR *Prefix, _In_ DWORD Error)
FormatMessageW(
FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_ARGUMENT_ARRAY |
FORMAT_MESSAGE_MAX_WIDTH_MASK,
- SystemMessage ? L"%1: %3(Code 0x%2!08X!)" : L"%1: Code 0x%2!08X!",
+ SystemMessage ? L"%4: %1: %3(Code 0x%2!08X!)" : L"%1: Code 0x%2!08X!",
0,
0,
(void *)&FormattedMessage,
0,
- (va_list *)(DWORD_PTR[]){ (DWORD_PTR)Prefix, (DWORD_PTR)Error, (DWORD_PTR)SystemMessage });
+ (va_list *)(DWORD_PTR[]){ (DWORD_PTR)Prefix, (DWORD_PTR)Error, (DWORD_PTR)SystemMessage, (DWORD_PTR)Function });
if (FormattedMessage)
Logger(WINTUN_LOG_ERR, FormattedMessage);
LocalFree(FormattedMessage);