From f0136172b063c81e399dea3c2b325d66e7b3fab3 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Tue, 9 Apr 2013 18:07:53 +0200 Subject: [PATCH] Change API to set log handler and log level. - Deprecate linphone_core_enable_logs(), linphone_core_enable_logs_with_cb() and linphone_core_disable_logs() functions. - Introduce linphone_core_set_log_handler(), linphone_core_set_log_file() and linphone_core_set_log_level() functions. --- coreapi/linphonecore.c | 32 +++++++++++++++++++++++++++++--- coreapi/linphonecore.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index f4782908..5f70f45e 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -407,10 +407,29 @@ const LinphoneAddress *linphone_core_get_current_call_remote_address(struct _Lin return linphone_call_get_remote_address(call); } +void linphone_core_set_log_handler(OrtpLogFunc logfunc) { + ortp_set_log_handler(logfunc); +} + +void linphone_core_set_log_file(FILE *file) { + if (file == NULL) file = stdout; + ortp_set_log_file(file); +} + +void linphone_core_set_log_level(OrtpLogLevel loglevel) { + ortp_set_log_level_mask(loglevel); + if (loglevel == 0) { + sal_disable_logs(); + } else { + sal_enable_logs(); + } +} + /** * Enable logs in supplied FILE*. * * @ingroup misc + * @deprecated Use #linphone_core_set_log_file and #linphone_core_set_log_level instead. * * @param file a C FILE* where to fprintf logs. If null stdout is used. * @@ -425,6 +444,7 @@ void linphone_core_enable_logs(FILE *file){ * Enable logs through the user's supplied log callback. * * @ingroup misc + * @deprecated Use #linphone_core_set_log_handler and #linphone_core_set_log_level instead. * * @param logfunc The address of a OrtpLogFunc callback whose protoype is * typedef void (*OrtpLogFunc)(OrtpLogLevel lev, const char *fmt, va_list args); @@ -439,6 +459,7 @@ void linphone_core_enable_logs_with_cb(OrtpLogFunc logfunc){ * Entirely disable logging. * * @ingroup misc + * @deprecated Use #linphone_core_set_log_level instead. **/ void linphone_core_disable_logs(){ ortp_set_log_level_mask(ORTP_ERROR|ORTP_FATAL); @@ -1197,6 +1218,7 @@ static void misc_config_read (LinphoneCore *lc) { LpConfig *config=lc->config; lc->max_call_logs=lp_config_get_int(config,"misc","history_max_size",15); lc->max_calls=lp_config_get_int(config,"misc","max_calls",NB_MAX_CALLS); + linphone_core_set_log_level((OrtpLogLevel)lp_config_get_int(config,"misc","log_level",0)); } @@ -2152,9 +2174,13 @@ void linphone_core_iterate(LinphoneCore *lc){ lc->initial_subscribes_sent=TRUE; } - if (one_second_elapsed && lp_config_needs_commit(lc->config)){ - lp_config_sync(lc->config); - } + if (one_second_elapsed) { + if (ortp_get_log_level_mask() != lp_config_get_int(lc->config, "misc", "log_level", 0)) { + lp_config_set_int(lc->config, "misc", "log_level", ortp_get_log_level_mask()); + } + if (lp_config_needs_commit(lc->config)) { + lp_config_sync(lc->config); + } } /** diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 37001d36..f8e1dcb8 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -874,6 +874,35 @@ typedef void * (*LinphoneWaitingCallback)(struct _LinphoneCore *lc, void *contex /* THE main API */ +/** + * Define a log handler. + * + * @ingroup misc + * + * @param logfunc The function pointer of the log handler. + */ +void linphone_core_set_log_handler(OrtpLogFunc logfunc); +/** + * Define a log file. + * + * @ingroup misc + * + * If the file pointer passed as an argument is NULL, stdout is used instead. + * + * @param file A pointer to the FILE structure of the file to write to. + */ +void linphone_core_set_log_file(FILE *file); +/** + * Define the log level. + * + * @ingroup misc + * + * The loglevel parameter is a bitmask parameter. Therefore to enable only warning and error + * messages, use ORTP_WARNING | ORTP_ERROR. To disable logs, simply set loglevel to 0. + * + * @param loglevel A bitmask of the log levels to set. + */ +void linphone_core_set_log_level(OrtpLogLevel loglevel); void linphone_core_enable_logs(FILE *file); void linphone_core_enable_logs_with_cb(OrtpLogFunc logfunc); void linphone_core_disable_logs(void); -- 2.39.2