Wireshark 4.5.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
wslog.h
Go to the documentation of this file.
1
12#ifndef __WSLOG_H__
13#define __WSLOG_H__
14
15#include <inttypes.h>
16#include <stdbool.h>
17#include <stdio.h>
18#include <stdarg.h>
19#include <time.h>
20#include <glib.h>
21
22#include <ws_symbol_export.h>
23#include <ws_attributes.h>
24#include <ws_log_defs.h>
25#include <ws_posix_compat.h>
26
27#ifdef WS_LOG_DOMAIN
28#define _LOG_DOMAIN WS_LOG_DOMAIN
29#else
30#define _LOG_DOMAIN ""
31#endif
32
33#ifdef WS_DEBUG
34#define _LOG_DEBUG_ENABLED true
35#else
36#define _LOG_DEBUG_ENABLED false
37#endif
38
39/*
40 * Define the macro WS_LOG_DOMAIN *before* including this header,
41 * for example:
42 * #define WS_LOG_DOMAIN LOG_DOMAIN_MAIN
43 */
44
45#ifdef __cplusplus
46extern "C" {
47#endif /* __cplusplus */
48
49/*
50 * Console open preference is stored in the Windows registry.
51 * HKEY_CURRENT_USER\Software\Wireshark\ConsoleOpen
52 */
53#define LOG_HKCU_CONSOLE_OPEN "ConsoleOpen"
54
55typedef enum {
56 LOG_CONSOLE_OPEN_NEVER,
57 LOG_CONSOLE_OPEN_AUTO, /* On demand. */
58 LOG_CONSOLE_OPEN_ALWAYS, /* Open during startup. */
59} ws_log_console_open_pref;
60
61WSUTIL_EXPORT
62ws_log_console_open_pref ws_log_console_open;
63
64typedef struct {
65 struct tm tstamp_secs;
66 long nanosecs;
67 intmax_t pid;
69
71typedef void (ws_log_writer_cb)(const char *domain, enum ws_log_level level,
72 const char *file, long line, const char *func,
73 const char *fatal_msg, ws_log_manifest_t *mft,
74 const char *user_format, va_list user_ap,
75 void *user_data);
76
77
79typedef void (ws_log_writer_free_data_cb)(void *user_data);
80
81
82WS_DLL_PUBLIC
83void ws_log_file_writer(FILE *fp, const char *domain, enum ws_log_level level,
84 const char *file, long line, const char *func,
86 const char *user_format, va_list user_ap);
87
88
89WS_DLL_PUBLIC
90void ws_log_console_writer(const char *domain, enum ws_log_level level,
91 const char *file, long line, const char *func,
93 const char *user_format, va_list user_ap);
94
95
102WS_DLL_PUBLIC
103void ws_log_console_writer_set_use_stdout(bool use_stdout);
104
105
107WS_DLL_PUBLIC
108WS_RETNONNULL
109const char *ws_log_level_to_string(enum ws_log_level level);
110
111
116WS_DLL_PUBLIC
117bool ws_log_msg_is_active(const char *domain, enum ws_log_level level);
118
119
121WS_DLL_PUBLIC
122enum ws_log_level ws_log_get_level(void);
123
124
127WS_DLL_PUBLIC
128enum ws_log_level ws_log_set_level(enum ws_log_level level);
129
130
138WS_DLL_PUBLIC
139enum ws_log_level ws_log_set_level_str(const char *str_level);
140
141
149WS_DLL_PUBLIC
150void ws_log_set_domain_filter(const char *domain_filter);
151
157WS_DLL_PUBLIC
158void ws_log_set_fatal_domain_filter(const char *domain_filter);
159
160
168WS_DLL_PUBLIC
169void ws_log_set_debug_filter(const char *str_filter);
170
171
176WS_DLL_PUBLIC
177void ws_log_set_noisy_filter(const char *str_filter);
178
179
186WS_DLL_PUBLIC
187enum ws_log_level ws_log_set_fatal_level(enum ws_log_level level);
188
189
195WS_DLL_PUBLIC
196enum ws_log_level ws_log_set_fatal_level_str(const char *str_level);
197
198
203WS_DLL_PUBLIC
205
206
213WS_DLL_PUBLIC
215 void *user_data,
216 ws_log_writer_free_data_cb *free_user_data);
217
218
219#define LOG_ARGS_NOEXIT -1
220
225WS_DLL_PUBLIC
226int ws_log_parse_args(int *argc_ptr, char *argv[],
227 void (*vcmdarg_err)(const char *, va_list ap),
228 int exit_failure);
229
230
237WS_DLL_PUBLIC
238void ws_log_init(void (*vcmdarg_err)(const char *, va_list ap));
239
240
246WS_DLL_PUBLIC
248 void (*vcmdarg_err)(const char *, va_list ap));
249
250
257WS_DLL_PUBLIC
259 void *user_data,
260 ws_log_writer_free_data_cb *free_user_data,
261 void (*vcmdarg_err)(const char *, va_list ap));
262
263
268WS_DLL_PUBLIC
269void ws_log(const char *domain, enum ws_log_level level,
270 const char *format, ...) G_GNUC_PRINTF(3,4);
271
272
277WS_DLL_PUBLIC
278void ws_logv(const char *domain, enum ws_log_level level,
279 const char *format, va_list ap);
280
281
287WS_DLL_PUBLIC
288void ws_log_full(const char *domain, enum ws_log_level level,
289 const char *file, long line, const char *func,
290 const char *format, ...) G_GNUC_PRINTF(6,7);
291
292
298WS_DLL_PUBLIC
299void ws_logv_full(const char *domain, enum ws_log_level level,
300 const char *file, long line, const char *func,
301 const char *format, va_list ap);
302
303
304WS_DLL_PUBLIC
305WS_NORETURN
306void ws_log_fatal_full(const char *domain, enum ws_log_level level,
307 const char *file, long line, const char *func,
308 const char *format, ...) G_GNUC_PRINTF(6,7);
309
310
311/*
312 * The if condition avoids -Wunused warnings for variables used only with
313 * WS_DEBUG, typically inside a ws_debug() call. The compiler will
314 * optimize away the dead execution branch.
315 */
316#define _LOG_IF_ACTIVE(active, level, file, line, func, ...) \
317 do { \
318 if (active) { \
319 ws_log_full(_LOG_DOMAIN, level, \
320 file, line, func, \
321 __VA_ARGS__); \
322 } \
323 } while (0)
324
325#define _LOG_FULL(active, level, ...) \
326 _LOG_IF_ACTIVE(active, level, __FILE__, __LINE__, __func__, __VA_ARGS__)
327
328#define _LOG_SIMPLE(active, level, ...) \
329 _LOG_IF_ACTIVE(active, level, NULL, -1, NULL, __VA_ARGS__)
330
337#define ws_error(...) \
338 ws_log_fatal_full(_LOG_DOMAIN, LOG_LEVEL_ERROR, \
339 __FILE__, __LINE__, __func__, __VA_ARGS__)
340
345#define ws_critical(...) \
346 _LOG_FULL(true, LOG_LEVEL_CRITICAL, __VA_ARGS__)
347
352#define ws_warning(...) \
353 _LOG_FULL(true, LOG_LEVEL_WARNING, __VA_ARGS__)
354
360#define ws_message(...) \
361 _LOG_SIMPLE(true, LOG_LEVEL_MESSAGE, __VA_ARGS__)
362
368#define ws_info(...) \
369 _LOG_SIMPLE(true, LOG_LEVEL_INFO, __VA_ARGS__)
370
375#define ws_debug(...) \
376 _LOG_FULL(_LOG_DEBUG_ENABLED, LOG_LEVEL_DEBUG, __VA_ARGS__)
377
382#define ws_noisy(...) \
383 _LOG_FULL(_LOG_DEBUG_ENABLED, LOG_LEVEL_NOISY, __VA_ARGS__)
384
386#define WS_DEBUG_HERE(...) \
387 _LOG_FULL(true, LOG_LEVEL_ECHO, __VA_ARGS__)
388
389#define WS_NOT_IMPLEMENTED() \
390 ws_error("Not implemented yet")
391
392WS_DLL_PUBLIC
393void ws_log_utf8_full(const char *domain, enum ws_log_level level,
394 const char *file, long line, const char *func,
395 const char *string, ssize_t length, const char *endptr);
396
397
398#define ws_log_utf8(str, len, endptr) \
399 do { \
400 if (_LOG_DEBUG_ENABLED) { \
401 ws_log_utf8_full(LOG_DOMAIN_UTF_8, LOG_LEVEL_DEBUG, \
402 __FILE__, __LINE__, __func__, \
403 str, len, endptr); \
404 } \
405 } while (0)
406
407
412WS_DLL_PUBLIC
413void ws_log_buffer_full(const char *domain, enum ws_log_level level,
414 const char *file, long line, const char *func,
415 const uint8_t *buffer, size_t size,
416 size_t max_bytes_len, const char *msg);
417
418
419#define ws_log_buffer(buf, size, msg) \
420 do { \
421 if (_LOG_DEBUG_ENABLED) { \
422 ws_log_buffer_full(_LOG_DOMAIN, LOG_LEVEL_DEBUG, \
423 __FILE__, __LINE__, __func__, \
424 buf, size, 36, msg ? msg : #buf); \
425 } \
426 } while (0)
427
428
436WS_DLL_PUBLIC
437void ws_log_write_always_full(const char *domain, enum ws_log_level level,
438 const char *file, long line, const char *func,
439 const char *format, ...) G_GNUC_PRINTF(6,7);
440
441
447WS_DLL_PUBLIC
448void ws_log_add_custom_file(FILE *fp);
449
450
451WS_DLL_PUBLIC
452void ws_log_print_usage(FILE *fp);
453
454#ifdef __cplusplus
455}
456#endif /* __cplusplus */
457
458#endif /* __WSLOG_H__ */
Definition mcast_stream.h:30
Definition wslog.h:64
WS_DLL_PUBLIC void ws_log(const char *domain, enum ws_log_level level, const char *format,...) G_GNUC_PRINTF(3
WS_DLL_PUBLIC void ws_log_set_writer_with_data(ws_log_writer_cb *writer, void *user_data, ws_log_writer_free_data_cb *free_user_data)
Definition wslog.c:775
WS_DLL_PUBLIC void ws_log_set_domain_filter(const char *domain_filter)
Definition wslog.c:713
WS_DLL_PUBLIC void ws_log_set_debug_filter(const char *str_filter)
Definition wslog.c:727
void() ws_log_writer_free_data_cb(void *user_data)
Definition wslog.h:79
WS_DLL_PUBLIC void ws_log_set_fatal_domain_filter(const char *domain_filter)
Definition wslog.c:720
WS_DLL_PUBLIC void ws_log_console_writer_set_use_stdout(bool use_stdout)
Definition wslog.c:1367
WS_DLL_PUBLIC enum ws_log_level ws_log_set_level(enum ws_log_level level)
Definition wslog.c:350
WS_DLL_PUBLIC void ws_log_set_noisy_filter(const char *str_filter)
Definition wslog.c:734
WS_DLL_PUBLIC void WS_DLL_PUBLIC void ws_logv_full(const char *domain, enum ws_log_level level, const char *file, long line, const char *func, const char *format, va_list ap)
Definition wslog.c:1148
WS_DLL_PUBLIC int ws_log_parse_args(int *argc_ptr, char *argv[], void(*vcmdarg_err)(const char *, va_list ap), int exit_failure)
Definition wslog.c:502
WS_DLL_PUBLIC void ws_log_write_always_full(const char *domain, enum ws_log_level level, const char *file, long line, const char *func, const char *format,...) G_GNUC_PRINTF(6
void() ws_log_writer_cb(const char *domain, enum ws_log_level level, const char *file, long line, const char *func, const char *fatal_msg, ws_log_manifest_t *mft, const char *user_format, va_list user_ap, void *user_data)
Definition wslog.h:71
WS_DLL_PUBLIC void ws_log_buffer_full(const char *domain, enum ws_log_level level, const char *file, long line, const char *func, const uint8_t *buffer, size_t size, size_t max_bytes_len, const char *msg)
Definition wslog.c:1320
WS_DLL_PUBLIC enum ws_log_level ws_log_set_fatal_level(enum ws_log_level level)
Definition wslog.c:741
WS_DLL_PUBLIC void ws_log_init(void(*vcmdarg_err)(const char *, va_list ap))
Definition wslog.c:847
WS_DLL_PUBLIC void WS_DLL_PUBLIC void ws_log_add_custom_file(FILE *fp)
Definition wslog.c:1390
WS_DLL_PUBLIC WS_RETNONNULL const char * ws_log_level_to_string(enum ws_log_level level)
Definition wslog.c:136
WS_DLL_PUBLIC void ws_log_full(const char *domain, enum ws_log_level level, const char *file, long line, const char *func, const char *format,...) G_GNUC_PRINTF(6
WS_DLL_PUBLIC void ws_log_init_with_writer(ws_log_writer_cb *writer, void(*vcmdarg_err)(const char *, va_list ap))
Definition wslog.c:923
WS_DLL_PUBLIC void WS_DLL_PUBLIC void ws_logv(const char *domain, enum ws_log_level level, const char *format, va_list ap)
Definition wslog.c:1137
WS_DLL_PUBLIC void ws_log_init_with_writer_and_data(ws_log_writer_cb *writer, void *user_data, ws_log_writer_free_data_cb *free_user_data, void(*vcmdarg_err)(const char *, va_list ap))
Definition wslog.c:931
WS_DLL_PUBLIC enum ws_log_level ws_log_get_level(void)
Definition wslog.c:344
WS_DLL_PUBLIC void ws_log_set_writer(ws_log_writer_cb *writer)
Definition wslog.c:764
WS_DLL_PUBLIC bool ws_log_msg_is_active(const char *domain, enum ws_log_level level)
Definition wslog.c:278
WS_DLL_PUBLIC enum ws_log_level ws_log_set_fatal_level_str(const char *str_level)
Definition wslog.c:755
WS_DLL_PUBLIC enum ws_log_level ws_log_set_level_str(const char *str_level)
Definition wslog.c:362