extcap: Register log handler conditionally

This matches the original implementation and allows displaying
logs to the console, including debug information, when running
an extcap from the CLI for testing and development purposes.

This should make extcap logging bug-for-bug compatible with the
behavior before dc7f0b88bb.
This commit is contained in:
João Valverde 2021-12-04 22:03:31 +00:00 committed by João Valverde
parent 25c7a1abc8
commit b6130cd970
3 changed files with 46 additions and 1 deletions

View File

@ -124,7 +124,7 @@ static void extcap_custom_log(const char *domain, enum ws_log_level level,
void extcap_log_init(const char *progname)
{
ws_log_init_with_writer(progname, extcap_custom_log, NULL);
ws_log_init(progname, NULL);
}
uint8_t extcap_base_parse_options(extcap_parameters * extcap, int result, char * optargument)
@ -138,6 +138,7 @@ uint8_t extcap_base_parse_options(extcap_parameters * extcap, int result, char *
break;
case EXTCAP_OPT_DEBUG_FILE:
extcap_init_custom_log(optargument);
ws_log_set_writer(extcap_custom_log);
break;
case EXTCAP_OPT_LIST_INTERFACES:
extcap->do_list_interfaces = 1;

View File

@ -568,6 +568,30 @@ enum ws_log_level ws_log_set_fatal_str(const char *str_level)
}
void ws_log_set_writer(ws_log_writer_cb *writer)
{
if (registered_log_writer_data_free)
registered_log_writer_data_free(registered_log_writer_data);
registered_log_writer = writer;
registered_log_writer_data = NULL;
registered_log_writer_data_free = NULL;
}
void ws_log_set_writer_with_data(ws_log_writer_cb *writer,
void *user_data,
ws_log_writer_free_data_cb *free_user_data)
{
if (registered_log_writer_data_free)
registered_log_writer_data_free(registered_log_writer_data);
registered_log_writer = writer;
registered_log_writer_data = user_data;
registered_log_writer_data_free = free_user_data;
}
static void glib_log_handler(const char *domain, GLogLevelFlags flags,
const char *message, gpointer user_data _U_)
{

View File

@ -162,6 +162,26 @@ WS_DLL_PUBLIC
enum ws_log_level ws_log_set_fatal_str(const char *str_level);
/** Set the active log writer.
*
* The parameter 'writer' can be NULL to use the default writer.
*/
WS_DLL_PUBLIC
void ws_log_set_writer(ws_log_writer_cb *writer);
/** Set the active log writer.
*
* The parameter 'writer' can be NULL to use the default writer.
* Accepts an extra user_data parameter that will be passed to
* the log writer.
*/
WS_DLL_PUBLIC
void ws_log_set_writer_with_data(ws_log_writer_cb *writer,
void *user_data,
ws_log_writer_free_data_cb *free_user_data);
#define LOG_ARGS_NOEXIT -1
/** Parses the command line arguments for log options.