Mercurial > hg > nginx-quic
comparison src/os/win32/ngx_event_log.c @ 2725:d43d73277c5c
Win32 master/workers model
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 20 Apr 2009 06:08:47 +0000 |
parents | |
children | d4a717592877 |
comparison
equal
deleted
inserted
replaced
2724:9fd2f12fee0a | 2725:d43d73277c5c |
---|---|
1 /* | |
2 * Copyright (C) Igor Sysoev | |
3 */ | |
4 | |
5 | |
6 #include <ngx_config.h> | |
7 #include <ngx_core.h> | |
8 | |
9 | |
10 #define NGX_MAX_ERROR_STR 2048 | |
11 | |
12 | |
13 void ngx_cdecl | |
14 ngx_event_log(ngx_err_t err, const char *fmt, ...) | |
15 { | |
16 u_char *p, *last; | |
17 long types; | |
18 HKEY key; | |
19 HANDLE ev; | |
20 va_list args; | |
21 u_char text[NGX_MAX_ERROR_STR]; | |
22 const char *msgarg[9]; | |
23 static u_char netmsg[] = "%SystemRoot%\\System32\\netmsg.dll"; | |
24 | |
25 p = text + GetModuleFileName(NULL, (char *) text, NGX_MAX_ERROR_STR - 50); | |
26 | |
27 *p++ = ':'; | |
28 ngx_linefeed(p); | |
29 | |
30 va_start(args, fmt); | |
31 p = ngx_vsnprintf(p, NGX_MAX_ERROR_STR, fmt, args); | |
32 va_end(args); | |
33 | |
34 last = text + NGX_MAX_ERROR_STR; | |
35 | |
36 if (err) { | |
37 | |
38 if (p > last - 50) { | |
39 | |
40 /* leave a space for an error code */ | |
41 | |
42 p = last - 50; | |
43 *p++ = '.'; | |
44 *p++ = '.'; | |
45 *p++ = '.'; | |
46 } | |
47 | |
48 p = ngx_snprintf(p, last - p, ((unsigned) err < 0x80000000) | |
49 ? " (%d: " : " (%Xd: ", err); | |
50 p = ngx_strerror_r(err, p, last - p); | |
51 | |
52 if (p < last) { | |
53 *p++ = ')'; | |
54 } | |
55 } | |
56 | |
57 if (p > last - NGX_LINEFEED_SIZE - 1) { | |
58 p = last - NGX_LINEFEED_SIZE - 1; | |
59 } | |
60 | |
61 ngx_linefeed(p); | |
62 | |
63 *p = '\0'; | |
64 | |
65 /* | |
66 * we do not log errors here since we use | |
67 * Event Log only to log our own logs open errors | |
68 */ | |
69 | |
70 if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, | |
71 "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\nginx", | |
72 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &key, NULL) | |
73 != 0) | |
74 { | |
75 return; | |
76 } | |
77 | |
78 if (RegSetValueEx(key, "EventMessageFile", 0, REG_EXPAND_SZ, | |
79 netmsg, sizeof(netmsg) - 1) | |
80 != 0) | |
81 { | |
82 return; | |
83 } | |
84 | |
85 types = EVENTLOG_ERROR_TYPE; | |
86 | |
87 if (RegSetValueEx(key, "TypesSupported", 0, REG_DWORD, | |
88 (u_char *) &types, sizeof(long)) | |
89 != 0) | |
90 { | |
91 return; | |
92 } | |
93 | |
94 RegCloseKey(key); | |
95 | |
96 ev = RegisterEventSource(NULL, "nginx"); | |
97 | |
98 msgarg[0] = (char *) text; | |
99 msgarg[1] = NULL; | |
100 msgarg[2] = NULL; | |
101 msgarg[3] = NULL; | |
102 msgarg[4] = NULL; | |
103 msgarg[5] = NULL; | |
104 msgarg[6] = NULL; | |
105 msgarg[7] = NULL; | |
106 msgarg[8] = NULL; | |
107 | |
108 /* | |
109 * the 3299 event id in netmsg.dll has the generic message format: | |
110 * "%1 %2 %3 %4 %5 %6 %7 %8 %9" | |
111 */ | |
112 | |
113 ReportEvent(ev, EVENTLOG_ERROR_TYPE, 0, 3299, NULL, 9, 0, msgarg, NULL); | |
114 | |
115 DeregisterEventSource(ev); | |
116 } |