libwebsockets
Lightweight C library for HTML5 websockets
|
Data Structures | |
struct | lws_log_cx |
Macros | |
#define | LLL_ERR (1 << 0) |
#define | LLL_WARN (1 << 1) |
#define | LLL_NOTICE (1 << 2) |
#define | LLL_INFO (1 << 3) |
#define | LLL_DEBUG (1 << 4) |
#define | LLL_PARSER (1 << 5) |
#define | LLL_HEADER (1 << 6) |
#define | LLL_EXT (1 << 7) |
#define | LLL_CLIENT (1 << 8) |
#define | LLL_LATENCY (1 << 9) |
#define | LLL_USER (1 << 10) |
#define | LLL_THREAD (1 << 11) |
#define | LLL_COUNT (12) /* set to count of valid flags */ |
#define | LLLF_SECRECY_PII (1 << 16) |
#define | LLLF_SECRECY_BEARER (1 << 17) |
#define | LLLF_LOG_TIMESTAMP (1 << 18) |
#define | LLLF_LOG_CONTEXT_AWARE (1 << 30) |
#define | lwsl_cx(_c, _fil, ...) |
#define | lwsl_vhost(_v, _fil, ...) |
#define | lwsl_wsi(_w, _fil, ...) |
#define | lwsl_ss(_h, _fil, ...) |
#define | lwsl_hexdump_context(_c, _fil, _buf, _len) |
#define | lwsl_hexdump_vhost(_v, _fil, _buf, _len) |
#define | lwsl_hexdump_wsi(_w, _fil, _buf, _len) |
#define | lwsl_hexdump_ss(_h, _fil, _buf, _len) |
#define | _LWS_LINIT (LLL_ERR | LLL_USER | LLL_WARN | LLL_NOTICE) |
#define | _LWS_LBS 0 |
#define | _LWS_LBC 0 |
#define | _LWS_ENABLED_LOGS (((_LWS_LINIT) | (_LWS_LBS)) & ~(_LWS_LBC)) |
#define | lwsl_err(...) _lws_log(LLL_ERR, __VA_ARGS__) |
#define | lwsl_warn(...) _lws_log(LLL_WARN, __VA_ARGS__) |
#define | lwsl_notice(...) _lws_log(LLL_NOTICE, __VA_ARGS__) |
#define | lwsl_info(...) do {} while(0) |
#define | lwsl_debug(...) do {} while(0) |
#define | lwsl_parser(...) do {} while(0) |
#define | lwsl_header(...) do {} while(0) |
#define | lwsl_ext(...) do {} while(0) |
#define | lwsl_client(...) do {} while(0) |
#define | lwsl_latency(...) do {} while(0) |
#define | lwsl_thread(...) do {} while(0) |
#define | lwsl_user(...) _lws_log(LLL_USER, __VA_ARGS__) |
#define | lwsl_hexdump_err(...) lwsl_hexdump_level(LLL_ERR, __VA_ARGS__) |
#define | lwsl_hexdump_warn(...) lwsl_hexdump_level(LLL_WARN, __VA_ARGS__) |
#define | lwsl_hexdump_notice(...) lwsl_hexdump_level(LLL_NOTICE, __VA_ARGS__) |
#define | lwsl_hexdump_info(...) lwsl_hexdump_level(LLL_INFO, __VA_ARGS__) |
#define | lwsl_hexdump_debug(...) lwsl_hexdump_level(LLL_DEBUG, __VA_ARGS__) |
#define | lwsl_cx_err(_c, ...) lwsl_cx(_c, LLL_ERR, __VA_ARGS__) |
#define | lwsl_cx_warn(_c, ...) lwsl_cx(_c, LLL_WARN, __VA_ARGS__) |
#define | lwsl_cx_notice(_c, ...) lwsl_cx(_c, LLL_NOTICE, __VA_ARGS__) |
#define | lwsl_cx_info(_c, ...) do {} while(0) |
#define | lwsl_cx_debug(_c, ...) do {} while(0) |
#define | lwsl_cx_parser(_c, ...) do {} while(0) |
#define | lwsl_cx_header(_c, ...) do {} while(0) |
#define | lwsl_cx_ext(_c, ...) do {} while(0) |
#define | lwsl_cx_client(_c, ...) do {} while(0) |
#define | lwsl_cx_latency(_c, ...) do {} while(0) |
#define | lwsl_cx_thread(_c, ...) do {} while(0) |
#define | lwsl_cx_user(_c, ...) lwsl_cx(_c, LLL_USER, __VA_ARGS__) |
#define | lwsl_hexdump_cx_err(_c, ...) lwsl_hexdump_context(_c, LLL_ERR, __VA_ARGS__) |
#define | lwsl_hexdump_cx_warn(_c, ...) lwsl_hexdump_context(_c, LLL_WARN, __VA_ARGS__) |
#define | lwsl_hexdump_cx_notice(_c, ...) lwsl_hexdump_context(_c, LLL_NOTICE, __VA_ARGS__) |
#define | lwsl_hexdump_cx_info(_c, ...) lwsl_hexdump_context(_c, LLL_INFO, __VA_ARGS__) |
#define | lwsl_hexdump_cx_debug(_c, ...) lwsl_hexdump_context(_c, LLL_DEBUG, __VA_ARGS__) |
#define | lwsl_vhost_err(_v, ...) lwsl_vhost(_v, LLL_ERR, __VA_ARGS__) |
#define | lwsl_vhost_warn(_v, ...) lwsl_vhost(_v, LLL_WARN, __VA_ARGS__) |
#define | lwsl_vhost_notice(_v, ...) lwsl_vhost(_v, LLL_NOTICE, __VA_ARGS__) |
#define | lwsl_vhost_info(_v, ...) do {} while(0) |
#define | lwsl_vhost_debug(_v, ...) do {} while(0) |
#define | lwsl_vhost_parser(_v, ...) do {} while(0) |
#define | lwsl_vhost_header(_v, ...) do {} while(0) |
#define | lwsl_vhost_ext(_v, ...) do {} while(0) |
#define | lwsl_vhost_client(_v, ...) do {} while(0) |
#define | lwsl_vhost_latency(_v, ...) do {} while(0) |
#define | lwsl_vhost_thread(_v, ...) do {} while(0) |
#define | lwsl_vhost_user(_v, ...) lwsl_vhost(_v, LLL_USER, __VA_ARGS__) |
#define | lwsl_hexdump_vhost_err(_v, ...) lwsl_hexdump_vhost(_v, LLL_ERR, __VA_ARGS__) |
#define | lwsl_hexdump_vhost_warn(_v, ...) lwsl_hexdump_vhost(_v, LLL_WARN, __VA_ARGS__) |
#define | lwsl_hexdump_vhost_notice(_v, ...) lwsl_hexdump_vhost(_v, LLL_NOTICE, __VA_ARGS__) |
#define | lwsl_hexdump_vhost_info(_v, ...) lwsl_hexdump_vhost(_v, LLL_INFO, __VA_ARGS__) |
#define | lwsl_hexdump_vhost_debug(_v, ...) lwsl_hexdump_vhost(_v, LLL_DEBUG, __VA_ARGS__) |
#define | lwsl_wsi_err(_w, ...) lwsl_wsi(_w, LLL_ERR, __VA_ARGS__) |
#define | lwsl_wsi_warn(_w, ...) lwsl_wsi(_w, LLL_WARN, __VA_ARGS__) |
#define | lwsl_wsi_notice(_w, ...) lwsl_wsi(_w, LLL_NOTICE, __VA_ARGS__) |
#define | lwsl_wsi_info(_w, ...) do {} while(0) |
#define | lwsl_wsi_debug(_w, ...) do {} while(0) |
#define | lwsl_wsi_parser(_w, ...) do {} while(0) |
#define | lwsl_wsi_header(_w, ...) do {} while(0) |
#define | lwsl_wsi_ext(_w, ...) do {} while(0) |
#define | lwsl_wsi_client(_w, ...) do {} while(0) |
#define | lwsl_wsi_latency(_w, ...) do {} while(0) |
#define | lwsl_wsi_thread(_w, ...) do {} while(0) |
#define | lwsl_wsi_user(_w, ...) lwsl_wsi(_w, LLL_USER, __VA_ARGS__) |
#define | lwsl_hexdump_wsi_err(_v, ...) lwsl_hexdump_wsi(_v, LLL_ERR, __VA_ARGS__) |
#define | lwsl_hexdump_wsi_warn(_v, ...) lwsl_hexdump_wsi(_v, LLL_WARN, __VA_ARGS__) |
#define | lwsl_hexdump_wsi_notice(_v, ...) lwsl_hexdump_wsi(_v, LLL_NOTICE, __VA_ARGS__) |
#define | lwsl_hexdump_wsi_info(_v, ...) lwsl_hexdump_wsi(_v, LLL_INFO, __VA_ARGS__) |
#define | lwsl_hexdump_wsi_debug(_v, ...) lwsl_hexdump_wsi(_v, LLL_DEBUG, __VA_ARGS__) |
#define | lwsl_ss_err(_w, ...) lwsl_ss(_w, LLL_ERR, __VA_ARGS__) |
#define | lwsl_ss_warn(_w, ...) lwsl_ss(_w, LLL_WARN, __VA_ARGS__) |
#define | lwsl_ss_notice(_w, ...) lwsl_ss(_w, LLL_NOTICE, __VA_ARGS__) |
#define | lwsl_ss_info(_w, ...) do {} while(0) |
#define | lwsl_ss_debug(_w, ...) do {} while(0) |
#define | lwsl_ss_parser(_w, ...) do {} while(0) |
#define | lwsl_ss_header(_w, ...) do {} while(0) |
#define | lwsl_ss_ext(_w, ...) do {} while(0) |
#define | lwsl_ss_client(_w, ...) do {} while(0) |
#define | lwsl_ss_latency(_w, ...) do {} while(0) |
#define | lwsl_ss_thread(_w, ...) do {} while(0) |
#define | lwsl_ss_user(_w, ...) lwsl_ss(_w, LLL_USER, __VA_ARGS__) |
#define | lwsl_hexdump_ss_err(_v, ...) lwsl_hexdump_ss(_v, LLL_ERR, __VA_ARGS__) |
#define | lwsl_hexdump_ss_warn(_v, ...) lwsl_hexdump_ss(_v, LLL_WARN, __VA_ARGS__) |
#define | lwsl_hexdump_ss_notice(_v, ...) lwsl_hexdump_ss(_v, LLL_NOTICE, __VA_ARGS__) |
#define | lwsl_hexdump_ss_info(_v, ...) lwsl_hexdump_ss(_v, LLL_INFO, __VA_ARGS__) |
#define | lwsl_hexdump_ss_debug(_v, ...) lwsl_hexdump_ss(_v, LLL_DEBUG, __VA_ARGS__) |
Typedefs | |
typedef void(* | lws_log_emit_t) (int level, const char *line) |
typedef void(* | lws_log_emit_cx_t) (struct lws_log_cx *cx, int level, const char *line, size_t len) |
typedef void(* | lws_log_prepend_cx_t) (struct lws_log_cx *cx, void *obj, char **p, char *e) |
typedef void(* | lws_log_use_cx_t) (struct lws_log_cx *cx, int _new) |
typedef struct lws_log_cx | lws_log_cx_t |
Functions | |
LWS_VISIBLE LWS_EXTERN int | lwsl_timestamp (int level, char *p, size_t len) |
LWS_VISIBLE LWS_EXTERN void | _lws_log (int filter, const char *format,...) LWS_FORMAT(2) |
LWS_VISIBLE LWS_EXTERN void | _lws_logv (int filter, const char *format, va_list vl) |
LWS_VISIBLE LWS_EXTERN struct lws_log_cx * | lwsl_context_get_cx (struct lws_context *cx) |
LWS_VISIBLE LWS_EXTERN struct lws_log_cx * | lwsl_vhost_get_cx (struct lws_vhost *vh) |
LWS_VISIBLE LWS_EXTERN struct lws_log_cx * | lwsl_wsi_get_cx (struct lws *wsi) |
LWS_VISIBLE LWS_EXTERN void | lws_log_emit_cx_file (struct lws_log_cx *cx, int level, const char *line, size_t len) |
LWS_VISIBLE LWS_EXTERN void | lws_log_use_cx_file (struct lws_log_cx *cx, int _new) |
LWS_VISIBLE LWS_EXTERN void | lws_log_prepend_context (struct lws_log_cx *cx, void *obj, char **p, char *e) |
LWS_VISIBLE LWS_EXTERN void | lws_log_prepend_vhost (struct lws_log_cx *cx, void *obj, char **p, char *e) |
LWS_VISIBLE LWS_EXTERN void | lws_log_prepend_wsi (struct lws_log_cx *cx, void *obj, char **p, char *e) |
LWS_VISIBLE LWS_EXTERN void | _lws_log_cx (lws_log_cx_t *cx, lws_log_prepend_cx_t prep, void *obj, int filter, const char *_fun, const char *format,...) LWS_FORMAT(6) |
LWS_VISIBLE LWS_EXTERN void | lwsl_hexdump_level (int level, const void *vbuf, size_t len) |
LWS_VISIBLE LWS_EXTERN void | lwsl_hexdump_level_cx (lws_log_cx_t *cx, lws_log_prepend_cx_t prep, void *obj, int hexdump_level, const void *vbuf, size_t len) |
LWS_VISIBLE LWS_EXTERN void | lwsl_hexdump (const void *buf, size_t len) |
LWS_VISIBLE LWS_EXTERN void | lws_set_log_level (int level, lws_log_emit_t log_emit_function) |
LWS_VISIBLE LWS_EXTERN void | lwsl_emit_syslog (int level, const char *line) |
LWS_VISIBLE LWS_EXTERN void | lwsl_emit_stderr (int level, const char *line) |
LWS_VISIBLE LWS_EXTERN void | lwsl_emit_stderr_notimestamp (int level, const char *line) |
LWS_VISIBLE LWS_EXTERN int | lwsl_visible (int level) |
LWS_VISIBLE LWS_EXTERN const char * | lws_wsi_tag (struct lws *wsi) |
LWS_VISIBLE LWS_EXTERN void | lwsl_refcount_cx (lws_log_cx_t *cx, int _new) |
Lws provides flexible and filterable logging facilities, which can be used inside lws and in user code.
Log categories may be individually filtered bitwise, and directed to built-in sinks for syslog-compatible logging, or a user-defined function.
Traditional logs use a single, processwide logging context. New style log apis (lws_xxx_cx()) can pass the logging context to use in.
#define LLLF_LOG_CONTEXT_AWARE (1 << 30) |
#include <include/libwebsockets/lws-logs.h>
set if the context uses an emit function that takes the logctx, auto- applied when setting emit using lws_set_log_level_cx() api
#define LLLF_LOG_TIMESTAMP (1 << 18) |
#include <include/libwebsockets/lws-logs.h>
set to prepend logs with timestamp
#define LLLF_SECRECY_BEARER (1 << 17) |
#include <include/libwebsockets/lws-logs.h>
possession of this data allows impersonation
#define LLLF_SECRECY_PII (1 << 16) |
#include <include/libwebsockets/lws-logs.h>
contains Personally Identifiable Information
#define lwsl_cx | ( | _c, | |
_fil, | |||
... | |||
) |
#include <include/libwebsockets/lws-logs.h>
#define lwsl_hexdump_context | ( | _c, | |
_fil, | |||
_buf, | |||
_len | |||
) |
#include <include/libwebsockets/lws-logs.h>
#define lwsl_hexdump_ss | ( | _h, | |
_fil, | |||
_buf, | |||
_len | |||
) |
#include <include/libwebsockets/lws-logs.h>
#define lwsl_hexdump_vhost | ( | _v, | |
_fil, | |||
_buf, | |||
_len | |||
) |
#include <include/libwebsockets/lws-logs.h>
#define lwsl_hexdump_wsi | ( | _w, | |
_fil, | |||
_buf, | |||
_len | |||
) |
#include <include/libwebsockets/lws-logs.h>
#define lwsl_ss | ( | _h, | |
_fil, | |||
... | |||
) |
#include <include/libwebsockets/lws-logs.h>
#define lwsl_vhost | ( | _v, | |
_fil, | |||
... | |||
) |
#include <include/libwebsockets/lws-logs.h>
#define lwsl_wsi | ( | _w, | |
_fil, | |||
... | |||
) |
#include <include/libwebsockets/lws-logs.h>
LWS_VISIBLE LWS_EXTERN void lws_set_log_level | ( | int | level, |
lws_log_emit_t | log_emit_function | ||
) |
#include <include/libwebsockets/lws-logs.h>
lws_set_log_level() - Set the logging bitfield
level | OR together the LLL_ debug contexts you want output from |
log_emit_function | NULL to leave it as it is, or a user-supplied function to perform log string emission instead of the default stderr one. |
log level defaults to "err", "warn" and "notice" contexts enabled and emission on stderr. If stderr is a tty (according to isatty()) then the output is coloured according to the log level using ANSI escapes.
You can set the default security level for logging using the secrecy_and_log_level() macro to set the level
parameter, eg
lws_set_log_level(secrecy_and_log_level(LWS_SECRECY_PII, LLL_ERR | LLL_WARN), my_emit_function);
Normally you can just leave it at the default.
LWS_VISIBLE LWS_EXTERN void lwsl_emit_stderr | ( | int | level, |
const char * | line | ||
) |
#include <include/libwebsockets/lws-logs.h>
lwsl_emit_stderr() - helper log emit function writes to stderr
level | one of LLL_ log level indexes |
line | log string |
You use this by passing the function pointer to lws_set_log_level(), to set it as the log emit function, it is not called directly.
It prepends a system timestamp like [2018/11/13 07:41:57:3989]
If stderr is a tty, then ansi colour codes are added.
LWS_VISIBLE LWS_EXTERN void lwsl_emit_stderr_notimestamp | ( | int | level, |
const char * | line | ||
) |
#include <include/libwebsockets/lws-logs.h>
lwsl_emit_stderr_notimestamp() - helper log emit function writes to stderr
level | one of LLL_ log level indexes |
line | log string |
You use this by passing the function pointer to lws_set_log_level(), to set it as the log emit function, it is not called directly.
If stderr is a tty, then ansi colour codes are added.
LWS_VISIBLE LWS_EXTERN void lwsl_emit_syslog | ( | int | level, |
const char * | line | ||
) |
#include <include/libwebsockets/lws-logs.h>
lwsl_emit_syslog() - helper log emit function writes to system log
level | one of LLL_ log level indexes |
line | log string |
You use this by passing the function pointer to lws_set_log_level(), to set it as the log emit function, it is not called directly.
LWS_VISIBLE LWS_EXTERN void lwsl_hexdump | ( | const void * | buf, |
size_t | len | ||
) |
#include <include/libwebsockets/lws-logs.h>
lwsl_hexdump() - helper to hexdump a buffer (DEBUG builds only)
buf | buffer start to dump |
len | length of buffer to dump |
Calls through to lwsl_hexdump_level(LLL_DEBUG, ... for compatability. It's better to use lwsl_hexdump_level(level, ... directly so you can control the visibility.
LWS_VISIBLE LWS_EXTERN void lwsl_hexdump_level | ( | int | level, |
const void * | vbuf, | ||
size_t | len | ||
) |
#include <include/libwebsockets/lws-logs.h>
lwsl_hexdump_level() - helper to hexdump a buffer at a selected debug level
level | one of LLL_ constants |
vbuf | buffer start to dump |
len | length of buffer to dump |
If level
is visible, does a nice hexdump -C style dump of vbuf
for len
bytes. This can be extremely convenient while debugging.
LWS_VISIBLE LWS_EXTERN int lwsl_timestamp | ( | int | level, |
char * | p, | ||
size_t | len | ||
) |
#include <include/libwebsockets/lws-logs.h>
lwsl_timestamp: generate logging timestamp string
level | logging level |
p | char * buffer to take timestamp |
len | length of p |
returns length written in p
LWS_VISIBLE LWS_EXTERN int lwsl_visible | ( | int | level | ) |
#include <include/libwebsockets/lws-logs.h>
lwsl_visible() - returns true if the log level should be printed
level | one of LLL_ log level indexes |
This is useful if you have to do work to generate the log content, you can skip the work if the log level used to print it is not actually enabled at runtime.