2 * Copyright (C) Igor Sysoev
3 * Copyright (C) Nginx, Inc.
7 #include <ngx_config.h>
11 #define NGX_MAX_ERROR_STR 2048
15 ngx_event_log(ngx_err_t err, const char *fmt, ...)
22 u_char text[NGX_MAX_ERROR_STR];
23 const char *msgarg[9];
24 static u_char netmsg[] = "%SystemRoot%\\System32\\netmsg.dll";
26 last = text + NGX_MAX_ERROR_STR;
27 p = text + GetModuleFileName(NULL, (char *) text, NGX_MAX_ERROR_STR - 50);
33 p = ngx_vslprintf(p, last, fmt, args);
37 p = ngx_log_errno(p, last, err);
40 if (p > last - NGX_LINEFEED_SIZE - 1) {
41 p = last - NGX_LINEFEED_SIZE - 1;
49 * we do not log errors here since we use
50 * Event Log only to log our own logs open errors
53 if (RegCreateKeyEx(HKEY_LOCAL_MACHINE,
54 "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\nginx",
55 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &key, NULL)
61 if (RegSetValueEx(key, "EventMessageFile", 0, REG_EXPAND_SZ,
62 netmsg, sizeof(netmsg) - 1)
68 types = EVENTLOG_ERROR_TYPE;
70 if (RegSetValueEx(key, "TypesSupported", 0, REG_DWORD,
71 (u_char *) &types, sizeof(long))
79 ev = RegisterEventSource(NULL, "nginx");
81 msgarg[0] = (char *) text;
92 * the 3299 event id in netmsg.dll has the generic message format:
93 * "%1 %2 %3 %4 %5 %6 %7 %8 %9"
96 ReportEvent(ev, EVENTLOG_ERROR_TYPE, 0, 3299, NULL, 9, 0, msgarg, NULL);
98 DeregisterEventSource(ev);