libwebsockets
Lightweight C library for HTML5 websockets
lws-logs.h
Go to the documentation of this file.
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 #define LLL_ERR (1 << 0)
41 #define LLL_WARN (1 << 1)
42 #define LLL_NOTICE (1 << 2)
43 #define LLL_INFO (1 << 3)
44 #define LLL_DEBUG (1 << 4)
45 #define LLL_PARSER (1 << 5)
46 #define LLL_HEADER (1 << 6)
47 #define LLL_EXT (1 << 7)
48 #define LLL_CLIENT (1 << 8)
49 #define LLL_LATENCY (1 << 9)
50 #define LLL_USER (1 << 10)
51 #define LLL_THREAD (1 << 11)
52 
53 #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 #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  lws_log_emit_t emit; /* legacy emit function */
83  lws_log_emit_cx_t emit_cx; /* LLLF_LOG_CONTEXT_AWARE */
84  } u;
85 
86 #if LWS_MAX_SMP > 1
88 #endif
89 
91  /**< NULL, or a function called after each change to .refcount below,
92  * this enables implementing side-effects like opening and closing
93  * log files when the first and last object binds / unbinds */
95  /**< NULL, or a cb to optionally prepend a string to logs we are a
96  * parent of */
97  struct lws_log_cx *parent;
98  /**< NULL, or points to log ctx we are a child of */
99  void *opaque;
100  /**< ignored by lws, used to pass config to emit_cx, eg, filepath */
101  void *stg;
102  /**< ignored by lws, may be used a storage by refcount_cb / emit_cx */
104  /**< mask of log levels we want to emit in this context */
106  /**< refcount of objects bound to this log context */
107 #if LWS_MAX_SMP > 1
108  char inited;
109 #endif
110 } lws_log_cx_t;
111 
112 /**
113  * lwsl_timestamp: generate logging timestamp string
114  *
115  * \param level: logging level
116  * \param p: char * buffer to take timestamp
117  * \param len: length of p
118  *
119  * returns length written in p
120  */
121 LWS_VISIBLE LWS_EXTERN int
122 lwsl_timestamp(int level, char *p, size_t len);
123 
124 #if defined(LWS_PLAT_OPTEE) && !defined(LWS_WITH_NETWORK)
125 #define _lws_log(aaa, ...) SMSG(__VA_ARGS__)
126 #else
127 LWS_VISIBLE LWS_EXTERN void
128 _lws_log(int filter, const char *format, ...) LWS_FORMAT(2);
129 LWS_VISIBLE LWS_EXTERN void
130 _lws_logv(int filter, const char *format, va_list vl);
131 #endif
132 
133 struct lws_vhost;
134 struct lws;
135 
136 LWS_VISIBLE LWS_EXTERN struct lws_log_cx *
137 lwsl_context_get_cx(struct lws_context *cx);
138 LWS_VISIBLE LWS_EXTERN struct lws_log_cx *
139 lwsl_vhost_get_cx(struct lws_vhost *vh);
140 LWS_VISIBLE LWS_EXTERN struct lws_log_cx *
141 lwsl_wsi_get_cx(struct lws *wsi);
142 #if defined(LWS_WITH_SECURE_STREAMS)
143 struct lws_ss_handle;
144 LWS_VISIBLE LWS_EXTERN struct lws_log_cx *
145 lwsl_ss_get_cx(struct lws_ss_handle *ss);
146 #endif
147 #if defined(LWS_WITH_SECURE_STREAMS_PROXY_API)
148 struct lws_sspc_handle;
149 LWS_VISIBLE LWS_EXTERN struct lws_log_cx *
150 lwsl_sspc_get_cx(struct lws_sspc_handle *ss);
151 #endif
152 
153 
154 LWS_VISIBLE LWS_EXTERN void
155 lws_log_emit_cx_file(struct lws_log_cx *cx, int level, const char *line,
156  size_t len);
157 
158 LWS_VISIBLE LWS_EXTERN void
159 lws_log_use_cx_file(struct lws_log_cx *cx, int _new);
160 
161 LWS_VISIBLE LWS_EXTERN void
162 lws_log_prepend_context(struct lws_log_cx *cx, void *obj, char **p, char *e);
163 LWS_VISIBLE LWS_EXTERN void
164 lws_log_prepend_vhost(struct lws_log_cx *cx, void *obj, char **p, char *e);
165 LWS_VISIBLE LWS_EXTERN void
166 lws_log_prepend_wsi(struct lws_log_cx *cx, void *obj, char **p, char *e);
167 #if defined(LWS_WITH_SECURE_STREAMS)
168 LWS_VISIBLE LWS_EXTERN void
169 lws_log_prepend_ss(struct lws_log_cx *cx, void *obj, char **p, char *e);
170 #endif
171 #if defined(LWS_WITH_SECURE_STREAMS_PROXY_API)
172 LWS_VISIBLE LWS_EXTERN void
173 lws_log_prepend_sspc(struct lws_log_cx *cx, void *obj, char **p, char *e);
174 #endif
175 
176 LWS_VISIBLE LWS_EXTERN void
177 _lws_log_cx(lws_log_cx_t *cx, lws_log_prepend_cx_t prep, void *obj,
178  int filter, const char *_fun, const char *format, ...) LWS_FORMAT(6);
179 
180 #define lwsl_cx(_c, _fil, ...)
181  _lws_log_cx(lwsl_context_get_cx(_c), lws_log_prepend_context,
182  _c, _fil, __func__, __VA_ARGS__)
183 #define lwsl_vhost(_v, _fil, ...)
184  _lws_log_cx(lwsl_vhost_get_cx(_v), lws_log_prepend_vhost, _v,
185  _fil, __func__, __VA_ARGS__)
186 #define lwsl_wsi(_w, _fil, ...)
187  _lws_log_cx(lwsl_wsi_get_cx(_w), lws_log_prepend_wsi, _w,
188  _fil, __func__, __VA_ARGS__)
189 #define lwsl_ss(_h, _fil, ...)
190  _lws_log_cx(lwsl_ss_get_cx(_h), lws_log_prepend_ss, _h,
191  _fil, __func__, __VA_ARGS__)
192 
193 #define lwsl_hexdump_context(_c, _fil, _buf, _len)
194  lwsl_hexdump_level_cx(lwsl_context_get_cx(_c),
195  lws_log_prepend_context,
196  _c, _fil, _buf, _len)
197 #define lwsl_hexdump_vhost(_v, _fil, _buf, _len)
198  lwsl_hexdump_level_cx(lwsl_vhost_get_cx(_v),
199  lws_log_prepend_vhost,
200  _v, _fil, _buf, _len)
201 #define lwsl_hexdump_wsi(_w, _fil, _buf, _len)
202  lwsl_hexdump_level_cx(lwsl_wsi_get_cx(_w),
203  lws_log_prepend_wsi,
204  _w, _fil, _buf, _len)
205 #define lwsl_hexdump_ss(_h, _fil, _buf, _len)
206  lwsl_hexdump_level_cx(lwsl_ss_get_cx(_h),
207  lws_log_prepend_ss,
208  _h, _fil, _buf, _len)
209 
210 /*
211  * Figure out which logs to build in or not
212  */
213 
214 #if defined(_DEBUG)
215  /*
216  * In DEBUG build, select all logs unless NO_LOGS
217  */
218  #if defined(LWS_WITH_NO_LOGS)
219  #define _LWS_LINIT (LLL_ERR | LLL_USER)
220  #else
221  #define _LWS_LINIT ((1 << LLL_COUNT) - 1)
222  #endif
223 #else /* not _DEBUG */
224 #if defined(LWS_WITH_NO_LOGS)
225 #define _LWS_LINIT (LLL_ERR | LLL_USER)
226 #else
227  #define _LWS_LINIT (LLL_ERR | LLL_USER | LLL_WARN | LLL_NOTICE)
228 #endif
229 #endif /* _DEBUG */
230 
231 /*
232  * Create either empty overrides or the ones forced at build-time.
233  * These overrides have the final say... any bits set in
234  * LWS_LOGGING_BITFIELD_SET force the build of those logs, any bits
235  * set in LWS_LOGGING_BITFIELD_CLEAR disable the build of those logs.
236  *
237  * If not defined lws decides based on CMAKE_BUILD_TYPE=DEBUG or not
238  */
239 
240 #if defined(LWS_LOGGING_BITFIELD_SET)
241  #define _LWS_LBS (LWS_LOGGING_BITFIELD_SET)
242 #else
243  #define _LWS_LBS 0
244 #endif
245 
246 #if defined(LWS_LOGGING_BITFIELD_CLEAR)
247  #define _LWS_LBC (LWS_LOGGING_BITFIELD_CLEAR)
248 #else
249  #define _LWS_LBC 0
250 #endif
251 
252 /*
253  * Compute the final active logging bitfield for build
254  */
255 #define _LWS_ENABLED_LOGS (((_LWS_LINIT) | (_LWS_LBS)) & ~(_LWS_LBC))
256 
257 /*
258  * Individually enable or disable log levels for build
259  * depending on what was computed
260  */
261 
262 /*
263  * Process scope logs
264  */
265 
267 #define lwsl_err(...) _lws_log(LLL_ERR, __VA_ARGS__)
268 #else
269 #define lwsl_err(...) do {} while(0)
270 #endif
271 
273 #define lwsl_warn(...) _lws_log(LLL_WARN, __VA_ARGS__)
274 #else
275 #define lwsl_warn(...) do {} while(0)
276 #endif
277 
279 #define lwsl_notice(...) _lws_log(LLL_NOTICE, __VA_ARGS__)
280 #else
281 #define lwsl_notice(...) do {} while(0)
282 #endif
283 
285 #define lwsl_info(...) _lws_log(LLL_INFO, __VA_ARGS__)
286 #else
287 #define lwsl_info(...) do {} while(0)
288 #endif
289 
291 #define lwsl_debug(...) _lws_log(LLL_DEBUG, __VA_ARGS__)
292 #else
293 #define lwsl_debug(...) do {} while(0)
294 #endif
295 
297 #define lwsl_parser(...) _lws_log(LLL_PARSER, __VA_ARGS__)
298 #else
299 #define lwsl_parser(...) do {} while(0)
300 #endif
301 
303 #define lwsl_header(...) _lws_log(LLL_HEADER, __VA_ARGS__)
304 #else
305 #define lwsl_header(...) do {} while(0)
306 #endif
307 
309 #define lwsl_ext(...) _lws_log(LLL_EXT, __VA_ARGS__)
310 #else
311 #define lwsl_ext(...) do {} while(0)
312 #endif
313 
315 #define lwsl_client(...) _lws_log(LLL_CLIENT, __VA_ARGS__)
316 #else
317 #define lwsl_client(...) do {} while(0)
318 #endif
319 
321 #define lwsl_latency(...) _lws_log(LLL_LATENCY, __VA_ARGS__)
322 #else
323 #define lwsl_latency(...) do {} while(0)
324 #endif
325 
327 #define lwsl_thread(...) _lws_log(LLL_THREAD, __VA_ARGS__)
328 #else
329 #define lwsl_thread(...) do {} while(0)
330 #endif
331 
333 #define lwsl_user(...) _lws_log(LLL_USER, __VA_ARGS__)
334 #else
335 #define lwsl_user(...) do {} while(0)
336 #endif
337 
338 #define lwsl_hexdump_err(...) lwsl_hexdump_level(LLL_ERR, __VA_ARGS__)
339 #define lwsl_hexdump_warn(...) lwsl_hexdump_level(LLL_WARN, __VA_ARGS__)
340 #define lwsl_hexdump_notice(...) lwsl_hexdump_level(LLL_NOTICE, __VA_ARGS__)
341 #define lwsl_hexdump_info(...) lwsl_hexdump_level(LLL_INFO, __VA_ARGS__)
342 #define lwsl_hexdump_debug(...) lwsl_hexdump_level(LLL_DEBUG, __VA_ARGS__)
343 
344 /*
345  * lws_context scope logs
346  */
347 
349 #define lwsl_cx_err(_c, ...) lwsl_cx(_c, LLL_ERR, __VA_ARGS__)
350 #else
351 #define lwsl_cx_err(_c, ...) do {} while(0)
352 #endif
353 
355 #define lwsl_cx_warn(_c, ...) lwsl_cx(_c, LLL_WARN, __VA_ARGS__)
356 #else
357 #define lwsl_cx_warn(_c, ...) do {} while(0)
358 #endif
359 
361 #define lwsl_cx_notice(_c, ...) lwsl_cx(_c, LLL_NOTICE, __VA_ARGS__)
362 #else
363 #define lwsl_cx_notice(_c, ...) do {} while(0)
364 #endif
365 
367 #define lwsl_cx_info(_c, ...) lwsl_cx(_c, LLL_INFO, __VA_ARGS__)
368 #else
369 #define lwsl_cx_info(_c, ...) do {} while(0)
370 #endif
371 
373 #define lwsl_cx_debug(_c, ...) lwsl_cx(_c, LLL_DEBUG, __VA_ARGS__)
374 #else
375 #define lwsl_cx_debug(_c, ...) do {} while(0)
376 #endif
377 
379 #define lwsl_cx_parser(_c, ...) lwsl_cx(_c, LLL_PARSER, __VA_ARGS__)
380 #else
381 #define lwsl_cx_parser(_c, ...) do {} while(0)
382 #endif
383 
385 #define lwsl_cx_header(_c, ...) lwsl_cx(_c, LLL_HEADER, __VA_ARGS__)
386 #else
387 #define lwsl_cx_header(_c, ...) do {} while(0)
388 #endif
389 
391 #define lwsl_cx_ext(_c, ...) lwsl_cx(_c, LLL_EXT, __VA_ARGS__)
392 #else
393 #define lwsl_cx_ext(_c, ...) do {} while(0)
394 #endif
395 
397 #define lwsl_cx_client(_c, ...) lwsl_cx(_c, LLL_CLIENT, __VA_ARGS__)
398 #else
399 #define lwsl_cx_client(_c, ...) do {} while(0)
400 #endif
401 
403 #define lwsl_cx_latency(_c, ...) lwsl_cx(_c, LLL_LATENCY, __VA_ARGS__)
404 #else
405 #define lwsl_cx_latency(_c, ...) do {} while(0)
406 #endif
407 
409 #define lwsl_cx_thread(_c, ...) lwsl_cx(_c, LLL_THREAD, __VA_ARGS__)
410 #else
411 #define lwsl_cx_thread(_c, ...) do {} while(0)
412 #endif
413 
415 #define lwsl_cx_user(_c, ...) lwsl_cx(_c, LLL_USER, __VA_ARGS__)
416 #else
417 #define lwsl_cx_user(_c, ...) do {} while(0)
418 #endif
419 
420 #define lwsl_hexdump_cx_err(_c, ...) lwsl_hexdump_context(_c, LLL_ERR, __VA_ARGS__)
421 #define lwsl_hexdump_cx_warn(_c, ...) lwsl_hexdump_context(_c, LLL_WARN, __VA_ARGS__)
422 #define lwsl_hexdump_cx_notice(_c, ...) lwsl_hexdump_context(_c, LLL_NOTICE, __VA_ARGS__)
423 #define lwsl_hexdump_cx_info(_c, ...) lwsl_hexdump_context(_c, LLL_INFO, __VA_ARGS__)
424 #define lwsl_hexdump_cx_debug(_c, ...) lwsl_hexdump_context(_c, LLL_DEBUG, __VA_ARGS__)
425 
426 /*
427  * lws_vhost
428  */
429 
431 #define lwsl_vhost_err(_v, ...) lwsl_vhost(_v, LLL_ERR, __VA_ARGS__)
432 #else
433 #define lwsl_vhost_err(_v, ...) do {} while(0)
434 #endif
435 
437 #define lwsl_vhost_warn(_v, ...) lwsl_vhost(_v, LLL_WARN, __VA_ARGS__)
438 #else
439 #define lwsl_vhost_warn(_v, ...) do {} while(0)
440 #endif
441 
443 #define lwsl_vhost_notice(_v, ...) lwsl_vhost(_v, LLL_NOTICE, __VA_ARGS__)
444 #else
445 #define lwsl_vhost_notice(_v, ...) do {} while(0)
446 #endif
447 
449 #define lwsl_vhost_info(_v, ...) lwsl_vhost(_v, LLL_INFO, __VA_ARGS__)
450 #else
451 #define lwsl_vhost_info(_v, ...) do {} while(0)
452 #endif
453 
455 #define lwsl_vhost_debug(_v, ...) lwsl_vhost(_v, LLL_DEBUG, __VA_ARGS__)
456 #else
457 #define lwsl_vhost_debug(_v, ...) do {} while(0)
458 #endif
459 
461 #define lwsl_vhost_parser(_v, ...) lwsl_vhost(_v, LLL_PARSER, __VA_ARGS__)
462 #else
463 #define lwsl_vhost_parser(_v, ...) do {} while(0)
464 #endif
465 
467 #define lwsl_vhost_header(_v, ...) lwsl_vhost(_v, LLL_HEADER, __VA_ARGS__)
468 #else
469 #define lwsl_vhost_header(_v, ...) do {} while(0)
470 #endif
471 
473 #define lwsl_vhost_ext(_v, ...) lwsl_vhost(_v, LLL_EXT, __VA_ARGS__)
474 #else
475 #define lwsl_vhost_ext(_v, ...) do {} while(0)
476 #endif
477 
479 #define lwsl_vhost_client(_v, ...) lwsl_vhost(_v, LLL_CLIENT, __VA_ARGS__)
480 #else
481 #define lwsl_vhost_client(_v, ...) do {} while(0)
482 #endif
483 
485 #define lwsl_vhost_latency(_v, ...) lwsl_vhost(_v, LLL_LATENCY, __VA_ARGS__)
486 #else
487 #define lwsl_vhost_latency(_v, ...) do {} while(0)
488 #endif
489 
491 #define lwsl_vhost_thread(_v, ...) lwsl_vhost(_v, LLL_THREAD, __VA_ARGS__)
492 #else
493 #define lwsl_vhost_thread(_v, ...) do {} while(0)
494 #endif
495 
497 #define lwsl_vhost_user(_v, ...) lwsl_vhost(_v, LLL_USER, __VA_ARGS__)
498 #else
499 #define lwsl_vhost_user(_v, ...) do {} while(0)
500 #endif
501 
502 #define lwsl_hexdump_vhost_err(_v, ...) lwsl_hexdump_vhost(_v, LLL_ERR, __VA_ARGS__)
503 #define lwsl_hexdump_vhost_warn(_v, ...) lwsl_hexdump_vhost(_v, LLL_WARN, __VA_ARGS__)
504 #define lwsl_hexdump_vhost_notice(_v, ...) lwsl_hexdump_vhost(_v, LLL_NOTICE, __VA_ARGS__)
505 #define lwsl_hexdump_vhost_info(_v, ...) lwsl_hexdump_vhost(_v, LLL_INFO, __VA_ARGS__)
506 #define lwsl_hexdump_vhost_debug(_v, ...) lwsl_hexdump_vhost(_v, LLL_DEBUG, __VA_ARGS__)
507 
508 
509 /*
510  * lws_wsi
511  */
512 
514 #define lwsl_wsi_err(_w, ...) lwsl_wsi(_w, LLL_ERR, __VA_ARGS__)
515 #else
516 #define lwsl_wsi_err(_w, ...) do {} while(0)
517 #endif
518 
520 #define lwsl_wsi_warn(_w, ...) lwsl_wsi(_w, LLL_WARN, __VA_ARGS__)
521 #else
522 #define lwsl_wsi_warn(_w, ...) do {} while(0)
523 #endif
524 
526 #define lwsl_wsi_notice(_w, ...) lwsl_wsi(_w, LLL_NOTICE, __VA_ARGS__)
527 #else
528 #define lwsl_wsi_notice(_w, ...) do {} while(0)
529 #endif
530 
532 #define lwsl_wsi_info(_w, ...) lwsl_wsi(_w, LLL_INFO, __VA_ARGS__)
533 #else
534 #define lwsl_wsi_info(_w, ...) do {} while(0)
535 #endif
536 
538 #define lwsl_wsi_debug(_w, ...) lwsl_wsi(_w, LLL_DEBUG, __VA_ARGS__)
539 #else
540 #define lwsl_wsi_debug(_w, ...) do {} while(0)
541 #endif
542 
544 #define lwsl_wsi_parser(_w, ...) lwsl_wsi(_w, LLL_PARSER, __VA_ARGS__)
545 #else
546 #define lwsl_wsi_parser(_w, ...) do {} while(0)
547 #endif
548 
550 #define lwsl_wsi_header(_w, ...) lwsl_wsi(_w, LLL_HEADER, __VA_ARGS__)
551 #else
552 #define lwsl_wsi_header(_w, ...) do {} while(0)
553 #endif
554 
556 #define lwsl_wsi_ext(_w, ...) lwsl_wsi(_w, LLL_EXT, __VA_ARGS__)
557 #else
558 #define lwsl_wsi_ext(_w, ...) do {} while(0)
559 #endif
560 
562 #define lwsl_wsi_client(_w, ...) lwsl_wsi(_w, LLL_CLIENT, __VA_ARGS__)
563 #else
564 #define lwsl_wsi_client(_w, ...) do {} while(0)
565 #endif
566 
568 #define lwsl_wsi_latency(_w, ...) lwsl_wsi(_w, LLL_LATENCY, __VA_ARGS__)
569 #else
570 #define lwsl_wsi_latency(_w, ...) do {} while(0)
571 #endif
572 
574 #define lwsl_wsi_thread(_w, ...) lwsl_wsi(_w, LLL_THREAD, __VA_ARGS__)
575 #else
576 #define lwsl_wsi_thread(_w, ...) do {} while(0)
577 #endif
578 
580 #define lwsl_wsi_user(_w, ...) lwsl_wsi(_w, LLL_USER, __VA_ARGS__)
581 #else
582 #define lwsl_wsi_user(_w, ...) do {} while(0)
583 #endif
584 
585 #define lwsl_hexdump_wsi_err(_v, ...) lwsl_hexdump_wsi(_v, LLL_ERR, __VA_ARGS__)
586 #define lwsl_hexdump_wsi_warn(_v, ...) lwsl_hexdump_wsi(_v, LLL_WARN, __VA_ARGS__)
587 #define lwsl_hexdump_wsi_notice(_v, ...) lwsl_hexdump_wsi(_v, LLL_NOTICE, __VA_ARGS__)
588 #define lwsl_hexdump_wsi_info(_v, ...) lwsl_hexdump_wsi(_v, LLL_INFO, __VA_ARGS__)
589 #define lwsl_hexdump_wsi_debug(_v, ...) lwsl_hexdump_wsi(_v, LLL_DEBUG, __VA_ARGS__)
590 
591 
592 /*
593  * lwsl_ss
594  */
595 
597 #define lwsl_ss_err(_w, ...) lwsl_ss(_w, LLL_ERR, __VA_ARGS__)
598 #else
599 #define lwsl_ss_err(_w, ...) do {} while(0)
600 #endif
601 
603 #define lwsl_ss_warn(_w, ...) lwsl_ss(_w, LLL_WARN, __VA_ARGS__)
604 #else
605 #define lwsl_ss_warn(_w, ...) do {} while(0)
606 #endif
607 
609 #define lwsl_ss_notice(_w, ...) lwsl_ss(_w, LLL_NOTICE, __VA_ARGS__)
610 #else
611 #define lwsl_ss_notice(_w, ...) do {} while(0)
612 #endif
613 
615 #define lwsl_ss_info(_w, ...) lwsl_ss(_w, LLL_INFO, __VA_ARGS__)
616 #else
617 #define lwsl_ss_info(_w, ...) do {} while(0)
618 #endif
619 
621 #define lwsl_ss_debug(_w, ...) lwsl_ss(_w, LLL_DEBUG, __VA_ARGS__)
622 #else
623 #define lwsl_ss_debug(_w, ...) do {} while(0)
624 #endif
625 
627 #define lwsl_ss_parser(_w, ...) lwsl_ss(_w, LLL_PARSER, __VA_ARGS__)
628 #else
629 #define lwsl_ss_parser(_w, ...) do {} while(0)
630 #endif
631 
633 #define lwsl_ss_header(_w, ...) lwsl_ss(_w, LLL_HEADER, __VA_ARGS__)
634 #else
635 #define lwsl_ss_header(_w, ...) do {} while(0)
636 #endif
637 
639 #define lwsl_ss_ext(_w, ...) lwsl_ss(_w, LLL_EXT, __VA_ARGS__)
640 #else
641 #define lwsl_ss_ext(_w, ...) do {} while(0)
642 #endif
643 
645 #define lwsl_ss_client(_w, ...) lwsl_ss(_w, LLL_CLIENT, __VA_ARGS__)
646 #else
647 #define lwsl_ss_client(_w, ...) do {} while(0)
648 #endif
649 
651 #define lwsl_ss_latency(_w, ...) lwsl_ss(_w, LLL_LATENCY, __VA_ARGS__)
652 #else
653 #define lwsl_ss_latency(_w, ...) do {} while(0)
654 #endif
655 
657 #define lwsl_ss_thread(_w, ...) lwsl_ss(_w, LLL_THREAD, __VA_ARGS__)
658 #else
659 #define lwsl_ss_thread(_w, ...) do {} while(0)
660 #endif
661 
663 #define lwsl_ss_user(_w, ...) lwsl_ss(_w, LLL_USER, __VA_ARGS__)
664 #else
665 #define lwsl_ss_user(_w, ...) do {} while(0)
666 #endif
667 
668 #define lwsl_hexdump_ss_err(_v, ...) lwsl_hexdump_ss(_v, LLL_ERR, __VA_ARGS__)
669 #define lwsl_hexdump_ss_warn(_v, ...) lwsl_hexdump_ss(_v, LLL_WARN, __VA_ARGS__)
670 #define lwsl_hexdump_ss_notice(_v, ...) lwsl_hexdump_ss(_v, LLL_NOTICE, __VA_ARGS__)
671 #define lwsl_hexdump_ss_info(_v, ...) lwsl_hexdump_ss(_v, LLL_INFO, __VA_ARGS__)
672 #define lwsl_hexdump_ss_debug(_v, ...) lwsl_hexdump_ss(_v, LLL_DEBUG, __VA_ARGS__)
673 
674 
675 
676 /**
677  * lwsl_hexdump_level() - helper to hexdump a buffer at a selected debug level
678  *
679  * \param level: one of LLL_ constants
680  * \param vbuf: buffer start to dump
681  * \param len: length of buffer to dump
682  *
683  * If \p level is visible, does a nice hexdump -C style dump of \p vbuf for
684  * \p len bytes. This can be extremely convenient while debugging.
685  */
686 LWS_VISIBLE LWS_EXTERN void
687 lwsl_hexdump_level(int level, const void *vbuf, size_t len);
688 
689 LWS_VISIBLE LWS_EXTERN void
690 lwsl_hexdump_level_cx(lws_log_cx_t *cx, lws_log_prepend_cx_t prep, void *obj,
691  int hexdump_level, const void *vbuf, size_t len);
692 
693 /**
694  * lwsl_hexdump() - helper to hexdump a buffer (DEBUG builds only)
695  *
696  * \param buf: buffer start to dump
697  * \param len: length of buffer to dump
698  *
699  * Calls through to lwsl_hexdump_level(LLL_DEBUG, ... for compatability.
700  * It's better to use lwsl_hexdump_level(level, ... directly so you can control
701  * the visibility.
702  */
703 LWS_VISIBLE LWS_EXTERN void
704 lwsl_hexdump(const void *buf, size_t len);
705 
706 /**
707  * lws_is_be() - returns nonzero if the platform is Big Endian
708  */
709 static LWS_INLINE int lws_is_be(void) {
710  const int probe = ~0xff;
711 
712  return *(const char *)&probe;
713 }
714 
715 /**
716  * lws_set_log_level() - Set the logging bitfield
717  * \param level: OR together the LLL_ debug contexts you want output from
718  * \param log_emit_function: NULL to leave it as it is, or a user-supplied
719  * function to perform log string emission instead of
720  * the default stderr one.
721  *
722  * log level defaults to "err", "warn" and "notice" contexts enabled and
723  * emission on stderr. If stderr is a tty (according to isatty()) then
724  * the output is coloured according to the log level using ANSI escapes.
725  *
726  * You can set the default security level for logging using the
727  * secrecy_and_log_level() macro to set the \p level parameter, eg
728  *
729  * lws_set_log_level(secrecy_and_log_level(LWS_SECRECY_PII, LLL_ERR | LLL_WARN),
730  * my_emit_function);
731  *
732  * Normally you can just leave it at the default.
733  */
734 LWS_VISIBLE LWS_EXTERN void
735 lws_set_log_level(int level, lws_log_emit_t log_emit_function);
736 
737 /**
738  * lwsl_emit_syslog() - helper log emit function writes to system log
739  *
740  * \param level: one of LLL_ log level indexes
741  * \param line: log string
742  *
743  * You use this by passing the function pointer to lws_set_log_level(), to set
744  * it as the log emit function, it is not called directly.
745  */
746 LWS_VISIBLE LWS_EXTERN void
747 lwsl_emit_syslog(int level, const char *line);
748 
749 /**
750  * lwsl_emit_stderr() - helper log emit function writes to stderr
751  *
752  * \param level: one of LLL_ log level indexes
753  * \param line: log string
754  *
755  * You use this by passing the function pointer to lws_set_log_level(), to set
756  * it as the log emit function, it is not called directly.
757  *
758  * It prepends a system timestamp like [2018/11/13 07:41:57:3989]
759  *
760  * If stderr is a tty, then ansi colour codes are added.
761  */
762 LWS_VISIBLE LWS_EXTERN void
763 lwsl_emit_stderr(int level, const char *line);
764 
765 /**
766  * lwsl_emit_stderr_notimestamp() - helper log emit function writes to stderr
767  *
768  * \param level: one of LLL_ log level indexes
769  * \param line: log string
770  *
771  * You use this by passing the function pointer to lws_set_log_level(), to set
772  * it as the log emit function, it is not called directly.
773  *
774  * If stderr is a tty, then ansi colour codes are added.
775  */
776 LWS_VISIBLE LWS_EXTERN void
777 lwsl_emit_stderr_notimestamp(int level, const char *line);
778 
779 /**
780  * lwsl_visible() - returns true if the log level should be printed
781  *
782  * \param level: one of LLL_ log level indexes
783  *
784  * This is useful if you have to do work to generate the log content, you
785  * can skip the work if the log level used to print it is not actually
786  * enabled at runtime.
787  */
788 LWS_VISIBLE LWS_EXTERN int
789 lwsl_visible(int level);
790 
791 struct lws;
792 
793 LWS_VISIBLE LWS_EXTERN const char *
794 lws_wsi_tag(struct lws *wsi);
795 
796 LWS_VISIBLE LWS_EXTERN void
797 lwsl_refcount_cx(lws_log_cx_t *cx, int _new);
798 
799 ///@}