Commit eacef0d3 authored by Simon Morlat's avatar Simon Morlat

Add a new API to set log level for the calling thread.

Rework logging.c internally, to make it easier to understand.
Document obscure functions.
parent ff1e58f9
......@@ -107,8 +107,14 @@ BCTBX_PUBLIC void *bctbx_log_handler_get_user_data(const bctbx_log_handler_t* lo
BCTBX_PUBLIC void bctbx_add_log_handler(bctbx_log_handler_t* handler);
BCTBX_PUBLIC void bctbx_remove_log_handler(bctbx_log_handler_t* handler);
/*
* Set a callback function to render logs for the default handler.
*/
BCTBX_PUBLIC void bctbx_set_log_handler(BctbxLogFunc func);
/*same as bctbx_set_log_handler but only for a domain. NULL for all*/
/*
* Same as bctbx_set_log_handler but only for a domain. NULL for all.
* Be careful that if domain is specified, the default log handler will no longer output logs for other domains.
*/
BCTBX_PUBLIC void bctbx_set_log_handler_for_domain(BctbxLogFunc func, const char* domain);
/*Convenient function that creates a static log handler logging into supplied FILE argument.
Despite it is not recommended to use it in libraries, it can be useful for simple test programs.*/
......@@ -118,7 +124,11 @@ BCTBX_PUBLIC bctbx_list_t* bctbx_get_log_handlers(void);
BCTBX_PUBLIC void bctbx_logv_out(const char *domain, BctbxLogLevel level, const char *fmt, va_list args);
BCTBX_PUBLIC void bctbx_logv_file(void* user_info, const char *domain, BctbxLogLevel level, const char *fmt, va_list args);
#define bctbx_log_level_enabled(domain, level) (bctbx_get_log_level_mask(domain) & (level))
/*
* Returns 1 if the log level 'level' is enabled for the calling thread, otherwise 0.
* This gives the condition to decide to output a log.
*/
BCTBX_PUBLIC int bctbx_log_level_enabled(const char *domain, BctbxLogLevel level);
BCTBX_PUBLIC void bctbx_logv(const char *domain, BctbxLogLevel level, const char *fmt, va_list args);
......@@ -136,6 +146,19 @@ BCTBX_PUBLIC void bctbx_set_log_level(const char *domain, BctbxLogLevel level);
BCTBX_PUBLIC void bctbx_set_log_level_mask(const char *domain, int levelmask);
BCTBX_PUBLIC unsigned int bctbx_get_log_level_mask(const char *domain);
/**
* Set a specific log level for the calling thread for domain.
* When domain is NULL, the log level applies to all domains.
*/
BCTBX_PUBLIC void bctbx_set_thread_log_level(const char *domain, BctbxLogLevel level);
/**
* Clears the specific log level set for the calling thread by bctbx_set_thread_log_level().
* After calling this function, the global (not per thread) log level will apply to
* logs printed by this thread.
*/
BCTBX_PUBLIC void bctbx_clear_thread_log_level(const char *domain);
/**
* Tell oRTP the id of the thread used to output the logs.
* This is meant to output all the logs from the same thread to prevent deadlock problems at the application level.
......@@ -281,7 +304,7 @@ public:
pumpstream(const char *domain, BctbxLogLevel level) : mDomain(domain ? domain : ""), mLevel(level),mTraceEnabled(true) {}
~pumpstream() {
const char *domain = mDomain.empty() ? NULL : mDomain.c_str();
if (bctbx_log_level_enabled(domain, mLevel) && mTraceEnabled)
if (mTraceEnabled && bctbx_log_level_enabled(domain, mLevel))
bctbx_log(domain, mLevel, "%s", str().c_str());
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment