1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-30 00:00:16 +01:00

context info: add default_loglevel

Allow this kind of pattern for context creation info preparation

        struct lws_context_creation_info info;

        lws_context_info_defaults(&info, policy);
        info.default_loglevel = LLL_USER | LLL_ERR | LLL_WARN;
        lws_cmdline_option_handle_builtin(argc, argv, &info);

Calling lws_context_info_defaults() zeros down and prepares boilerplate in
the info struct, setting the default_loglevel asserts your application
default for the loglevel and then lws_cmdline_option_handle_builtin() will
set either that default loglevel, or override it from the commandline with
-d 1039 etc
This commit is contained in:
Andy Green 2023-12-13 06:43:14 +00:00
parent 957503436e
commit 52a6ab357e
2 changed files with 9 additions and 1 deletions

View file

@ -952,6 +952,13 @@ struct lws_context_creation_info {
*/
#endif
int default_loglevel;
/**< CONTEXT: 0 for LLL_USER, LLL_ERR, LLL_WARN, LLL_NOTICE enabled by default when
* using lws_cmdline_option_handle_builtin(), else set to the LLL_ flags you want
* to be the default before calling lws_cmdline_option_handle_builtin(). Your
* selected default loglevel can then be cleanly overridden using -d 1039 etc
* commandline switch */
/* Add new things just above here ---^
* This is part of the ABI, don't needlessly break compatibility
*

View file

@ -1632,7 +1632,8 @@ lws_cmdline_option_handle_builtin(int argc, const char **argv,
struct lws_context_creation_info *info)
{
const char *p;
int n, m, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE;
int n, m, logs = info->default_loglevel ? info->default_loglevel :
LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE;
#if defined(LWS_WITH_SYS_FAULT_INJECTION)
uint64_t seed = (uint64_t)lws_now_usecs();
#endif