libwebsockets
Lightweight C library for HTML5 websockets
Logging

Macros

#define lwsl_err(...)   _lws_log(LLL_ERR, __VA_ARGS__)
 
#define lwsl_user(...)   _lws_log(LLL_USER, __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_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__)
 

Enumerations

enum  lws_log_levels {
  LLL_ERR = 1 << 0, LLL_WARN = 1 << 1, LLL_NOTICE = 1 << 2, LLL_INFO = 1 << 3,
  LLL_DEBUG = 1 << 4, LLL_PARSER = 1 << 5, LLL_HEADER = 1 << 6, LLL_EXT = 1 << 7,
  LLL_CLIENT = 1 << 8, LLL_LATENCY = 1 << 9, LLL_USER = 1 << 10, LLL_THREAD = 1 << 11,
  LLL_COUNT = 12
}
 

Functions

LWS_VISIBLE LWS_EXTERN int lwsl_timestamp (int level, char *p, int 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 void lwsl_hexdump_level (int 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, void(*log_emit_function)(int level, const char *line))
 
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)
 

Detailed Description

Logging

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.

Function Documentation

◆ lws_set_log_level()

LWS_VISIBLE LWS_EXTERN void lws_set_log_level ( int  level,
void(*)(int level, const char *line)  log_emit_function 
)

#include <include/libwebsockets/lws-logs.h>

lws_set_log_level() - Set the logging bitfield

Parameters
levelOR together the LLL_ debug contexts you want output from
log_emit_functionNULL 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.

◆ lwsl_emit_stderr()

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

Parameters
levelone of LLL_ log level indexes
linelog 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.

◆ lwsl_emit_stderr_notimestamp()

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

Parameters
levelone of LLL_ log level indexes
linelog 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.

◆ lwsl_emit_syslog()

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

Parameters
levelone of LLL_ log level indexes
linelog 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.

◆ lwsl_hexdump()

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)

Parameters
bufbuffer start to dump
lenlength 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.

◆ lwsl_hexdump_level()

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

Parameters
levelone of LLL_ constants
vbufbuffer start to dump
lenlength 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.

◆ lwsl_timestamp()

LWS_VISIBLE LWS_EXTERN int lwsl_timestamp ( int  level,
char *  p,
int  len 
)

#include <include/libwebsockets/lws-logs.h>

lwsl_timestamp: generate logging timestamp string

Parameters
levellogging level
pchar * buffer to take timestamp
lenlength of p

returns length written in p

◆ lwsl_visible()

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

Parameters
levelone 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.