comparison common/logging.c @ 620:bc02ee484067

Add dummy logging with ressourced messages. The hack in icon.rc is necessary as with mingw 3.0 there appears to be a problem to include multiple resources after another. The data is included but the sections are not detected correctly in windows. Combining them in a single resource fixes this.
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 19 Jun 2014 17:48:10 +0200
parents 0172740f5c6e
children 5042ace08cba
comparison
equal deleted inserted replaced
619:e780405f8150 620:bc02ee484067
14 14
15 #include <strhelp.h> 15 #include <strhelp.h>
16 16
17 #ifdef WIN32 17 #ifdef WIN32
18 # include <windows.h> 18 # include <windows.h>
19 # include "events.h"
19 #else 20 #else
20 # include <syslog.h> 21 # include <syslog.h>
21 #endif 22 #endif
22 23
23 24
26 win_log(const char *format, va_list ap, bool error) 27 win_log(const char *format, va_list ap, bool error)
27 { 28 {
28 HANDLE log_src = NULL, 29 HANDLE log_src = NULL,
29 process_token = NULL; 30 process_token = NULL;
30 wchar_t *wmsg = NULL; 31 wchar_t *wmsg = NULL;
31 BOOL failure = TRUE; 32 BOOL success = FALSE;
32 WORD type = 0,
33 category = 0;
34 char buffer[MAX_LOG+1]; 33 char buffer[MAX_LOG+1];
35 PTOKEN_USER user_struct = NULL; 34 PTOKEN_USER user_struct = NULL;
36 PSID user_sid = NULL; 35 PSID user_sid = NULL;
37 36
38 vsnprintf (buffer, MAX_LOG, format, ap); 37 vsnprintf (buffer, MAX_LOG, format, ap);
39 buffer[MAX_LOG] = '\0'; 38 buffer[MAX_LOG] = '\0';
40 39
41 log_src = RegisterEventSourceA (NULL, LOG_NAME); 40 log_src = RegisterEventSourceW (NULL, L"" LOG_NAME);
42 41
43 if (log_src == NULL) 42 if (log_src == NULL)
44 { 43 {
45 PRINTLASTERROR ("Failed to open log source."); 44 PRINTLASTERROR ("Failed to open log source.");
46 return; 45 return;
47 }
48
49 if (error)
50 {
51 type = EVENTLOG_ERROR_TYPE;
52 }
53 else
54 {
55 type = EVENTLOG_INFORMATION_TYPE;
56 } 46 }
57 47
58 wmsg = utf8_to_wchar (buffer, strlen(buffer)); 48 wmsg = utf8_to_wchar (buffer, strlen(buffer));
59 if (wmsg == NULL) 49 if (wmsg == NULL)
60 { 50 {
78 user_sid = user_struct->User.Sid; 68 user_sid = user_struct->User.Sid;
79 } 69 }
80 } 70 }
81 71
82 72
83 failure = ReportEventW (log_src, 73 success = ReportEventW (log_src,
84 type, 74 error ? EVENTLOG_ERROR_TYPE : EVENTLOG_INFORMATION_TYPE,
85 category, 75 EVENT_CAT_TB,
86 0, 76 error ? MSG_DEFAULT_ERROR : MSG_DEFAULT_INFO,
87 user_sid, 77 user_sid,
88 1, 78 1,
89 0, 79 0,
90 (const WCHAR **) &wmsg, 80 (const WCHAR **) &wmsg,
91 NULL); 81 NULL);
92 if (failure) 82 if (!success)
93 { 83 {
94 PRINTLASTERROR ("Failed to report event."); 84 PRINTLASTERROR ("Failed to report event.");
95 } 85 }
96 86
97 done: 87 done:

http://wald.intevation.org/projects/trustbridge/