diff options
author | NingSun <ning.sun@intel.com> | 2018-02-08 08:34:03 -0800 |
---|---|---|
committer | NingSun <ning.sun@intel.com> | 2018-02-08 09:14:52 -0800 |
commit | 0c89b3ccba7c9b7332ab67ae1936aff51ca62367 (patch) | |
tree | 70c1b1d160d4c6d0a83395ca9a87c1264d0d3439 /SoftHSMv2/src/lib/win32/syslog.cpp | |
parent | 945613b4db4e07f75d2bc7463db580ddfaa700fd (diff) |
Initial sshsm project structure
Issue-ID: AAF-94
Change-Id: I5e82fff418e7567b161acf9b98013a9b85ffc5b4
Signed-off-by: NingSun <ning.sun@intel.com>
Diffstat (limited to 'SoftHSMv2/src/lib/win32/syslog.cpp')
-rw-r--r-- | SoftHSMv2/src/lib/win32/syslog.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/SoftHSMv2/src/lib/win32/syslog.cpp b/SoftHSMv2/src/lib/win32/syslog.cpp new file mode 100644 index 0000000..927592e --- /dev/null +++ b/SoftHSMv2/src/lib/win32/syslog.cpp @@ -0,0 +1,69 @@ +#include <config.h> + +#include <stdio.h> +#include <stdarg.h> +#include <stdlib.h> +#include <string.h> +#include <syslog.h> + +#ifdef _WIN32 + +static HANDLE hEventLog = NULL; + +/* + * Close the Handle to the application Event Log + */ +void +closelog() { + DeregisterEventSource(hEventLog); +} + +/* + * Initialize event logging + */ +void +openlog(const char *ident, int logopt, int facility) { + /* Get a handle to the Application event log */ + hEventLog = RegisterEventSourceA(NULL, ident); +} + +/* + * Log to the NT Event Log + */ +void +syslog(int priority, const char *message, ...) { + va_list ap; + char buf[1024]; + LPCSTR str[1]; + + str[0] = buf; + + va_start(ap, message); + vsprintf(buf, message, ap); + va_end(ap); + + /* Make sure that the channel is open to write the event */ + if (hEventLog == NULL) { + openlog("SoftHSM", 0, 0); + } + if (hEventLog != NULL) { + switch (priority) { + case LOG_INFO: + case LOG_NOTICE: + case LOG_DEBUG: + ReportEventA(hEventLog, EVENTLOG_INFORMATION_TYPE, 0, + 0x40000003, NULL, 1, 0, str, NULL); + break; + case LOG_WARNING: + ReportEventA(hEventLog, EVENTLOG_WARNING_TYPE, 0, + 0x80000002, NULL, 1, 0, str, NULL); + break; + default: + ReportEventA(hEventLog, EVENTLOG_ERROR_TYPE, 0, + 0xc0000001, NULL, 1, 0, str, NULL); + break; + } + } +} + +#endif |