annotate common/logging.c @ 616:0172740f5c6e

Include user information in windows event log messages
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 19 Jun 2014 12:06:47 +0200
parents 2a4f7364ab81
children bc02ee484067
rev   line source
404
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 252
diff changeset
1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 252
diff changeset
2 * Software engineering by Intevation GmbH
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 252
diff changeset
3 *
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 252
diff changeset
4 * This file is Free Software under the GNU GPL (v>=2)
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 252
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY!
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 252
diff changeset
6 * See LICENSE.txt for details.
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 252
diff changeset
7 */
252
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
8 #include "logging.h"
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
9 #include "strhelp.h"
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
10
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
11 #include <stdio.h>
615
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
12 #include <stdarg.h>
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
13 #include <stdbool.h>
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
14
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
15 #include <strhelp.h>
252
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
16
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
17 #ifdef WIN32
615
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
18 # include <windows.h>
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
19 #else
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
20 # include <syslog.h>
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
21 #endif
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
22
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
23
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
24 #ifdef WIN32
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
25 static void
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
26 win_log(const char *format, va_list ap, bool error)
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
27 {
616
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
28 HANDLE log_src = NULL,
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
29 process_token = NULL;
615
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
30 wchar_t *wmsg = NULL;
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
31 BOOL failure = TRUE;
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
32 WORD type = 0,
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
33 category = 0;
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
34 char buffer[MAX_LOG+1];
616
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
35 PTOKEN_USER user_struct = NULL;
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
36 PSID user_sid = NULL;
615
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
37
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
38 vsnprintf (buffer, MAX_LOG, format, ap);
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
39 buffer[MAX_LOG] = '\0';
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
40
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
41 log_src = RegisterEventSourceA (NULL, LOG_NAME);
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
42
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
43 if (log_src == NULL)
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
44 {
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
45 PRINTLASTERROR ("Failed to open log source.");
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
46 return;
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
47 }
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
48
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
49 if (error)
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
50 {
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
51 type = EVENTLOG_ERROR_TYPE;
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
52 }
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
53 else
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
54 {
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
55 type = EVENTLOG_INFORMATION_TYPE;
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
56 }
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
57
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
58 wmsg = utf8_to_wchar (buffer, strlen(buffer));
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
59 if (wmsg == NULL)
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
60 {
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
61 ERRORPRINTF ("Failed to convert log message to utf-16");
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
62 goto done;
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
63 }
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
64
616
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
65 /* Get the current user sid for logging */
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
66
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
67 OpenProcessToken (GetCurrentProcess(), TOKEN_READ, &process_token);
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
68 if (process_token)
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
69 {
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
70 DWORD size = 0;
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
71
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
72 // check how much space is needed
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
73 GetTokenInformation (process_token, TokenUser, NULL, 0, &size);
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
74 if (ERROR_INSUFFICIENT_BUFFER == GetLastError())
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
75 {
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
76 user_struct = xmalloc (size);
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
77 GetTokenInformation (process_token, TokenUser, user_struct, size, &size);
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
78 user_sid = user_struct->User.Sid;
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
79 }
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
80 }
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
81
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
82
615
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
83 failure = ReportEventW (log_src,
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
84 type,
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
85 category,
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
86 0,
616
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
87 user_sid,
615
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
88 1,
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
89 0,
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
90 (const WCHAR **) &wmsg,
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
91 NULL);
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
92 if (failure)
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
93 {
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
94 PRINTLASTERROR ("Failed to report event.");
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
95 }
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
96
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
97 done:
616
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
98 if (process_token)
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
99 {
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
100 CloseHandle(process_token);
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
101 }
0172740f5c6e Include user information in windows event log messages
Andre Heinecke <andre.heinecke@intevation.de>
parents: 615
diff changeset
102 xfree (user_struct);
615
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
103 xfree (wmsg);
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
104
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
105 if (!DeregisterEventSource (log_src))
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
106 {
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
107 PRINTLASTERROR ("Failed to close log source.");
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
108 }
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
109 return;
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
110 }
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
111
252
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
112 char *
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
113 getLastErrorMsg()
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
114 {
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
115 LPWSTR bufPtr = NULL;
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
116 DWORD err = GetLastError();
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
117 char *retval = NULL;
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
118 FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER |
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
119 FORMAT_MESSAGE_FROM_SYSTEM |
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
120 FORMAT_MESSAGE_IGNORE_INSERTS,
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
121 NULL, err, 0, (LPWSTR) &bufPtr, 0, NULL);
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
122 if (!bufPtr)
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
123 {
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
124 HMODULE hWinhttp = GetModuleHandleW (L"crypt32");
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
125 if (hWinhttp)
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
126 {
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
127 FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER |
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
128 FORMAT_MESSAGE_FROM_HMODULE |
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
129 FORMAT_MESSAGE_IGNORE_INSERTS,
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
130 hWinhttp, HRESULT_CODE (err), 0,
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
131 (LPWSTR) &bufPtr, 0, NULL);
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
132 }
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
133 }
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
134 if (!bufPtr) {
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
135 fprintf (stderr, "Error getting last error for code: %lx \n", err);
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
136 return NULL;
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
137 }
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
138
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
139 retval = wchar_to_utf8(bufPtr, wcslen(bufPtr));
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
140 LocalFree (bufPtr);
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
141
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
142 return retval;
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
143 }
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
144
615
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
145 #else /* WIN32 */
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
146
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
147
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
148 static void
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
149 linux_log (const char *format, va_list ap, bool error)
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
150 {
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
151 openlog (LOG_NAME, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER);
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
152 vsyslog ( error ? LOG_ERR : LOG_INFO, format, ap);
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
153 }
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
154
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
155 #endif /* WIN32 */
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
156
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
157 void
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
158 syslog_info_printf(const char *format, ...)
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
159 {
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
160 va_list args;
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
161 va_start (args, format);
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
162 #ifdef WIN32
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
163 win_log (format, args, false);
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
164 #else
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
165 linux_log (format, args, false);
252
bd7fb50078b4 Add logging.h for some logging / debug functions
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
166 #endif
615
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
167 va_end (args);
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
168 }
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
169
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
170 void
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
171 syslog_error_printf(const char *format, ...)
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
172 {
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
173 va_list args;
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
174 va_start (args, format);
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
175 #ifdef WIN32
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
176 win_log (format, args, true);
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
177 #else
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
178 linux_log (format, args, true);
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
179 #endif
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
180 va_end (args);
2a4f7364ab81 Add first simple event logging functions
Andre Heinecke <andre.heinecke@intevation.de>
parents: 404
diff changeset
181 }

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