Skip to content

Commit e381d2d

Browse files
committed
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
1 parent c43a0d6 commit e381d2d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

include/libwebsockets/lws-context-vhost.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,13 @@ struct lws_context_creation_info {
952952
*/
953953
#endif
954954

955+
int default_loglevel;
956+
/**< CONTEXT: 0 for LLL_USER, LLL_ERR, LLL_WARN, LLL_NOTICE enabled by default when
957+
* using lws_cmdline_option_handle_builtin(), else set to the LLL_ flags you want
958+
* to be the default before calling lws_cmdline_option_handle_builtin(). Your
959+
* selected default loglevel can then be cleanly overridden using -d 1039 etc
960+
* commandline switch */
961+
955962
/* Add new things just above here ---^
956963
* This is part of the ABI, don't needlessly break compatibility
957964
*

lib/core/libwebsockets.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1632,7 +1632,8 @@ lws_cmdline_option_handle_builtin(int argc, const char **argv,
16321632
struct lws_context_creation_info *info)
16331633
{
16341634
const char *p;
1635-
int n, m, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE;
1635+
int n, m, logs = info->default_loglevel ? info->default_loglevel :
1636+
LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE;
16361637
#if defined(LWS_WITH_SYS_FAULT_INJECTION)
16371638
uint64_t seed = (uint64_t)lws_now_usecs();
16381639
#endif

0 commit comments

Comments
 (0)