[Libwebsockets] New logging features
Andy Green
andy at warmcat.com
Sun Jun 27 11:25:51 CEST 2021
Hi -
There are a couple of patches on main that add the idea of a "log
context" alongside the existing logging.
You can read about it in the bottom section "New logging context apis" in
https://libwebsockets.org/git/libwebsockets/tree/READMEs/README.logging.md?h=main
By default there is still a processwide log context that works using the
same public apis, everything use it and acts the same. There's no plan
to deprecate any of those apis, since you still need them to log when
there are no lws objects handy to provide a different log context. So
you can just continue to use the old ones if you don't care.
Internally, the current processwide logging is now implemented using a
default log context, but you can make your own additional log contexts
and have lws_contexts, lws_vhosts, wsi and Secure Stream handles use
those instead of the default ones at creation time. Helpers are
provided to simplify emit to stderr and to an arbitrary filepath per log
context, which can be set at runtime.
The logging mask belongs to the log context as well, so it's now
possible to eg, have a default quiet log level but have a verbose log
context, and bind a specific client wsi to that.
I have migrated about half of the lws internal logging to use the new
apis, so, eg, logs related to a wsi will follow along with the wsi's log
context setting. I'll migrate more in the next days.
Sets of macros are provided that extend the usual helpers like
lwsl_err(...) to, eg, lwsl_wsi_err(wsi, ...), these objects know how to
prepend their tags to the logging.
__func__ is prepended automatically, and you don't need any trailing \n
any more in the format string. So the new logs tend to remove
boilerplate at use and make the log contents more consistent.
This is still quite new so if it brings up any ideas feel free to discuss.
-Andy
More information about the Libwebsockets
mailing list