1 /*
2 * Copyright (C) 2006 Adam Kropelin
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 2 of the GNU General
6 * Public License as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the Free
15 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16 * MA 02110-1335, USA.
17 */
18
19 #include <syslog.h>
20 #include <stdio.h>
21 #include "winapi.h"
22
23 /* Implement syslog() using Win32 Event Service */
openlog(const char * app,int,int)24 void openlog(const char *app, int, int) {}
closelog(void)25 void closelog(void) {}
syslog(int type,const char * fmt,...)26 void syslog(int type, const char *fmt, ...)
27 {
28 va_list arg_ptr;
29 char message[1024];
30 HANDLE heventsrc;
31 char* strings[32];
32 WORD wtype;
33
34 va_start(arg_ptr, fmt);
35 message[0] = '\n';
36 message[1] = '\n';
37 vsnprintf(message+2, sizeof(message)-2, fmt, arg_ptr);
38 va_end(arg_ptr);
39
40 strings[0] = message;
41
42 // Convert syslog type to Win32 type. This mapping is somewhat arbitrary
43 // since there are many more LOG_* types than EVENTLOG_* types.
44 switch (type) {
45 case LOG_ERR:
46 wtype = EVENTLOG_ERROR_TYPE;
47 break;
48 case LOG_CRIT:
49 case LOG_ALERT:
50 case LOG_WARNING:
51 wtype = EVENTLOG_WARNING_TYPE;
52 break;
53 default:
54 wtype = EVENTLOG_INFORMATION_TYPE;
55 break;
56 }
57
58 // Use event logging to log the error
59 heventsrc = RegisterEventSource(NULL, "apcctrl");
60
61 if (heventsrc != NULL) {
62 ReportEvent(
63 heventsrc, // handle of event source
64 wtype, // event type
65 0, // event category
66 0, // event ID
67 NULL, // current user's SID
68 1, // strings in 'strings'
69 0, // no bytes of raw data
70 (const char **)strings, // array of error strings
71 NULL); // no raw data
72
73 DeregisterEventSource(heventsrc);
74 }
75 }
76