Skip to content

Commit

Permalink
context info: add default_loglevel
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lws-team committed Dec 13, 2023
1 parent c43a0d6 commit e381d2d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions include/libwebsockets/lws-context-vhost.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
3 changes: 2 additions & 1 deletion lib/core/libwebsockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e381d2d

Please sign in to comment.