Coverage Report

Created: 2025-12-16 08:26

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libwebsockets/include/libwebsockets/lws-logs.h
Line
Count
Source
1
/*
2
 * libwebsockets - small server side websockets and web server implementation
3
 *
4
 * Copyright (C) 2010 - 2021 Andy Green <andy@warmcat.com>
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to
8
 * deal in the Software without restriction, including without limitation the
9
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
 * sell copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22
 * IN THE SOFTWARE.
23
 */
24
25
/** \defgroup log Logging
26
 *
27
 * ##Logging
28
 *
29
 * Lws provides flexible and filterable logging facilities, which can be
30
 * used inside lws and in user code.
31
 *
32
 * Log categories may be individually filtered bitwise, and directed to built-in
33
 * sinks for syslog-compatible logging, or a user-defined function.
34
 *
35
 * Traditional logs use a single, processwide logging context.  New style log
36
 * apis (lws_xxx_cx()) can pass the logging context to use in.
37
 */
38
///@{
39
40
25
#define LLL_ERR     (1 << 0)
41
0
#define LLL_WARN    (1 << 1)
42
0
#define LLL_NOTICE    (1 << 2)
43
0
#define LLL_INFO    (1 << 3)
44
11.4k
#define LLL_DEBUG   (1 << 4)
45
0
#define LLL_PARSER    (1 << 5)
46
0
#define LLL_HEADER    (1 << 6)
47
#define LLL_EXT     (1 << 7)
48
0
#define LLL_CLIENT    (1 << 8)
49
#define LLL_LATENCY   (1 << 9)
50
0
#define LLL_USER    (1 << 10)
51
#define LLL_THREAD    (1 << 11)
52
53
25
#define LLL_COUNT   (12) /* set to count of valid flags */
54
55
#define LLLF_SECRECY_PII  (1 << 16)
56
  /**< contains Personally Identifiable Information */
57
#define LLLF_SECRECY_BEARER (1 << 17)
58
  /**< possession of this data allows impersonation */
59
60
#define LLLF_LOG_TIMESTAMP  (1 << 18)
61
  /**< set to prepend logs with timestamp */
62
63
25
#define LLLF_LOG_CONTEXT_AWARE  (1 << 30)
64
/**< set if the context uses an emit function that takes the logctx, auto-
65
 * applied when setting emit using lws_set_log_level_cx() api */
66
67
struct lws_log_cx;
68
69
typedef void (*lws_log_emit_t)(int level, const char *line);
70
typedef void (*lws_log_emit_cx_t)(struct lws_log_cx *cx, int level,
71
          const char *line, size_t len);
72
typedef void (*lws_log_prepend_cx_t)(struct lws_log_cx *cx, void *obj,
73
             char **p, char *e);
74
typedef void (*lws_log_use_cx_t)(struct lws_log_cx *cx, int _new);
75
76
/*
77
 * This is the logging context
78
 */
79
80
typedef struct lws_log_cx {
81
  union {
82
/* Apparently Qt likes to leave 'emit' defined at the preprocessor */
83
#if defined(emit)
84
#undef emit
85
#endif
86
    lws_log_emit_t    emit; /* legacy emit function */
87
    lws_log_emit_cx_t emit_cx; /* LLLF_LOG_CONTEXT_AWARE */
88
  } u;
89
90
#if LWS_MAX_SMP > 1
91
  pthread_mutex_t     refcount_lock;
92
#endif
93
94
  lws_log_use_cx_t    refcount_cb;
95
  /**< NULL, or a function called after each change to .refcount below,
96
   * this enables implementing side-effects like opening and closing
97
   * log files when the first and last object binds / unbinds */
98
  lws_log_prepend_cx_t    prepend;
99
  /**< NULL, or a cb to optionally prepend a string to logs we are a
100
   * parent of */
101
  struct lws_log_cx   *parent;
102
  /**< NULL, or points to log ctx we are a child of */
103
  void        *opaque;
104
  /**< ignored by lws, used to pass config to emit_cx, eg, filepath */
105
  void        *stg;
106
  /**< ignored by lws, may be used a storage by refcount_cb / emit_cx */
107
  uint32_t      lll_flags;
108
  /**< mask of log levels we want to emit in this context */
109
  int32_t       refcount;
110
  /**< refcount of objects bound to this log context */
111
#if LWS_MAX_SMP > 1
112
  char        inited;
113
#endif
114
} lws_log_cx_t;
115
116
/**
117
 * lwsl_timestamp: generate logging timestamp string
118
 *
119
 * \param level:  logging level
120
 * \param p:    char * buffer to take timestamp
121
 * \param len:  length of p
122
 *
123
 * returns length written in p
124
 */
125
LWS_VISIBLE LWS_EXTERN int
126
lwsl_timestamp(int level, char *p, size_t len);
127
128
#if defined(LWS_PLAT_OPTEE) && !defined(LWS_WITH_NETWORK)
129
#define _lws_log(aaa, ...) SMSG(__VA_ARGS__)
130
#else
131
LWS_VISIBLE LWS_EXTERN void
132
_lws_log(int filter, const char *format, ...) LWS_FORMAT(2);
133
LWS_VISIBLE LWS_EXTERN void
134
_lws_logv(int filter, const char *format, va_list vl);
135
#endif
136
137
struct lws_vhost;
138
struct lws;
139
140
LWS_VISIBLE LWS_EXTERN struct lws_log_cx *
141
lwsl_context_get_cx(struct lws_context *cx);
142
LWS_VISIBLE LWS_EXTERN struct lws_log_cx *
143
lwsl_vhost_get_cx(struct lws_vhost *vh);
144
LWS_VISIBLE LWS_EXTERN struct lws_log_cx *
145
lwsl_wsi_get_cx(struct lws *wsi);
146
#if defined(LWS_WITH_SECURE_STREAMS)
147
struct lws_ss_handle;
148
LWS_VISIBLE LWS_EXTERN struct lws_log_cx *
149
lwsl_ss_get_cx(struct lws_ss_handle *ss);
150
#endif
151
#if defined(LWS_WITH_SECURE_STREAMS_PROXY_API)
152
struct lws_sspc_handle;
153
LWS_VISIBLE LWS_EXTERN struct lws_log_cx *
154
lwsl_sspc_get_cx(struct lws_sspc_handle *ss);
155
#endif
156
157
158
LWS_VISIBLE LWS_EXTERN void
159
lws_log_emit_cx_file(struct lws_log_cx *cx, int level, const char *line,
160
      size_t len);
161
162
LWS_VISIBLE LWS_EXTERN void
163
lws_log_use_cx_file(struct lws_log_cx *cx, int _new);
164
165
LWS_VISIBLE LWS_EXTERN void
166
lws_log_prepend_context(struct lws_log_cx *cx, void *obj, char **p, char *e);
167
LWS_VISIBLE LWS_EXTERN void
168
lws_log_prepend_vhost(struct lws_log_cx *cx, void *obj, char **p, char *e);
169
LWS_VISIBLE LWS_EXTERN void
170
lws_log_prepend_wsi(struct lws_log_cx *cx, void *obj, char **p, char *e);
171
#if defined(LWS_WITH_SECURE_STREAMS)
172
LWS_VISIBLE LWS_EXTERN void
173
lws_log_prepend_ss(struct lws_log_cx *cx, void *obj, char **p, char *e);
174
#endif
175
#if defined(LWS_WITH_SECURE_STREAMS_PROXY_API)
176
LWS_VISIBLE LWS_EXTERN void
177
lws_log_prepend_sspc(struct lws_log_cx *cx, void *obj, char **p, char *e);
178
#endif
179
180
LWS_VISIBLE LWS_EXTERN void
181
_lws_log_cx(lws_log_cx_t *cx, lws_log_prepend_cx_t prep, void *obj,
182
      int filter, const char *_fun, const char *format, ...) LWS_FORMAT(6);
183
184
#define lwsl_cx(_c, _fil, ...) \
185
0
     _lws_log_cx(lwsl_context_get_cx(_c), lws_log_prepend_context, \
186
0
          _c, _fil, __func__, __VA_ARGS__)
187
#define lwsl_vhost(_v, _fil, ...) \
188
0
     _lws_log_cx(lwsl_vhost_get_cx(_v), lws_log_prepend_vhost, _v, \
189
0
          _fil, __func__, __VA_ARGS__)
190
#define lwsl_wsi(_w, _fil, ...) \
191
0
     _lws_log_cx(lwsl_wsi_get_cx(_w), lws_log_prepend_wsi, _w, \
192
0
          _fil, __func__, __VA_ARGS__)
193
#define lwsl_ss(_h, _fil, ...) \
194
0
     _lws_log_cx(lwsl_ss_get_cx(_h), lws_log_prepend_ss, _h, \
195
0
          _fil, __func__, __VA_ARGS__)
196
197
#define lwsl_hexdump_context(_c, _fil, _buf, _len) \
198
    lwsl_hexdump_level_cx(lwsl_context_get_cx(_c), \
199
              lws_log_prepend_context, \
200
              _c, _fil, _buf, _len)
201
#define lwsl_hexdump_vhost(_v, _fil, _buf, _len) \
202
    lwsl_hexdump_level_cx(lwsl_vhost_get_cx(_v), \
203
              lws_log_prepend_vhost, \
204
              _v, _fil, _buf, _len)
205
#define lwsl_hexdump_wsi(_w, _fil, _buf, _len) \
206
0
    lwsl_hexdump_level_cx(lwsl_wsi_get_cx(_w), \
207
0
              lws_log_prepend_wsi, \
208
0
              _w, _fil, _buf, _len)
209
#define lwsl_hexdump_ss(_h, _fil, _buf, _len) \
210
    lwsl_hexdump_level_cx(lwsl_ss_get_cx(_h), \
211
              lws_log_prepend_ss, \
212
              _h, _fil, _buf, _len)
213
214
/*
215
 * Figure out which logs to build in or not
216
 */
217
218
#if defined(_DEBUG)
219
 /*
220
  * In DEBUG build, select all logs unless NO_LOGS
221
  */
222
 #if defined(LWS_WITH_NO_LOGS)
223
  #define _LWS_LINIT (LLL_ERR | LLL_USER)
224
 #else
225
   #define _LWS_LINIT ((1 << LLL_COUNT) - 1)
226
 #endif
227
#else /* not _DEBUG */
228
#if defined(LWS_WITH_NO_LOGS)
229
#define _LWS_LINIT (LLL_ERR | LLL_USER)
230
#else
231
 #define _LWS_LINIT (LLL_ERR | LLL_USER | LLL_WARN | LLL_NOTICE)
232
#endif
233
#endif /* _DEBUG */
234
235
/*
236
 * Create either empty overrides or the ones forced at build-time.
237
 * These overrides have the final say... any bits set in
238
 * LWS_LOGGING_BITFIELD_SET force the build of those logs, any bits
239
 * set in LWS_LOGGING_BITFIELD_CLEAR disable the build of those logs.
240
 *
241
 * If not defined lws decides based on CMAKE_BUILD_TYPE=DEBUG or not
242
 */
243
244
#if defined(LWS_LOGGING_BITFIELD_SET)
245
 #define _LWS_LBS (LWS_LOGGING_BITFIELD_SET)
246
#else
247
 #define _LWS_LBS 0
248
#endif
249
250
#if defined(LWS_LOGGING_BITFIELD_CLEAR)
251
 #define _LWS_LBC (LWS_LOGGING_BITFIELD_CLEAR)
252
#else
253
 #define _LWS_LBC 0
254
#endif
255
256
/*
257
 * Compute the final active logging bitfield for build
258
 */
259
#define _LWS_ENABLED_LOGS (((_LWS_LINIT) | (_LWS_LBS)) & ~(_LWS_LBC))
260
261
/*
262
 * Individually enable or disable log levels for build
263
 * depending on what was computed
264
 */
265
266
/*
267
 * Process scope logs
268
 */
269
270
#if (_LWS_ENABLED_LOGS & LLL_ERR)
271
25
#define lwsl_err(...) _lws_log(LLL_ERR, __VA_ARGS__)
272
#else
273
#define lwsl_err(...) do {} while(0)
274
#endif
275
276
#if (_LWS_ENABLED_LOGS & LLL_WARN)
277
0
#define lwsl_warn(...) _lws_log(LLL_WARN, __VA_ARGS__)
278
#else
279
#define lwsl_warn(...) do {} while(0)
280
#endif
281
282
#if (_LWS_ENABLED_LOGS & LLL_NOTICE)
283
0
#define lwsl_notice(...) _lws_log(LLL_NOTICE, __VA_ARGS__)
284
#else
285
#define lwsl_notice(...) do {} while(0)
286
#endif
287
288
#if (_LWS_ENABLED_LOGS & LLL_INFO)
289
0
#define lwsl_info(...) _lws_log(LLL_INFO, __VA_ARGS__)
290
#else
291
#define lwsl_info(...) do {} while(0)
292
#endif
293
294
#if (_LWS_ENABLED_LOGS & LLL_DEBUG)
295
11.4k
#define lwsl_debug(...) _lws_log(LLL_DEBUG, __VA_ARGS__)
296
#else
297
#define lwsl_debug(...) do {} while(0)
298
#endif
299
300
#if (_LWS_ENABLED_LOGS & LLL_PARSER)
301
0
#define lwsl_parser(...) _lws_log(LLL_PARSER, __VA_ARGS__)
302
#else
303
#define lwsl_parser(...) do {} while(0)
304
#endif
305
306
#if (_LWS_ENABLED_LOGS & LLL_HEADER)
307
0
#define lwsl_header(...) _lws_log(LLL_HEADER, __VA_ARGS__)
308
#else
309
#define lwsl_header(...) do {} while(0)
310
#endif
311
312
#if (_LWS_ENABLED_LOGS & LLL_EXT)
313
#define lwsl_ext(...) _lws_log(LLL_EXT, __VA_ARGS__)
314
#else
315
#define lwsl_ext(...) do {} while(0)
316
#endif
317
318
#if (_LWS_ENABLED_LOGS & LLL_CLIENT)
319
0
#define lwsl_client(...) _lws_log(LLL_CLIENT, __VA_ARGS__)
320
#else
321
#define lwsl_client(...) do {} while(0)
322
#endif
323
324
#if (_LWS_ENABLED_LOGS & LLL_LATENCY)
325
#define lwsl_latency(...) _lws_log(LLL_LATENCY, __VA_ARGS__)
326
#else
327
#define lwsl_latency(...) do {} while(0)
328
#endif
329
330
#if (_LWS_ENABLED_LOGS & LLL_THREAD)
331
#define lwsl_thread(...) _lws_log(LLL_THREAD, __VA_ARGS__)
332
#else
333
#define lwsl_thread(...) do {} while(0)
334
#endif
335
336
#if (_LWS_ENABLED_LOGS & LLL_USER)
337
0
#define lwsl_user(...) _lws_log(LLL_USER, __VA_ARGS__)
338
#else
339
#define lwsl_user(...) do {} while(0)
340
#endif
341
342
#define lwsl_hexdump_user(...)    lwsl_hexdump_level(LLL_USER,   __VA_ARGS__)
343
0
#define lwsl_hexdump_err(...)   lwsl_hexdump_level(LLL_ERR,    __VA_ARGS__)
344
#define lwsl_hexdump_warn(...)    lwsl_hexdump_level(LLL_WARN,   __VA_ARGS__)
345
0
#define lwsl_hexdump_notice(...)  lwsl_hexdump_level(LLL_NOTICE, __VA_ARGS__)
346
0
#define lwsl_hexdump_info(...)    lwsl_hexdump_level(LLL_INFO,   __VA_ARGS__)
347
0
#define lwsl_hexdump_debug(...)   lwsl_hexdump_level(LLL_DEBUG,  __VA_ARGS__)
348
349
/*
350
 * lws_context scope logs
351
 */
352
353
#if (_LWS_ENABLED_LOGS & LLL_ERR)
354
0
#define lwsl_cx_err(_c, ...) lwsl_cx(_c, LLL_ERR, __VA_ARGS__)
355
#else
356
#define lwsl_cx_err(_c, ...) do {} while(0)
357
#endif
358
359
#if (_LWS_ENABLED_LOGS & LLL_WARN)
360
0
#define lwsl_cx_warn(_c, ...) lwsl_cx(_c, LLL_WARN, __VA_ARGS__)
361
#else
362
#define lwsl_cx_warn(_c, ...) do {} while(0)
363
#endif
364
365
#if (_LWS_ENABLED_LOGS & LLL_NOTICE)
366
0
#define lwsl_cx_notice(_c, ...) lwsl_cx(_c, LLL_NOTICE, __VA_ARGS__)
367
#else
368
#define lwsl_cx_notice(_c, ...) do {} while(0)
369
#endif
370
371
#if (_LWS_ENABLED_LOGS & LLL_INFO)
372
0
#define lwsl_cx_info(_c, ...) lwsl_cx(_c, LLL_INFO, __VA_ARGS__)
373
#else
374
#define lwsl_cx_info(_c, ...) do {} while(0)
375
#endif
376
377
#if (_LWS_ENABLED_LOGS & LLL_DEBUG)
378
0
#define lwsl_cx_debug(_c, ...) lwsl_cx(_c, LLL_DEBUG, __VA_ARGS__)
379
#else
380
#define lwsl_cx_debug(_c, ...) do {} while(0)
381
#endif
382
383
#if (_LWS_ENABLED_LOGS & LLL_PARSER)
384
#define lwsl_cx_parser(_c, ...) lwsl_cx(_c, LLL_PARSER, __VA_ARGS__)
385
#else
386
#define lwsl_cx_parser(_c, ...) do {} while(0)
387
#endif
388
389
#if (_LWS_ENABLED_LOGS & LLL_HEADER)
390
#define lwsl_cx_header(_c, ...) lwsl_cx(_c, LLL_HEADER, __VA_ARGS__)
391
#else
392
#define lwsl_cx_header(_c, ...) do {} while(0)
393
#endif
394
395
#if (_LWS_ENABLED_LOGS & LLL_EXT)
396
#define lwsl_cx_ext(_c, ...) lwsl_cx(_c, LLL_EXT, __VA_ARGS__)
397
#else
398
#define lwsl_cx_ext(_c, ...) do {} while(0)
399
#endif
400
401
#if (_LWS_ENABLED_LOGS & LLL_CLIENT)
402
#define lwsl_cx_client(_c, ...) lwsl_cx(_c, LLL_CLIENT, __VA_ARGS__)
403
#else
404
#define lwsl_cx_client(_c, ...) do {} while(0)
405
#endif
406
407
#if (_LWS_ENABLED_LOGS & LLL_LATENCY)
408
#define lwsl_cx_latency(_c, ...) lwsl_cx(_c, LLL_LATENCY, __VA_ARGS__)
409
#else
410
#define lwsl_cx_latency(_c, ...) do {} while(0)
411
#endif
412
413
#if (_LWS_ENABLED_LOGS & LLL_THREAD)
414
#define lwsl_cx_thread(_c, ...) lwsl_cx(_c, LLL_THREAD, __VA_ARGS__)
415
#else
416
#define lwsl_cx_thread(_c, ...) do {} while(0)
417
#endif
418
419
#if (_LWS_ENABLED_LOGS & LLL_USER)
420
#define lwsl_cx_user(_c, ...) lwsl_cx(_c, LLL_USER, __VA_ARGS__)
421
#else
422
#define lwsl_cx_user(_c, ...) do {} while(0)
423
#endif
424
425
#define lwsl_hexdump_cx_err(_c, ...)    lwsl_hexdump_context(_c, LLL_ERR, __VA_ARGS__)
426
#define lwsl_hexdump_cx_warn(_c, ...)   lwsl_hexdump_context(_c, LLL_WARN, __VA_ARGS__)
427
#define lwsl_hexdump_cx_notice(_c, ...) lwsl_hexdump_context(_c, LLL_NOTICE, __VA_ARGS__)
428
#define lwsl_hexdump_cx_info(_c, ...)   lwsl_hexdump_context(_c, LLL_INFO, __VA_ARGS__)
429
#define lwsl_hexdump_cx_debug(_c, ...)  lwsl_hexdump_context(_c, LLL_DEBUG, __VA_ARGS__)
430
431
/*
432
 * lws_vhost
433
 */
434
435
#if (_LWS_ENABLED_LOGS & LLL_ERR)
436
0
#define lwsl_vhost_err(_v, ...) lwsl_vhost(_v, LLL_ERR, __VA_ARGS__)
437
#else
438
#define lwsl_vhost_err(_v, ...) do {} while(0)
439
#endif
440
441
#if (_LWS_ENABLED_LOGS & LLL_WARN)
442
0
#define lwsl_vhost_warn(_v, ...) lwsl_vhost(_v, LLL_WARN, __VA_ARGS__)
443
#else
444
#define lwsl_vhost_warn(_v, ...) do {} while(0)
445
#endif
446
447
#if (_LWS_ENABLED_LOGS & LLL_NOTICE)
448
0
#define lwsl_vhost_notice(_v, ...) lwsl_vhost(_v, LLL_NOTICE, __VA_ARGS__)
449
#else
450
#define lwsl_vhost_notice(_v, ...) do {} while(0)
451
#endif
452
453
#if (_LWS_ENABLED_LOGS & LLL_INFO)
454
0
#define lwsl_vhost_info(_v, ...) lwsl_vhost(_v, LLL_INFO, __VA_ARGS__)
455
#else
456
#define lwsl_vhost_info(_v, ...) do {} while(0)
457
#endif
458
459
#if (_LWS_ENABLED_LOGS & LLL_DEBUG)
460
0
#define lwsl_vhost_debug(_v, ...) lwsl_vhost(_v, LLL_DEBUG, __VA_ARGS__)
461
#else
462
#define lwsl_vhost_debug(_v, ...) do {} while(0)
463
#endif
464
465
#if (_LWS_ENABLED_LOGS & LLL_PARSER)
466
#define lwsl_vhost_parser(_v, ...) lwsl_vhost(_v, LLL_PARSER, __VA_ARGS__)
467
#else
468
#define lwsl_vhost_parser(_v, ...) do {} while(0)
469
#endif
470
471
#if (_LWS_ENABLED_LOGS & LLL_HEADER)
472
#define lwsl_vhost_header(_v, ...) lwsl_vhost(_v, LLL_HEADER, __VA_ARGS__)
473
#else
474
#define lwsl_vhost_header(_v, ...) do {} while(0)
475
#endif
476
477
#if (_LWS_ENABLED_LOGS & LLL_EXT)
478
#define lwsl_vhost_ext(_v, ...) lwsl_vhost(_v, LLL_EXT, __VA_ARGS__)
479
#else
480
#define lwsl_vhost_ext(_v, ...) do {} while(0)
481
#endif
482
483
#if (_LWS_ENABLED_LOGS & LLL_CLIENT)
484
#define lwsl_vhost_client(_v, ...) lwsl_vhost(_v, LLL_CLIENT, __VA_ARGS__)
485
#else
486
#define lwsl_vhost_client(_v, ...) do {} while(0)
487
#endif
488
489
#if (_LWS_ENABLED_LOGS & LLL_LATENCY)
490
#define lwsl_vhost_latency(_v, ...) lwsl_vhost(_v, LLL_LATENCY, __VA_ARGS__)
491
#else
492
#define lwsl_vhost_latency(_v, ...) do {} while(0)
493
#endif
494
495
#if (_LWS_ENABLED_LOGS & LLL_THREAD)
496
#define lwsl_vhost_thread(_v, ...) lwsl_vhost(_v, LLL_THREAD, __VA_ARGS__)
497
#else
498
#define lwsl_vhost_thread(_v, ...) do {} while(0)
499
#endif
500
501
#if (_LWS_ENABLED_LOGS & LLL_USER)
502
#define lwsl_vhost_user(_v, ...) lwsl_vhost(_v, LLL_USER, __VA_ARGS__)
503
#else
504
#define lwsl_vhost_user(_v, ...) do {} while(0)
505
#endif
506
507
#define lwsl_hexdump_vhost_err(_v, ...)    lwsl_hexdump_vhost(_v, LLL_ERR, __VA_ARGS__)
508
#define lwsl_hexdump_vhost_warn(_v, ...)   lwsl_hexdump_vhost(_v, LLL_WARN, __VA_ARGS__)
509
#define lwsl_hexdump_vhost_notice(_v, ...) lwsl_hexdump_vhost(_v, LLL_NOTICE, __VA_ARGS__)
510
#define lwsl_hexdump_vhost_info(_v, ...)   lwsl_hexdump_vhost(_v, LLL_INFO, __VA_ARGS__)
511
#define lwsl_hexdump_vhost_debug(_v, ...)  lwsl_hexdump_vhost(_v, LLL_DEBUG, __VA_ARGS__)
512
513
514
/*
515
 * lws_wsi
516
 */
517
518
#if (_LWS_ENABLED_LOGS & LLL_ERR)
519
0
#define lwsl_wsi_err(_w, ...) lwsl_wsi(_w, LLL_ERR, __VA_ARGS__)
520
#else
521
#define lwsl_wsi_err(_w, ...) do {} while(0)
522
#endif
523
524
#if (_LWS_ENABLED_LOGS & LLL_WARN)
525
0
#define lwsl_wsi_warn(_w, ...) lwsl_wsi(_w, LLL_WARN, __VA_ARGS__)
526
#else
527
#define lwsl_wsi_warn(_w, ...) do {} while(0)
528
#endif
529
530
#if (_LWS_ENABLED_LOGS & LLL_NOTICE)
531
0
#define lwsl_wsi_notice(_w, ...) lwsl_wsi(_w, LLL_NOTICE, __VA_ARGS__)
532
#else
533
#define lwsl_wsi_notice(_w, ...) do {} while(0)
534
#endif
535
536
#if (_LWS_ENABLED_LOGS & LLL_INFO)
537
0
#define lwsl_wsi_info(_w, ...) lwsl_wsi(_w, LLL_INFO, __VA_ARGS__)
538
#else
539
#define lwsl_wsi_info(_w, ...) do {} while(0)
540
#endif
541
542
#if (_LWS_ENABLED_LOGS & LLL_DEBUG)
543
0
#define lwsl_wsi_debug(_w, ...) lwsl_wsi(_w, LLL_DEBUG, __VA_ARGS__)
544
#else
545
#define lwsl_wsi_debug(_w, ...) do {} while(0)
546
#endif
547
548
#if (_LWS_ENABLED_LOGS & LLL_PARSER)
549
0
#define lwsl_wsi_parser(_w, ...) lwsl_wsi(_w, LLL_PARSER, __VA_ARGS__)
550
#else
551
#define lwsl_wsi_parser(_w, ...) do {} while(0)
552
#endif
553
554
#if (_LWS_ENABLED_LOGS & LLL_HEADER)
555
#define lwsl_wsi_header(_w, ...) lwsl_wsi(_w, LLL_HEADER, __VA_ARGS__)
556
#else
557
#define lwsl_wsi_header(_w, ...) do {} while(0)
558
#endif
559
560
#if (_LWS_ENABLED_LOGS & LLL_EXT)
561
0
#define lwsl_wsi_ext(_w, ...) lwsl_wsi(_w, LLL_EXT, __VA_ARGS__)
562
#else
563
#define lwsl_wsi_ext(_w, ...) do {} while(0)
564
#endif
565
566
#if (_LWS_ENABLED_LOGS & LLL_CLIENT)
567
#define lwsl_wsi_client(_w, ...) lwsl_wsi(_w, LLL_CLIENT, __VA_ARGS__)
568
#else
569
#define lwsl_wsi_client(_w, ...) do {} while(0)
570
#endif
571
572
#if (_LWS_ENABLED_LOGS & LLL_LATENCY)
573
#define lwsl_wsi_latency(_w, ...) lwsl_wsi(_w, LLL_LATENCY, __VA_ARGS__)
574
#else
575
#define lwsl_wsi_latency(_w, ...) do {} while(0)
576
#endif
577
578
#if (_LWS_ENABLED_LOGS & LLL_THREAD)
579
#define lwsl_wsi_thread(_w, ...) lwsl_wsi(_w, LLL_THREAD, __VA_ARGS__)
580
#else
581
#define lwsl_wsi_thread(_w, ...) do {} while(0)
582
#endif
583
584
#if (_LWS_ENABLED_LOGS & LLL_USER)
585
#define lwsl_wsi_user(_w, ...) lwsl_wsi(_w, LLL_USER, __VA_ARGS__)
586
#else
587
#define lwsl_wsi_user(_w, ...) do {} while(0)
588
#endif
589
590
#define lwsl_hexdump_wsi_err(_v, ...)    lwsl_hexdump_wsi(_v, LLL_ERR, __VA_ARGS__)
591
#define lwsl_hexdump_wsi_warn(_v, ...)   lwsl_hexdump_wsi(_v, LLL_WARN, __VA_ARGS__)
592
#define lwsl_hexdump_wsi_notice(_v, ...) lwsl_hexdump_wsi(_v, LLL_NOTICE, __VA_ARGS__)
593
0
#define lwsl_hexdump_wsi_info(_v, ...)   lwsl_hexdump_wsi(_v, LLL_INFO, __VA_ARGS__)
594
0
#define lwsl_hexdump_wsi_debug(_v, ...)  lwsl_hexdump_wsi(_v, LLL_DEBUG, __VA_ARGS__)
595
#define lwsl_hexdump_wsi_user(_v, ...)   lwsl_hexdump_wsi(_v, LLL_USER, __VA_ARGS__)
596
597
598
599
/*
600
 * lwsl_ss
601
 */
602
603
#if (_LWS_ENABLED_LOGS & LLL_ERR)
604
0
#define lwsl_ss_err(_w, ...) lwsl_ss(_w, LLL_ERR, __VA_ARGS__)
605
#else
606
#define lwsl_ss_err(_w, ...) do {} while(0)
607
#endif
608
609
#if (_LWS_ENABLED_LOGS & LLL_WARN)
610
0
#define lwsl_ss_warn(_w, ...) lwsl_ss(_w, LLL_WARN, __VA_ARGS__)
611
#else
612
#define lwsl_ss_warn(_w, ...) do {} while(0)
613
#endif
614
615
#if (_LWS_ENABLED_LOGS & LLL_NOTICE)
616
0
#define lwsl_ss_notice(_w, ...) lwsl_ss(_w, LLL_NOTICE, __VA_ARGS__)
617
#else
618
#define lwsl_ss_notice(_w, ...) do {} while(0)
619
#endif
620
621
#if (_LWS_ENABLED_LOGS & LLL_INFO)
622
0
#define lwsl_ss_info(_w, ...) lwsl_ss(_w, LLL_INFO, __VA_ARGS__)
623
#else
624
#define lwsl_ss_info(_w, ...) do {} while(0)
625
#endif
626
627
#if (_LWS_ENABLED_LOGS & LLL_DEBUG)
628
0
#define lwsl_ss_debug(_w, ...) lwsl_ss(_w, LLL_DEBUG, __VA_ARGS__)
629
#else
630
#define lwsl_ss_debug(_w, ...) do {} while(0)
631
#endif
632
633
#if (_LWS_ENABLED_LOGS & LLL_PARSER)
634
#define lwsl_ss_parser(_w, ...) lwsl_ss(_w, LLL_PARSER, __VA_ARGS__)
635
#else
636
#define lwsl_ss_parser(_w, ...) do {} while(0)
637
#endif
638
639
#if (_LWS_ENABLED_LOGS & LLL_HEADER)
640
#define lwsl_ss_header(_w, ...) lwsl_ss(_w, LLL_HEADER, __VA_ARGS__)
641
#else
642
#define lwsl_ss_header(_w, ...) do {} while(0)
643
#endif
644
645
#if (_LWS_ENABLED_LOGS & LLL_EXT)
646
#define lwsl_ss_ext(_w, ...) lwsl_ss(_w, LLL_EXT, __VA_ARGS__)
647
#else
648
#define lwsl_ss_ext(_w, ...) do {} while(0)
649
#endif
650
651
#if (_LWS_ENABLED_LOGS & LLL_CLIENT)
652
#define lwsl_ss_client(_w, ...) lwsl_ss(_w, LLL_CLIENT, __VA_ARGS__)
653
#else
654
#define lwsl_ss_client(_w, ...) do {} while(0)
655
#endif
656
657
#if (_LWS_ENABLED_LOGS & LLL_LATENCY)
658
#define lwsl_ss_latency(_w, ...) lwsl_ss(_w, LLL_LATENCY, __VA_ARGS__)
659
#else
660
#define lwsl_ss_latency(_w, ...) do {} while(0)
661
#endif
662
663
#if (_LWS_ENABLED_LOGS & LLL_THREAD)
664
#define lwsl_ss_thread(_w, ...) lwsl_ss(_w, LLL_THREAD, __VA_ARGS__)
665
#else
666
#define lwsl_ss_thread(_w, ...) do {} while(0)
667
#endif
668
669
#if (_LWS_ENABLED_LOGS & LLL_USER)
670
#define lwsl_ss_user(_w, ...) lwsl_ss(_w, LLL_USER, __VA_ARGS__)
671
#else
672
#define lwsl_ss_user(_w, ...) do {} while(0)
673
#endif
674
675
#define lwsl_hexdump_ss_err(_v, ...)    lwsl_hexdump_ss(_v, LLL_ERR, __VA_ARGS__)
676
#define lwsl_hexdump_ss_warn(_v, ...)   lwsl_hexdump_ss(_v, LLL_WARN, __VA_ARGS__)
677
#define lwsl_hexdump_ss_notice(_v, ...) lwsl_hexdump_ss(_v, LLL_NOTICE, __VA_ARGS__)
678
#define lwsl_hexdump_ss_info(_v, ...)   lwsl_hexdump_ss(_v, LLL_INFO, __VA_ARGS__)
679
#define lwsl_hexdump_ss_debug(_v, ...)  lwsl_hexdump_ss(_v, LLL_DEBUG, __VA_ARGS__)
680
681
682
683
/**
684
 * lwsl_hexdump_level() - helper to hexdump a buffer at a selected debug level
685
 *
686
 * \param level: one of LLL_ constants
687
 * \param vbuf: buffer start to dump
688
 * \param len: length of buffer to dump
689
 *
690
 * If \p level is visible, does a nice hexdump -C style dump of \p vbuf for
691
 * \p len bytes.  This can be extremely convenient while debugging.
692
 */
693
LWS_VISIBLE LWS_EXTERN void
694
lwsl_hexdump_level(int level, const void *vbuf, size_t len);
695
696
LWS_VISIBLE LWS_EXTERN void
697
lwsl_hexdump_level_cx(lws_log_cx_t *cx, lws_log_prepend_cx_t prep, void *obj,
698
          int hexdump_level, const void *vbuf, size_t len);
699
700
/**
701
 * lwsl_hexdump() - helper to hexdump a buffer (DEBUG builds only)
702
 *
703
 * \param buf: buffer start to dump
704
 * \param len: length of buffer to dump
705
 *
706
 * Calls through to lwsl_hexdump_level(LLL_DEBUG, ... for compatability.
707
 * It's better to use lwsl_hexdump_level(level, ... directly so you can control
708
 * the visibility.
709
 */
710
LWS_VISIBLE LWS_EXTERN void
711
lwsl_hexdump(const void *buf, size_t len);
712
713
/**
714
 * lws_is_be() - returns nonzero if the platform is Big Endian
715
 */
716
0
static LWS_INLINE int lws_is_be(void) {
717
0
  const int probe = ~0xff;
718
0
719
0
  return *(const char *)&probe;
720
0
}
Unexecuted instantiation: upng-gzip.c:lws_is_be
Unexecuted instantiation: alloc.c:lws_is_be
Unexecuted instantiation: logs.c:lws_is_be
Unexecuted instantiation: unix-misc.c:lws_is_be
Unexecuted instantiation: lws_dll2.c:lws_is_be
Unexecuted instantiation: context.c:lws_is_be
Unexecuted instantiation: libwebsockets.c:lws_is_be
Unexecuted instantiation: lws-cache-ttl.c:lws_is_be
Unexecuted instantiation: heap.c:lws_is_be
Unexecuted instantiation: file.c:lws_is_be
Unexecuted instantiation: dlo.c:lws_is_be
Unexecuted instantiation: dlo-text.c:lws_is_be
Unexecuted instantiation: dlo-png.c:lws_is_be
Unexecuted instantiation: dlo-jpeg.c:lws_is_be
Unexecuted instantiation: lwsac.c:lws_is_be
Unexecuted instantiation: stdin.c:lws_is_be
Unexecuted instantiation: system.c:lws_is_be
Unexecuted instantiation: smd.c:lws_is_be
Unexecuted instantiation: close.c:lws_is_be
Unexecuted instantiation: vhost.c:lws_is_be
Unexecuted instantiation: pollfd.c:lws_is_be
Unexecuted instantiation: service.c:lws_is_be
Unexecuted instantiation: sorted-usec-list.c:lws_is_be
Unexecuted instantiation: wsi.c:lws_is_be
Unexecuted instantiation: wsi-timeout.c:lws_is_be
Unexecuted instantiation: adopt.c:lws_is_be
Unexecuted instantiation: ops-pipe.c:lws_is_be
Unexecuted instantiation: state.c:lws_is_be
Unexecuted instantiation: client.c:lws_is_be
Unexecuted instantiation: sort-dns.c:lws_is_be
Unexecuted instantiation: conmon.c:lws_is_be
Unexecuted instantiation: header.c:lws_is_be
Unexecuted instantiation: parsers.c:lws_is_be
Unexecuted instantiation: server.c:lws_is_be
Unexecuted instantiation: ops-h1.c:lws_is_be
Unexecuted instantiation: http2.c:lws_is_be
Unexecuted instantiation: hpack.c:lws_is_be
Unexecuted instantiation: ops-h2.c:lws_is_be
Unexecuted instantiation: ops-ws.c:lws_is_be
Unexecuted instantiation: client-ws.c:lws_is_be
Unexecuted instantiation: client-parser-ws.c:lws_is_be
Unexecuted instantiation: server-ws.c:lws_is_be
Unexecuted instantiation: ops-raw-skt.c:lws_is_be
Unexecuted instantiation: ops-raw-file.c:lws_is_be
Unexecuted instantiation: ops-listen.c:lws_is_be
Unexecuted instantiation: client-http.c:lws_is_be
Unexecuted instantiation: ops-netlink.c:lws_is_be
Unexecuted instantiation: poll.c:lws_is_be
Unexecuted instantiation: secure-streams.c:lws_is_be
Unexecuted instantiation: policy-common.c:lws_is_be
Unexecuted instantiation: captive-portal-detect.c:lws_is_be
Unexecuted instantiation: ss-raw.c:lws_is_be
Unexecuted instantiation: policy-json.c:lws_is_be
Unexecuted instantiation: fetch-policy.c:lws_is_be
Unexecuted instantiation: ss-h1.c:lws_is_be
Unexecuted instantiation: ss-h2.c:lws_is_be
Unexecuted instantiation: ss-ws.c:lws_is_be
Unexecuted instantiation: unix-caps.c:lws_is_be
Unexecuted instantiation: unix-init.c:lws_is_be
Unexecuted instantiation: unix-file.c:lws_is_be
Unexecuted instantiation: unix-pipe.c:lws_is_be
Unexecuted instantiation: unix-service.c:lws_is_be
Unexecuted instantiation: unix-sockets.c:lws_is_be
Unexecuted instantiation: unix-fds.c:lws_is_be
Unexecuted instantiation: tls-network.c:lws_is_be
Unexecuted instantiation: openssl-tls.c:lws_is_be
Unexecuted instantiation: openssl-x509.c:lws_is_be
Unexecuted instantiation: openssl-ssl.c:lws_is_be
Unexecuted instantiation: openssl-session.c:lws_is_be
Unexecuted instantiation: lws-genhash.c:lws_is_be
Unexecuted instantiation: tls-server.c:lws_is_be
Unexecuted instantiation: openssl-server.c:lws_is_be
Unexecuted instantiation: tls-client.c:lws_is_be
Unexecuted instantiation: openssl-client.c:lws_is_be
Unexecuted instantiation: lws-gencrypto-common.c:lws_is_be
Unexecuted instantiation: buflist.c:lws_is_be
Unexecuted instantiation: vfs.c:lws_is_be
Unexecuted instantiation: base64-decode.c:lws_is_be
Unexecuted instantiation: upng.c:lws_is_be
Unexecuted instantiation: jpeg.c:lws_is_be
Unexecuted instantiation: dlo-font-mcufont.c:lws_is_be
Unexecuted instantiation: sha-1.c:lws_is_be
Unexecuted instantiation: lejp.c:lws_is_be
Unexecuted instantiation: dummy-callback.c:lws_is_be
Unexecuted instantiation: output.c:lws_is_be
Unexecuted instantiation: network.c:lws_is_be
Unexecuted instantiation: route.c:lws_is_be
Unexecuted instantiation: connect.c:lws_is_be
Unexecuted instantiation: connect2.c:lws_is_be
Unexecuted instantiation: connect3.c:lws_is_be
Unexecuted instantiation: connect4.c:lws_is_be
Unexecuted instantiation: date.c:lws_is_be
Unexecuted instantiation: cookie.c:lws_is_be
Unexecuted instantiation: tls.c:lws_is_be
Unexecuted instantiation: tls-sessions.c:lws_is_be
721
722
/**
723
 * lws_set_log_level() - Set the logging bitfield
724
 * \param level:  OR together the LLL_ debug contexts you want output from
725
 * \param log_emit_function:  NULL to leave it as it is, or a user-supplied
726
 *      function to perform log string emission instead of
727
 *      the default stderr one.
728
 *
729
 * log level defaults to "err", "warn" and "notice" contexts enabled and
730
 * emission on stderr.  If stderr is a tty (according to isatty()) then
731
 * the output is coloured according to the log level using ANSI escapes.
732
 *
733
 * You can set the default security level for logging using the
734
 * secrecy_and_log_level() macro to set the \p level parameter, eg
735
 *
736
 * lws_set_log_level(secrecy_and_log_level(LWS_SECRECY_PII, LLL_ERR | LLL_WARN),
737
 *         my_emit_function);
738
 *
739
 * Normally you can just leave it at the default.
740
 */
741
LWS_VISIBLE LWS_EXTERN void
742
lws_set_log_level(int level, lws_log_emit_t log_emit_function);
743
744
/**
745
 * lwsl_emit_syslog() - helper log emit function writes to system log
746
 *
747
 * \param level: one of LLL_ log level indexes
748
 * \param line: log string
749
 *
750
 * You use this by passing the function pointer to lws_set_log_level(), to set
751
 * it as the log emit function, it is not called directly.
752
 */
753
LWS_VISIBLE LWS_EXTERN void
754
lwsl_emit_syslog(int level, const char *line);
755
756
/**
757
 * lwsl_emit_stderr() - helper log emit function writes to stderr
758
 *
759
 * \param level: one of LLL_ log level indexes
760
 * \param line: log string
761
 *
762
 * You use this by passing the function pointer to lws_set_log_level(), to set
763
 * it as the log emit function, it is not called directly.
764
 *
765
 * It prepends a system timestamp like [2018/11/13 07:41:57:3989]
766
 *
767
 * If stderr is a tty, then ansi colour codes are added.
768
 */
769
LWS_VISIBLE LWS_EXTERN void
770
lwsl_emit_stderr(int level, const char *line);
771
772
/**
773
 * lwsl_emit_stderr_notimestamp() - helper log emit function writes to stderr
774
 *
775
 * \param level: one of LLL_ log level indexes
776
 * \param line: log string
777
 *
778
 * You use this by passing the function pointer to lws_set_log_level(), to set
779
 * it as the log emit function, it is not called directly.
780
 *
781
 * If stderr is a tty, then ansi colour codes are added.
782
 */
783
LWS_VISIBLE LWS_EXTERN void
784
lwsl_emit_stderr_notimestamp(int level, const char *line);
785
786
/**
787
 * lwsl_visible() - returns true if the log level should be printed
788
 *
789
 * \param level: one of LLL_ log level indexes
790
 *
791
 * This is useful if you have to do work to generate the log content, you
792
 * can skip the work if the log level used to print it is not actually
793
 * enabled at runtime.
794
 */
795
LWS_VISIBLE LWS_EXTERN int
796
lwsl_visible(int level);
797
798
struct lws;
799
800
LWS_VISIBLE LWS_EXTERN const char *
801
lws_wsi_tag(struct lws *wsi);
802
803
LWS_VISIBLE LWS_EXTERN void
804
lwsl_refcount_cx(lws_log_cx_t *cx, int _new);
805
806
///@}