13 static int log_to_systemlog
;
14 static int log_debug_messages
;
16 static void rpcapd_vlog_stderr(log_priority
,
17 PCAP_FORMAT_STRING(const char *), va_list) PCAP_PRINTFLIKE(2, 0);
19 static void rpcapd_vlog_stderr(log_priority priority
, const char *message
, va_list ap
)
24 * Squelch warnings from compilers that *don't* assume that
25 * priority always has a valid enum value and therefore don't
26 * assume that we'll always go through one of the case arms.
28 * If we have a default case, compilers that *do* assume that
29 * will then complain about the default case code being
32 * Damned if you do, damned if you don't.
55 fprintf(stderr
, "rpcapd: %s", tag
);
56 vfprintf(stderr
, message
, ap
);
60 static void rpcapd_vlog_systemlog(log_priority
,
61 PCAP_FORMAT_STRING(const char *), va_list) PCAP_PRINTFLIKE(2, 0);
64 #define MESSAGE_SUBKEY \
65 "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\rpcapd"
67 static void rpcapd_vlog_systemlog(log_priority priority
, const char *message
,
71 static int initialized
= 0;
73 static HANDLE log_handle
;
81 * Register our message stuff in the Registry.
83 * First, create the registry key for us. If the key
84 * already exists, this succeeds and returns a handle
87 if (RegCreateKey(HKEY_LOCAL_MACHINE
, MESSAGE_SUBKEY
,
88 &key_handle
) != ERROR_SUCCESS
) {
90 * Failed - give up and just log this message,
91 * and all subsequent messages, to the
96 rpcapd_vlog_stderr(priority
, message
, ap
);
99 log_handle
= RegisterEventSource(NULL
, "rpcapd");
107 // XXX - what *should* we do about debug messages?
109 eventlog_type
= EVENTLOG_INFORMATION_TYPE
;
110 event_id
= RPCAPD_INFO_ID
;
114 eventlog_type
= EVENTLOG_INFORMATION_TYPE
;
115 event_id
= RPCAPD_INFO_ID
;
118 case LOGPRIO_WARNING
:
119 eventlog_type
= EVENTLOG_WARNING_TYPE
;
120 event_id
= RPCAPD_WARNING_ID
;
124 eventlog_type
= EVENTLOG_ERROR_TYPE
;
125 event_id
= RPCAPD_ERROR_ID
;
133 vsprintf(msgbuf
, message
, ap
);
137 * If this fails, how are we going to report it?
139 (void) ReportEvent(log_handle
, eventlog_type
, 0, event_id
, NULL
, 1, 0,
142 rpcapd_vlog_stderr(priority
, message
, ap
);
146 static void rpcapd_vlog_systemlog(log_priority priority
, const char *message
,
149 static int initialized
= 0;
156 openlog("rpcapd", LOG_PID
, LOG_DAEMON
);
163 syslog_priority
= LOG_DEBUG
;
167 syslog_priority
= LOG_INFO
;
170 case LOGPRIO_WARNING
:
171 syslog_priority
= LOG_WARNING
;
175 syslog_priority
= LOG_ERR
;
183 vsyslog(syslog_priority
, message
, ap
);
187 void rpcapd_log_set(int log_to_systemlog_arg
, int log_debug_messages_arg
)
189 log_debug_messages
= log_debug_messages_arg
;
190 log_to_systemlog
= log_to_systemlog_arg
;
193 void rpcapd_log(log_priority priority
, const char *message
, ...)
197 if (priority
!= LOGPRIO_DEBUG
|| log_debug_messages
) {
198 va_start(ap
, message
);
199 if (log_to_systemlog
)
201 rpcapd_vlog_systemlog(priority
, message
, ap
);
205 rpcapd_vlog_stderr(priority
, message
, ap
);