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(const char *progname,
239 void (*vcmdarg_err)(const char *, va_list ap));
240
241
247WS_DLL_PUBLIC
248void ws_log_init_with_writer(const char *progname,
249 ws_log_writer_cb *writer,
250 void (*vcmdarg_err)(const char *, va_list ap));
251
252
259WS_DLL_PUBLIC
260void ws_log_init_with_writer_and_data(const char *progname,
261 ws_log_writer_cb *writer,
262 void *user_data,
263 ws_log_writer_free_data_cb *free_user_data,
264 void (*vcmdarg_err)(const char *, va_list ap));
265
266
271WS_DLL_PUBLIC
272void ws_log(const char *domain, enum ws_log_level level,
273 const char *format, ...) G_GNUC_PRINTF(3,4);
274
275
280WS_DLL_PUBLIC
281void ws_logv(const char *domain, enum ws_log_level level,
282 const char *format, va_list ap);
283
284
290WS_DLL_PUBLIC
291void ws_log_full(const char *domain, enum ws_log_level level,
292 const char *file, long line, const char *func,
293 const char *format, ...) G_GNUC_PRINTF(6,7);
294
295
301WS_DLL_PUBLIC
302void ws_logv_full(const char *domain, enum ws_log_level level,
303 const char *file, long line, const char *func,
304 const char *format, va_list ap);
305
306
307WS_DLL_PUBLIC
308WS_NORETURN
309void ws_log_fatal_full(const char *domain, enum ws_log_level level,
310 const char *file, long line, const char *func,
311 const char *format, ...) G_GNUC_PRINTF(6,7);
312
313
314/*
315 * The if condition avoids -Wunused warnings for variables used only with
316 * WS_DEBUG, typically inside a ws_debug() call. The compiler will
317 * optimize away the dead execution branch.
318 */
319#define _LOG_IF_ACTIVE(active, level, file, line, func, ...) \
320 do { \
321 if (active) { \
322 ws_log_full(_LOG_DOMAIN, level, \
323 file, line, func, \
324 __VA_ARGS__); \
325 } \
326 } while (0)
327
328#define _LOG_FULL(active, level, ...) \
329 _LOG_IF_ACTIVE(active, level, __FILE__, __LINE__, __func__, __VA_ARGS__)
330
331#define _LOG_SIMPLE(active, level, ...) \
332 _LOG_IF_ACTIVE(active, level, NULL, -1, NULL, __VA_ARGS__)
333
340#define ws_error(...) \
341 ws_log_fatal_full(_LOG_DOMAIN, LOG_LEVEL_ERROR, \
342 __FILE__, __LINE__, __func__, __VA_ARGS__)
343
348#define ws_critical(...) \
349 _LOG_FULL(true, LOG_LEVEL_CRITICAL, __VA_ARGS__)
350
355#define ws_warning(...) \
356 _LOG_FULL(true, LOG_LEVEL_WARNING, __VA_ARGS__)
357
363#define ws_message(...) \
364 _LOG_SIMPLE(true, LOG_LEVEL_MESSAGE, __VA_ARGS__)
365
371#define ws_info(...) \
372 _LOG_SIMPLE(true, LOG_LEVEL_INFO, __VA_ARGS__)
373
378#define ws_debug(...) \
379 _LOG_FULL(_LOG_DEBUG_ENABLED, LOG_LEVEL_DEBUG, __VA_ARGS__)
380
385#define ws_noisy(...) \
386 _LOG_FULL(_LOG_DEBUG_ENABLED, LOG_LEVEL_NOISY, __VA_ARGS__)
387
389#define WS_DEBUG_HERE(...) \
390 _LOG_FULL(true, LOG_LEVEL_ECHO, __VA_ARGS__)
391
392#define WS_NOT_IMPLEMENTED() \
393 ws_error("Not implemented yet")
394
395WS_DLL_PUBLIC
396void ws_log_utf8_full(const char *domain, enum ws_log_level level,
397 const char *file, long line, const char *func,
398 const char *string, ssize_t length, const char *endptr);
399
400
401#define ws_log_utf8(str, len, endptr) \
402 do { \
403 if (_LOG_DEBUG_ENABLED) { \
404 ws_log_utf8_full(LOG_DOMAIN_UTF_8, LOG_LEVEL_DEBUG, \
405 __FILE__, __LINE__, __func__, \
406 str, len, endptr); \
407 } \
408 } while (0)
409
410
415WS_DLL_PUBLIC
416void ws_log_buffer_full(const char *domain, enum ws_log_level level,
417 const char *file, long line, const char *func,
418 const uint8_t *buffer, size_t size,
419 size_t max_bytes_len, const char *msg);
420
421
422#define ws_log_buffer(buf, size) \
423 do { \
424 if (_LOG_DEBUG_ENABLED) { \
425 ws_log_buffer_full(_LOG_DOMAIN, LOG_LEVEL_DEBUG, \
426 __FILE__, __LINE__, __func__, \
427 buf, size, 36, #buf); \
428 } \
429 } while (0)
430
431
439WS_DLL_PUBLIC
440void ws_log_write_always_full(const char *domain, enum ws_log_level level,
441 const char *file, long line, const char *func,
442 const char *format, ...) G_GNUC_PRINTF(6,7);
443
444
450WS_DLL_PUBLIC
451void ws_log_add_custom_file(FILE *fp);
452
453
454WS_DLL_PUBLIC
455void ws_log_print_usage(FILE *fp);
456
457#ifdef __cplusplus
458}
459#endif /* __cplusplus */
460
461#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_init_with_writer_and_data(const char *progname, 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:936
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:1373
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:1154
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:1326
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_DLL_PUBLIC void ws_log_add_custom_file(FILE *fp)
Definition wslog.c:1396
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_init(const char *progname, void(*vcmdarg_err)(const char *, va_list ap))
Definition wslog.c:847
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_DLL_PUBLIC void ws_logv(const char *domain, enum ws_log_level level, const char *format, va_list ap)
Definition wslog.c:1143
WS_DLL_PUBLIC void ws_log_init_with_writer(const char *progname, ws_log_writer_cb *writer, void(*vcmdarg_err)(const char *, va_list ap))
Definition wslog.c:927
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