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
,
70 static int initialized
= 0;
72 static HANDLE log_handle
;
80 * Register our message stuff in the Registry.
82 * First, create the registry key for us. If the key
83 * already exists, this succeeds and returns a handle
86 if (RegCreateKey(HKEY_LOCAL_MACHINE
, MESSAGE_SUBKEY
,
87 &key_handle
) != ERROR_SUCCESS
) {
89 * Failed - give up and just log this message,
90 * and all subsequent messages, to the
95 rpcapd_vlog_stderr(priority
, message
, ap
);
98 log_handle
= RegisterEventSource(NULL
, "rpcapd");
106 // XXX - what *should* we do about debug messages?
108 eventlog_type
= EVENTLOG_INFORMATION_TYPE
;
109 event_id
= RPCAPD_INFO_ID
;
113 eventlog_type
= EVENTLOG_INFORMATION_TYPE
;
114 event_id
= RPCAPD_INFO_ID
;
117 case LOGPRIO_WARNING
:
118 eventlog_type
= EVENTLOG_WARNING_TYPE
;
119 event_id
= RPCAPD_WARNING_ID
;
123 eventlog_type
= EVENTLOG_ERROR_TYPE
;
124 event_id
= RPCAPD_ERROR_ID
;
132 vsprintf(msgbuf
, message
, ap
);
136 * If this fails, how are we going to report it?
138 (void) ReportEvent(log_handle
, eventlog_type
, 0, event_id
, NULL
, 1, 0,
142 static void rpcapd_vlog_systemlog(log_priority priority
, const char *message
,
145 static int initialized
= 0;
152 openlog("rpcapd", LOG_PID
, LOG_DAEMON
);
159 syslog_priority
= LOG_DEBUG
;
163 syslog_priority
= LOG_INFO
;
166 case LOGPRIO_WARNING
:
167 syslog_priority
= LOG_WARNING
;
171 syslog_priority
= LOG_ERR
;
179 vsyslog(syslog_priority
, message
, ap
);
183 void rpcapd_log_set(int log_to_systemlog_arg
, int log_debug_messages_arg
)
185 log_debug_messages
= log_debug_messages_arg
;
186 log_to_systemlog
= log_to_systemlog_arg
;
189 void rpcapd_log(log_priority priority
, const char *message
, ...)
193 if (priority
!= LOGPRIO_DEBUG
|| log_debug_messages
) {
194 va_start(ap
, message
);
195 if (log_to_systemlog
)
197 rpcapd_vlog_systemlog(priority
, message
, ap
);
201 rpcapd_vlog_stderr(priority
, message
, ap
);