Commit 8c8a83bc authored by jehan's avatar jehan

remove ortp own logging functions to leverage on bctbx instead

parent 6e05a7f5
...@@ -28,76 +28,86 @@ ...@@ -28,76 +28,86 @@
#include <ortp/port.h> #include <ortp/port.h>
#ifdef BCTBX_LOG_DOMAIN
#undef BCTBX_LOG_DOMAIN
#endif
#ifndef ORTP_LOG_DOMAIN #ifndef ORTP_LOG_DOMAIN
#define ORTP_LOG_DOMAIN NULL #define ORTP_LOG_DOMAIN "ortp"
#endif #endif
#define BCTBX_LOG_DOMAIN ORTP_LOG_DOMAIN
#include "bctoolbox/logging.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {
#endif #endif
typedef enum { /***************/
ORTP_DEBUG=1, /* logging api */
ORTP_TRACE=1<<1, /***************/
ORTP_MESSAGE=1<<2,
ORTP_WARNING=1<<3,
ORTP_ERROR=1<<4,
ORTP_FATAL=1<<5,
ORTP_LOGLEV_END=1<<6
} OrtpLogLevel;
#define ORTP_FATAL BCTBX_LOG_FATAL
#define ORTP_ERROR BCTBX_LOG_ERROR
#define ORTP_WARNING BCTBX_LOG_WARNING
#define ORTP_MESSAGE BCTBX_LOG_MESSAGE
#define ORTP_TRACE BCTBX_LOG_TRACE
#define ORTP_DEBUG BCTBX_LOG_DEBUG
#define ORTP_END BCTBX_LOG_END
#define ORTP_LOGLEV_END BCTBX_LOG_LOGLEV_END
#define OrtpLogLevel BctbxLogLevel
typedef void (*OrtpLogFunc)(const char *domain, OrtpLogLevel lev, const char *fmt, va_list args); #define OrtpLogFunc BctbxLogFunc
/*#define ortp_set_log_file bctbx_set_log_file*/
ORTP_PUBLIC void ortp_set_log_file(FILE *file); ORTP_PUBLIC void ortp_set_log_file(FILE *file);
/*#define ortp_set_log_handler bctbx_set_log_handler*/
ORTP_PUBLIC void ortp_set_log_handler(OrtpLogFunc func); ORTP_PUBLIC void ortp_set_log_handler(OrtpLogFunc func);
ORTP_PUBLIC OrtpLogFunc ortp_get_log_handler(void);
ORTP_PUBLIC void ortp_logv_out(const char *domain, OrtpLogLevel level, const char *fmt, va_list args);
#define ortp_log_level_enabled(domain, level) (ortp_get_log_level_mask(domain) & (level)) /* This function does not have any means by now, as even bctbx_set_log_handler is deprecated. use bctbx_log_handler_t instead*/
ORTP_PUBLIC OrtpLogFunc ortp_get_log_handler(void);
ORTP_PUBLIC void ortp_logv(const char *domain, OrtpLogLevel level, const char *fmt, va_list args);
#define ortp_logv_out bctbx_logv_out
/*ORTP_PUBLIC void ortp_logv_out(const char *domain, OrtpLogLevel level, const char *fmt, va_list args);*/
#define ortp_log_level_enabled(domain, level) (bctbx_get_log_level_mask(domain) & (level))
#define ortp_logv bctbx_logv
/*ORTP_PUBLIC void ortp_logv(const char *domain, OrtpLogLevel level, const char *fmt, va_list args);*/
/** /**
* Flushes the log output queue. * Flushes the log output queue.
* WARNING: Must be called from the thread that has been defined with ortp_set_log_thread_id(). * WARNING: Must be called from the thread that has been defined with ortp_set_log_thread_id().
*/ */
ORTP_PUBLIC void ortp_logv_flush(void); #define ortp_logv_flush bctbx_logv_flush
/*ORTP_PUBLIC void ortp_logv_flush(void);*/
/** /**
* Activate all log level greater or equal than specified level argument. * Activate all log level greater or equal than specified level argument.
**/ **/
ORTP_PUBLIC void ortp_set_log_level(const char *domain, OrtpLogLevel level); #define ortp_set_log_level bctbx_set_log_level
/*ORTP_PUBLIC void ortp_set_log_level(const char *domain, OrtpLogLevel level);*/
ORTP_PUBLIC void ortp_set_log_level_mask(const char *domain, int levelmask); #define ortp_set_log_level_mask bctbx_set_log_level_mask
ORTP_PUBLIC unsigned int ortp_get_log_level_mask(const char *domain); /*ORTP_PUBLIC void ortp_set_log_level_mask(const char *domain, int levelmask);*/
#define ortp_get_log_level_mask bctbx_get_log_level_mask
/*ORTP_PUBLIC unsigned int ortp_get_log_level_mask(const char *domain);*/
/** /**
* Tell oRTP the id of the thread used to output the logs. * 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. * This is meant to output all the logs from the same thread to prevent deadlock problems at the application level.
* @param[in] thread_id The id of the thread that will output the logs (can be obtained using ortp_thread_self()). * @param[in] thread_id The id of the thread that will output the logs (can be obtained using ortp_thread_self()).
*/ */
ORTP_PUBLIC void ortp_set_log_thread_id(unsigned long thread_id); #define ortp_set_log_thread_id bctbx_set_log_thread_id
/*ORTP_PUBLIC void ortp_set_log_thread_id(unsigned long thread_id);*/
#ifdef __GNUC__
#define CHECK_FORMAT_ARGS(m,n) __attribute__((format(printf,m,n)))
#else
#define CHECK_FORMAT_ARGS(m,n)
#endif
#ifdef __clang__
/*in case of compile with -g static inline can produce this type of warning*/
#pragma GCC diagnostic ignored "-Wunused-function"
#endif
#ifdef ORTP_DEBUG_MODE #ifdef ORTP_DEBUG_MODE
static ORTP_INLINE void CHECK_FORMAT_ARGS(1,2) ortp_debug(const char *fmt,...) #define ortp_debug bctbx_debug
{
va_list args;
va_start (args, fmt);
ortp_logv(ORTP_LOG_DOMAIN, ORTP_DEBUG, fmt, args);
va_end (args);
}
#else #else
#define ortp_debug(...) #define ortp_debug(...)
...@@ -115,47 +125,19 @@ static ORTP_INLINE void CHECK_FORMAT_ARGS(1,2) ortp_debug(const char *fmt,...) ...@@ -115,47 +125,19 @@ static ORTP_INLINE void CHECK_FORMAT_ARGS(1,2) ortp_debug(const char *fmt,...)
static ORTP_INLINE void CHECK_FORMAT_ARGS(2,3) ortp_log(OrtpLogLevel lev, const char *fmt,...) { static ORTP_INLINE void CHECK_FORMAT_ARGS(2,3) ortp_log(OrtpLogLevel lev, const char *fmt,...) {
va_list args; va_list args;
va_start (args, fmt); va_start (args, fmt);
ortp_logv(ORTP_LOG_DOMAIN, lev, fmt, args); bctbx_logv(ORTP_LOG_DOMAIN, lev, fmt, args);
va_end (args);
}
static ORTP_INLINE void CHECK_FORMAT_ARGS(1,2) ortp_message(const char *fmt,...)
{
va_list args;
va_start (args, fmt);
ortp_logv(ORTP_LOG_DOMAIN, ORTP_MESSAGE, fmt, args);
va_end (args);
}
static ORTP_INLINE void CHECK_FORMAT_ARGS(1,2) ortp_warning(const char *fmt,...)
{
va_list args;
va_start (args, fmt);
ortp_logv(ORTP_LOG_DOMAIN, ORTP_WARNING, fmt, args);
va_end (args);
}
#endif
static ORTP_INLINE void CHECK_FORMAT_ARGS(1,2) ortp_error(const char *fmt,...)
{
va_list args;
va_start (args, fmt);
ortp_logv(ORTP_LOG_DOMAIN, ORTP_ERROR, fmt, args);
va_end (args);
}
static ORTP_INLINE void CHECK_FORMAT_ARGS(1,2) ortp_fatal(const char *fmt,...)
{
va_list args;
va_start (args, fmt);
ortp_logv(ORTP_LOG_DOMAIN, ORTP_FATAL, fmt, args);
va_end (args); va_end (args);
} }
#define ortp_message bctbx_message
#define ortp_warning bctbx_warning
#define ortp_error bctbx_error
#define ortp_fatal bctbx_fatal
#endif /*ORTP_NOMESSAGE_MODE*/
#ifdef __QNX__ #ifdef __QNX__
void ortp_qnx_log_handler(const char *domain, OrtpLogLevel lev, const char *fmt, va_list args); #define ortp_qnx_log_handler bctbx_qnx_log_handler
/*void ortp_qnx_log_handler(const char *domain, OrtpLogLevel lev, const char *fmt, va_list args);*/
#endif #endif
......
...@@ -318,9 +318,13 @@ ORTP_PUBLIC int close_socket(ortp_socket_t sock); ...@@ -318,9 +318,13 @@ ORTP_PUBLIC int close_socket(ortp_socket_t sock);
ORTP_PUBLIC int set_non_blocking_socket(ortp_socket_t sock); ORTP_PUBLIC int set_non_blocking_socket(ortp_socket_t sock);
ORTP_PUBLIC char *ortp_strndup(const char *str,int n); ORTP_PUBLIC char *ortp_strndup(const char *str,int n);
ORTP_PUBLIC char *ortp_strdup_printf(const char *fmt,...); #define ortp_strdup_printf bctbx_strdup_printf
ORTP_PUBLIC char *ortp_strdup_vprintf(const char *fmt, va_list ap); /*ORTP_PUBLIC char *ortp_strdup_printf(const char *fmt,...);*/
ORTP_PUBLIC char *ortp_strcat_printf(char *dst, const char *fmt,...); #define ortp_strdup_vprintf bctbx_strdup_vprintf
/*ORTP_PUBLIC char *ortp_strdup_vprintf(const char *fmt, va_list ap);*/
#define ortp_strcat_printf bctbx_strcat_printf
/*ORTP_PUBLIC char *ortp_strcat_printf(char *dst, const char *fmt,...);*/
ORTP_PUBLIC char *ortp_strcat_vprintf(char *dst, const char *fmt, va_list ap); ORTP_PUBLIC char *ortp_strcat_vprintf(char *dst, const char *fmt, va_list ap);
ORTP_PUBLIC int ortp_file_exist(const char *pathname); ORTP_PUBLIC int ortp_file_exist(const char *pathname);
......
...@@ -17,6 +17,71 @@ ...@@ -17,6 +17,71 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#include "ortp/utils.h"
#include "ortp/logging.h"
static bctbx_log_handler_t * __ortp_logger = NULL;
static OrtpLogFunc __ortp_log_func = bctbx_logv_out;
static unsigned int ortp_init_logger_refcount = 0;
static void wrapper(void* info,const char *domain, BctbxLogLevel lev, const char *fmt, va_list args) {
BctbxLogFunc func = (BctbxLogFunc)info;
if (func) func(domain, lev, fmt, args);
}
void ortp_init_logger(void){
if (ortp_init_logger_refcount++ > 0) return; /*already initialized*/
bctbx_init_logger(FALSE);
__ortp_logger = bctbx_create_log_handler(wrapper, bctbx_logv_out_destroy, __ortp_log_func);
bctbx_log_handler_set_domain(__ortp_logger, ORTP_LOG_DOMAIN);
bctbx_add_log_handler(__ortp_logger);
}
void ortp_uninit_logger(void){
if (--ortp_init_logger_refcount <= 0) {
bctbx_remove_log_handler(__ortp_logger);
bctbx_uninit_logger();
}
}
void ortp_set_log_handler(OrtpLogFunc func){
__ortp_log_func = func ;
if (__ortp_logger)
bctbx_log_handler_set_user_data(__ortp_logger,func);
}
OrtpLogFunc ortp_get_log_handler(void){
return __ortp_log_func;
}
/**
*@param file a FILE pointer where to output the ortp logs.
*
**/
void ortp_set_log_file(FILE *file){
if (!__ortp_logger) {
ortp_init_logger();
ortp_error("ortp_init_logger must be call before ortp_set_log_file, please fix it!");
}
/*first remove log handler*/
bctbx_remove_log_handler(__ortp_logger);
if (file) {
__ortp_logger = bctbx_create_file_log_handler(0, "unknown","unknown", file);
} else {
/*restaure default loguer*/
__ortp_logger = bctbx_create_log_handler(wrapper, bctbx_logv_out_destroy, ortp_logv_out);
}
bctbx_log_handler_set_domain(__ortp_logger, ORTP_LOG_DOMAIN);
bctbx_add_log_handler(__ortp_logger);
}
#if 0
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "ortp-config.h" #include "ortp-config.h"
#endif #endif
...@@ -429,3 +494,4 @@ void ortp_qnx_log_handler(const char *domain, OrtpLogLevel lev, const char *fmt, ...@@ -429,3 +494,4 @@ void ortp_qnx_log_handler(const char *domain, OrtpLogLevel lev, const char *fmt,
slog2c(slog2_buffer_handle[buffer_idx], 0, severity, msg); slog2c(slog2_buffer_handle[buffer_idx], 0, severity, msg);
} }
#endif /* __QNX__ */ #endif /* __QNX__ */
#endif
...@@ -25,7 +25,7 @@ if (NOT IOS) ...@@ -25,7 +25,7 @@ if (NOT IOS)
foreach(executable ${EXECUTABLES}) foreach(executable ${EXECUTABLES})
bc_apply_compile_flags(${executable}.c STRICT_OPTIONS_CPP STRICT_OPTIONS_C) bc_apply_compile_flags(${executable}.c STRICT_OPTIONS_CPP STRICT_OPTIONS_C)
add_executable(${executable} ${executable}.c) add_executable(${executable} ${executable}.c)
target_link_libraries(${executable} ortp) target_link_libraries(${executable} ortp ${BCTOOLBOX_CORE_LIBRARIES})
endforeach() endforeach()
install(TARGETS ${EXECUTABLES} install(TARGETS ${EXECUTABLES}
......
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