From facab07c405225cbb99f8c8a4b94ec7a43f48367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grisez?= Date: Tue, 10 Oct 2017 14:31:58 +0200 Subject: [PATCH] Creates a new singleton object for logging features in the API of Liblinphone (cherry picked from commit d61a62de91483a5ba6029153c224adec9ef68622) --- coreapi/CMakeLists.txt | 1 + coreapi/linphonecore.c | 39 ++--- coreapi/logging-private.h | 61 ++++++++ coreapi/logging.c | 256 +++++++++++++++++++++++++++++++ include/CMakeLists.txt | 1 + include/linphone/core.h | 23 ++- include/linphone/logging.h | 178 +++++++++++++++++++++ src/c-wrapper/c-wrapper.h | 2 + tester/tester.c | 4 +- wrappers/cpp/class_impl.mustache | 1 + 10 files changed, 527 insertions(+), 39 deletions(-) create mode 100644 coreapi/logging-private.h create mode 100644 coreapi/logging.c create mode 100644 include/linphone/logging.h diff --git a/coreapi/CMakeLists.txt b/coreapi/CMakeLists.txt index 03600de80..85e13205c 100644 --- a/coreapi/CMakeLists.txt +++ b/coreapi/CMakeLists.txt @@ -84,6 +84,7 @@ set(LINPHONE_SOURCE_FILES_C linphonecore.c linphone_tunnel_config.c localplayer.c + logging.c lpc2xml.c lpconfig.c lsd.c diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index c6af072cf..b0a4347fe 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -21,7 +21,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "linphone/core.h" #include "linphone/sipsetup.h" #include "linphone/lpconfig.h" +#include "linphone/logging.h" #include "private.h" +#include "logging-private.h" #include "quality_reporting.h" #include "lime.h" #include "conference_private.h" @@ -500,40 +502,17 @@ void linphone_core_set_log_file(FILE *file) { } void linphone_core_set_log_level(OrtpLogLevel loglevel) { - unsigned int mask = loglevel; - switch (loglevel) { - case ORTP_TRACE: - case ORTP_DEBUG: - mask |= ORTP_DEBUG; - BCTBX_NO_BREAK; - case ORTP_MESSAGE: - mask |= ORTP_MESSAGE; - BCTBX_NO_BREAK; - case ORTP_WARNING: - mask |= ORTP_WARNING; - BCTBX_NO_BREAK; - case ORTP_ERROR: - mask |= ORTP_ERROR; - BCTBX_NO_BREAK; - case ORTP_FATAL: - mask |= ORTP_FATAL; - break; - case ORTP_LOGLEV_END: - break; - } - linphone_core_set_log_level_mask(mask); + LinphoneLoggingService *log_service = linphone_logging_service_get(); + linphone_logging_service_set_log_level(log_service, _bctbx_log_level_to_linphone_log_level(loglevel)); } -void linphone_core_set_log_level_mask(unsigned int loglevel) { - bctbx_set_log_level_mask("bctbx", (int)loglevel); - bctbx_set_log_level_mask("ortp", (int)loglevel); - bctbx_set_log_level_mask("mediastreamer", (int)loglevel); - bctbx_set_log_level_mask("bzrtp", (int)loglevel); /*need something to set log level for all domains*/ - bctbx_set_log_level_mask("linphone", (int)loglevel); - sal_set_log_level((OrtpLogLevel)loglevel); +void linphone_core_set_log_level_mask(unsigned int mask) { + LinphoneLoggingService *log_service = linphone_logging_service_get(); + linphone_logging_service_set_log_level_mask(log_service, _bctbx_log_mask_to_linphone_log_mask(mask)); } unsigned int linphone_core_get_log_level_mask(void) { - return bctbx_get_log_level_mask(ORTP_LOG_DOMAIN); + LinphoneLoggingService *log_service = linphone_logging_service_get(); + return linphone_logging_service_get_log_level_mask(log_service); } static int _open_log_collection_file_with_idx(int idx) { struct stat statbuf; diff --git a/coreapi/logging-private.h b/coreapi/logging-private.h new file mode 100644 index 000000000..e9b54b990 --- /dev/null +++ b/coreapi/logging-private.h @@ -0,0 +1,61 @@ +/* +logging-private.h +Copyright (C) 2017 Belledonne Communications SARL + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef _LOGGING_PRIVATE_H_ +#define _LOGGING_PRIVATE_H_ + +#include +#include "linphone/logging.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Converts a #BctbxLogLevel into #LinphoneLogLevel. + */ +LinphoneLogLevel _bctbx_log_level_to_linphone_log_level(BctbxLogLevel level); + +/** + * @brief Converts a mask of #BctbxLogLevel into a mask of #LinphoneLogLevel. + */ +unsigned int _bctbx_log_mask_to_linphone_log_mask(unsigned int mask); + +/** + * @brief Converts a #LinphoneLogLevel into #BctbxLogLevel. + */ +BctbxLogLevel _linphone_log_level_to_bctbx_log_level(LinphoneLogLevel level); + +/** + * @brief Converts a mask of #LinphoneLogLevel into a mask of #BctbxLogLevel. + */ +unsigned int _linphone_log_mask_to_bctbx_log_mask(unsigned int mask); + +/** + * @brief Releases the instance pointer of the singleton. + * @note You should not need to call this function since it is automatically done + * at process ending. + */ +void _linphone_logging_service_clean(void); + +#ifdef __cplusplus +} +#endif + +#endif // _LOGGING_PRIVATE_H_ diff --git a/coreapi/logging.c b/coreapi/logging.c new file mode 100644 index 000000000..e39ae0012 --- /dev/null +++ b/coreapi/logging.c @@ -0,0 +1,256 @@ +/* +log.c +Copyright (C) 2017 Belledonne Communications SARL + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include +#include + +#include +#include +#include + +#include "linphone/logging.h" + +#include "c-wrapper/c-wrapper.h" +#include "logging-private.h" + + +struct _LinphoneLoggingService { + belle_sip_object_t base; + LinphoneLoggingServiceCbs *cbs; + bctbx_log_handler_t *log_handler; +}; + +BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneLoggingService); +BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneLoggingService); + +struct _LinphoneLoggingServiceCbs { + belle_sip_object_t base; + void *user_data; + LinphoneLoggingServiceCbsLogMessageWrittenCb message_event_cb; +}; + +BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneLoggingServiceCbs); +BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneLoggingServiceCbs); + +static LinphoneLoggingServiceCbs *_linphone_logging_service_cbs_new(void); + + + + + +static LinphoneLoggingService *_linphone_logging_service_instance = NULL; + +static std::map _linphone_log_level_to_bctbx_log_level_map = { + { LinphoneLogLevelDebug , BCTBX_LOG_DEBUG }, + { LinphoneLogLevelTrace , BCTBX_LOG_TRACE }, + { LinphoneLogLevelMessage , BCTBX_LOG_MESSAGE }, + { LinphoneLogLevelWarning , BCTBX_LOG_WARNING }, + { LinphoneLogLevelError , BCTBX_LOG_ERROR }, + { LinphoneLogLevelFatal , BCTBX_LOG_FATAL } +}; + +LinphoneLogLevel _bctbx_log_level_to_linphone_log_level(BctbxLogLevel level) { + auto &tmap = _linphone_log_level_to_bctbx_log_level_map; + auto predicate = [level](const std::pair &tuple)->bool{return tuple.second==level;}; + auto response = std::find_if(tmap.cbegin(), tmap.cend(), predicate); + if (response != tmap.cend()) { + return response->first; + } else { + ms_fatal("%s(): invalid argurement [%d]", __FUNCTION__, level); + return LinphoneLogLevelDebug; + } +} + +unsigned int _bctbx_log_mask_to_linphone_log_mask(unsigned int mask) { + unsigned int res = 0; + auto &tmap = _linphone_log_level_to_bctbx_log_level_map; + for (auto it=tmap.cbegin(); it!=tmap.cend(); it++) { + if (mask & it->second) { + mask&=~it->second; + res|=it->first; + } + } + if (mask != 0) { + ms_fatal("%s(): invalid flag set in mask [%x]", __FUNCTION__, mask); + } + return res; +} + +BctbxLogLevel _linphone_log_level_to_bctbx_log_level(LinphoneLogLevel level) { + try { + return _linphone_log_level_to_bctbx_log_level_map.at(level); + } catch (const std::out_of_range &e) { + ms_fatal("%s(): invalid argument [%d]", __FUNCTION__, level); + return BCTBX_LOG_LOGLEV_END; + } +} + +unsigned int _linphone_log_mask_to_bctbx_log_mask(unsigned int mask) { + unsigned int res = 0; + auto &tmap = _linphone_log_level_to_bctbx_log_level_map; + for (auto it=tmap.cbegin(); it!=tmap.cend(); it++) { + if (mask & it->first) { + mask&=~it->first; + res|=it->second; + } + } + if (mask != 0) { + ms_fatal("%s(): invalid flag set in mask [%x]", __FUNCTION__, mask); + } + return res; +} + +static void _log_handler_on_message_written_cb(void *info,const char *domain, BctbxLogLevel lev, const char *fmt, va_list args) { + LinphoneLoggingService *service = (LinphoneLoggingService *)info; + if (service->cbs->message_event_cb) { + char *message = bctbx_strdup_vprintf(fmt, args); + service->cbs->message_event_cb(service, domain, _bctbx_log_level_to_linphone_log_level(lev), message); + bctbx_free(message); + } +} + +static void _log_handler_destroy_cb(bctbx_log_handler_t *handler) { + LinphoneLoggingService *service = (LinphoneLoggingService *)bctbx_log_handler_get_user_data(handler); + service->log_handler = NULL; +} + +static LinphoneLoggingService *_linphone_logging_service_new(void) { + LinphoneLoggingService *service = belle_sip_object_new(LinphoneLoggingService); + service->log_handler = bctbx_create_log_handler(_log_handler_on_message_written_cb, _log_handler_destroy_cb, service); + service->cbs = _linphone_logging_service_cbs_new(); + bctbx_add_log_handler(service->log_handler); + return service; +} + +LinphoneLoggingService *linphone_logging_service_get(void) { + if (_linphone_logging_service_instance == NULL) { + _linphone_logging_service_instance = _linphone_logging_service_new(); + atexit(_linphone_logging_service_clean); + } + return _linphone_logging_service_instance; +} + +void _linphone_logging_service_clean(void) { + if (_linphone_logging_service_instance) { + linphone_logging_service_unref(_linphone_logging_service_instance); + _linphone_logging_service_instance = NULL; + } +} + +LinphoneLoggingService *linphone_logging_service_ref(LinphoneLoggingService *service) { + return (LinphoneLoggingService *)belle_sip_object_ref(service); +} + +void linphone_logging_service_unref(LinphoneLoggingService *service) { + belle_sip_object_ref(service); +} + +static void _linphone_logging_service_uninit(LinphoneLoggingService *log_service) { + if (log_service->log_handler) bctbx_remove_log_handler(log_service->log_handler); + linphone_logging_service_cbs_unref(log_service->cbs); +} + +void linphone_logging_service_release_instance(void) { + if (_linphone_logging_service_instance) { + belle_sip_object_unref(BELLE_SIP_OBJECT(_linphone_logging_service_instance)); + } + _linphone_logging_service_instance = NULL; +} + +LinphoneLoggingServiceCbs *linphone_logging_service_get_callbacks(const LinphoneLoggingService *log_service) { + return log_service->cbs; +} + +static const char *_linphone_logging_service_log_domains[] = { + "bctbx", + "ortp", + "mediastreamer", + "bzrtp", + "linphone", + NULL +}; + +void linphone_logging_service_set_log_level(LinphoneLoggingService *log_service, LinphoneLogLevel loglevel) { + const char **domain; + for (domain=_linphone_logging_service_log_domains; *domain; domain++) { + bctbx_set_log_level(*domain, _linphone_log_level_to_bctbx_log_level(loglevel)); + } +} + +void linphone_logging_service_set_log_level_mask(LinphoneLoggingService *log_service, unsigned int mask) { + const char **domain; + for (domain=_linphone_logging_service_log_domains; *domain; domain++) { + bctbx_set_log_level_mask(*domain, _linphone_log_mask_to_bctbx_log_mask(mask)); + } +} + +unsigned int linphone_logging_service_get_log_level_mask(const LinphoneLoggingService *log_service) { + return _bctbx_log_mask_to_linphone_log_mask(bctbx_get_log_level_mask(ORTP_LOG_DOMAIN)); +} + +void linphone_logging_service_set_log_file(const LinphoneLoggingService *service, const char *dir, const char *filename, size_t max_size) { + bctbx_log_handler_t *log_handler = bctbx_create_file_log_handler((uint64_t)max_size, dir, filename, NULL); + bctbx_add_log_handler(log_handler); +} + +BELLE_SIP_INSTANCIATE_VPTR(LinphoneLoggingService, belle_sip_object_t, + _linphone_logging_service_uninit, // uninit + NULL, // clone + NULL, // marshal + FALSE // unown +); + + + + + + + + + +static LinphoneLoggingServiceCbs *_linphone_logging_service_cbs_new(void) { + return belle_sip_object_new(LinphoneLoggingServiceCbs); +} + +LinphoneLoggingServiceCbs *linphone_logging_service_cbs_ref(LinphoneLoggingServiceCbs *cbs) { + return (LinphoneLoggingServiceCbs *)belle_sip_object_ref(cbs); +} + +void linphone_logging_service_cbs_unref(LinphoneLoggingServiceCbs *cbs) { + belle_sip_object_unref(cbs); +} + +void linphone_logging_service_cbs_set_log_message_written(LinphoneLoggingServiceCbs *cbs, LinphoneLoggingServiceCbsLogMessageWrittenCb cb) { + cbs->message_event_cb = cb; +} + +LinphoneLoggingServiceCbsLogMessageWrittenCb linphone_logging_service_cbs_get_log_message_written(const LinphoneLoggingServiceCbs *cbs) { + return cbs->message_event_cb; +} + +void linphone_logging_service_cbs_set_user_data(LinphoneLoggingServiceCbs *cbs, void *user_data) { + cbs->user_data = user_data; +} + +BELLE_SIP_INSTANCIATE_VPTR(LinphoneLoggingServiceCbs, belle_sip_object_t, + NULL, // uninit + NULL, // clone + NULL, // marshal + FALSE // unown +); diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 92593391a..2e09af5eb 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -48,6 +48,7 @@ set(ROOT_HEADER_FILES im_notif_policy.h info_message.h ldapprovider.h + logging.h lpconfig.h misc.h nat_policy.h diff --git a/include/linphone/core.h b/include/linphone/core.h index 7ee26c5d0..ce0e774e0 100644 --- a/include/linphone/core.h +++ b/include/linphone/core.h @@ -800,25 +800,28 @@ LINPHONE_PUBLIC void linphone_core_reset_log_collection(void); /** * @bref Define a log handler. * @param logfunc The function pointer of the log handler. + * @deprecated Use #linphone_log_service_set_log_handler() instead. Deprecated since 2017-10-10. * @donotwrap */ -LINPHONE_PUBLIC void linphone_core_set_log_handler(OrtpLogFunc logfunc); +LINPHONE_PUBLIC LINPHONE_DEPRECATED void linphone_core_set_log_handler(OrtpLogFunc logfunc); /** * @brief Define a log file. * * 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. + * @deprecated Use #linphone_log_service_set_file() instead. Deprecated since 2017-10-10. * @donotwrap */ -LINPHONE_PUBLIC void linphone_core_set_log_file(FILE *file); +LINPHONE_PUBLIC LINPHONE_DEPRECATED void linphone_core_set_log_file(FILE *file); /** * @brief Define the minimum level for logging. * @param loglevel Minimum level for logging messages. + * @deprecated Use #linphone_logging_service_set_log_level() instead. Deprecated since 2017-10-10. * @donotwrap **/ -LINPHONE_PUBLIC void linphone_core_set_log_level(OrtpLogLevel loglevel); +LINPHONE_PUBLIC LINPHONE_DEPRECATED void linphone_core_set_log_level(OrtpLogLevel loglevel); /** * Define the log level using mask. @@ -826,22 +829,25 @@ LINPHONE_PUBLIC void linphone_core_set_log_level(OrtpLogLevel loglevel); * 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. + * @param mask A bitmask of the log levels to set. + * @deprecated Use #linphone_logging_service_set_log_level() instead. Deprecated since 2017-10-10. */ -LINPHONE_PUBLIC void linphone_core_set_log_level_mask(unsigned int loglevel); +LINPHONE_PUBLIC LINPHONE_DEPRECATED void linphone_core_set_log_level_mask(unsigned int mask); /** * Get defined log level mask. * * @return 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. + * @deprecated Use #linphone_logging_service_get_log_level_mask() instead. Deprecated since 2017-10-10. */ -LINPHONE_PUBLIC unsigned int linphone_core_get_log_level_mask(void); +LINPHONE_PUBLIC LINPHONE_DEPRECATED unsigned int linphone_core_get_log_level_mask(void); /** * Enable logs in supplied FILE*. * @param file a C FILE* where to fprintf logs. If null stdout is used. - * @deprecated Use #linphone_core_set_log_file and #linphone_core_set_log_level instead. + * @deprecated Use #linphone_core_set_log_file and #linphone_core_set_log_level() instead. + * Deprecated since 2017-01-12. * @donotwrap **/ LINPHONE_DEPRECATED LINPHONE_PUBLIC void linphone_core_enable_logs(FILE *file); @@ -851,13 +857,14 @@ LINPHONE_DEPRECATED LINPHONE_PUBLIC void linphone_core_enable_logs(FILE *file); * @param logfunc The address of a OrtpLogFunc callback whose protoype is * typedef void (*OrtpLogFunc)(OrtpLogLevel lev, const char *fmt, va_list args); * @deprecated Use #linphone_core_set_log_handler and #linphone_core_set_log_level instead. + * Deprecated since 2017-01-12. * @donotwrap **/ LINPHONE_DEPRECATED LINPHONE_PUBLIC void linphone_core_enable_logs_with_cb(OrtpLogFunc logfunc); /** * Entirely disable logging. - * @deprecated Use #linphone_core_set_log_level instead. + * @deprecated Use #linphone_core_set_log_level() instead. Deprecated since 2017-01-12. * @donotwrap **/ LINPHONE_DEPRECATED LINPHONE_PUBLIC void linphone_core_disable_logs(void); diff --git a/include/linphone/logging.h b/include/linphone/logging.h new file mode 100644 index 000000000..e54d0702f --- /dev/null +++ b/include/linphone/logging.h @@ -0,0 +1,178 @@ +/* +logging.h +Copyright (C) 2017 Belledonne Communications SARL + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef _LINPHONE_LOG_H_ +#define _LINPHONE_LOG_H_ + +#include "types.h" +#include "defs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup logging + * @{ + */ + +/** + * @brief Singleton class giving access to logging features. + */ +typedef struct _LinphoneLoggingService LinphoneLoggingService; + +/** + * @brief Listener for #LinphoneLoggingService. + */ +typedef struct _LinphoneLoggingServiceCbs LinphoneLoggingServiceCbs; + +/** + * @brief Verbosity levels of log messages. + */ +typedef enum _LinphoneLogLevel { + LinphoneLogLevelDebug = 1, /**< @brief Level for debug messages. */ + LinphoneLogLevelTrace = 1<<1, /**< @brief Level for traces. */ + LinphoneLogLevelMessage = 1<<2, /**< @brief Level for information messages. */ + LinphoneLogLevelWarning = 1<<3, /**< @brief Level for warning messages. */ + LinphoneLogLevelError = 1<<4, /**< @brief Level for error messages. */ + LinphoneLogLevelFatal = 1<<5 /**< @brief Level for fatal error messages. */ +} LinphoneLogLevel; + +/** + * @brief Type of callbacks called each time liblinphone write a log message. + * + * @param log_service A pointer on the logging service singleton. + * @param domain A string describing which sub-library of liblinphone the message is coming from. + * @param lev Verbosity level of the message. + * @param message Content of the message. + */ +typedef void (*LinphoneLoggingServiceCbsLogMessageWrittenCb)(LinphoneLoggingService *log_service, const char *domain, LinphoneLogLevel lev, const char *message); + + + + + +/** + * @brief Gets the singleton logging service object. + * + * The singleton is automatically instantiated if it hasn't + * been done yet. + * + * @return A pointer on the singleton. + */ +LINPHONE_PUBLIC LinphoneLoggingService *linphone_logging_service_get(void); + +/** + * @brief Increases the reference counter. + */ +LINPHONE_PUBLIC LinphoneLoggingService *linphone_logging_service_ref(LinphoneLoggingService *service); + +/** + * @brief Decreases the reference counter and destroy the object + * if the counter reaches 0. + */ +LINPHONE_PUBLIC void linphone_logging_service_unref(LinphoneLoggingService *service); + +/** + * @brief Gets the logging service listener. + */ +LINPHONE_PUBLIC LinphoneLoggingServiceCbs *linphone_logging_service_get_callbacks(const LinphoneLoggingService *log_service); + +/** + * @brief Set the verbosity of the log. + * + * For instance, a level of #LinphoneLogLevelMessage will let pass fatal, error, warning and message-typed messages + * whereas trace and debug messages will be dumped out. + */ +LINPHONE_PUBLIC void linphone_logging_service_set_log_level(LinphoneLoggingService *log_service, LinphoneLogLevel level); + +/** + * @brief Sets the types of messages that will be authorized to be written in the log. + * @param log_service The logging service singleton. + * @param mask Example: #LinphoneLogLevelMessage|#LinphoneLogLevelError will ONLY let pass message-typed and error messages. + * @note Calling that function reset the log level that has been specified by #linphone_logging_service_set_log_level(). + */ +LINPHONE_PUBLIC void linphone_logging_service_set_log_level_mask(LinphoneLoggingService *log_service, unsigned int mask); + +/** + * @brief Gets the log level mask. + */ +LINPHONE_PUBLIC unsigned int linphone_logging_service_get_log_level_mask(const LinphoneLoggingService *log_service); + +/** + * @brief Enables logging in a file. + * + * That function enables an internal log handler that writes log messages in + * log-rotated files. + * + * @param dir Directory where to create the distinct parts of the log. + * @param filename Name of the log file. + * @param max_size The maximal size of each part of the log. The log rotating is triggered + * each time the currently opened log part reach that limit. + */ +LINPHONE_PUBLIC void linphone_logging_service_set_log_file(const LinphoneLoggingService *service, const char *dir, const char *filename, size_t max_size); + + + + + +/** + * @brief Increases the reference counter. + */ +LINPHONE_PUBLIC LinphoneLoggingServiceCbs *linphone_logging_service_cbs_ref(LinphoneLoggingServiceCbs *cbs); + +/** + * @brief Decreases the reference counter. + * + * The object is automatically destroyed once the counter reach 0. + */ +LINPHONE_PUBLIC void linphone_logging_service_cbs_unref(LinphoneLoggingServiceCbs *cbs); + +/** + * @brief Sets the callback to call each time liblinphone writes a log message. + */ +LINPHONE_PUBLIC void linphone_logging_service_cbs_set_log_message_written(LinphoneLoggingServiceCbs *cbs, LinphoneLoggingServiceCbsLogMessageWrittenCb cb); + +/** + * @brief Gets the value of the message event callback. + */ +LINPHONE_PUBLIC LinphoneLoggingServiceCbsLogMessageWrittenCb linphone_logging_service_cbs_get_log_message_written(const LinphoneLoggingServiceCbs *cbs); + +/** + * @brief Pass a pointer on a custom object. + * + * That pointer can be get back by callbacks by using #linphone_logging_service_get_cbs() and #linphone_logging_service_cbs_get_user_data(). + */ +LINPHONE_PUBLIC void linphone_logging_service_cbs_set_user_data(LinphoneLoggingServiceCbs *cbs, void *user_data); + +/** + * @brief Gets the user_data pointer back. + */ +LINPHONE_PUBLIC void *linphone_logging_service_cbs_get_user_data(const LinphoneLoggingServiceCbs *cbs); + + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif // _LINPHONE_LOG_H_ diff --git a/src/c-wrapper/c-wrapper.h b/src/c-wrapper/c-wrapper.h index 9ebb30f72..e0109ce7c 100644 --- a/src/c-wrapper/c-wrapper.h +++ b/src/c-wrapper/c-wrapper.h @@ -100,6 +100,8 @@ BELLE_SIP_TYPE_ID(LinphoneImNotifPolicy), BELLE_SIP_TYPE_ID(LinphoneInfoMessage), BELLE_SIP_TYPE_ID(LinphoneLDAPContactProvider), BELLE_SIP_TYPE_ID(LinphoneLDAPContactSearch), +BELLE_SIP_TYPE_ID(LinphoneLoggingService), +BELLE_SIP_TYPE_ID(LinphoneLoggingServiceCbs), BELLE_SIP_TYPE_ID(LinphoneNatPolicy), BELLE_SIP_TYPE_ID(LinphonePayloadType), BELLE_SIP_TYPE_ID(LinphonePlayer), diff --git a/tester/tester.c b/tester/tester.c index c47cff87f..6eaafeab9 100644 --- a/tester/tester.c +++ b/tester/tester.c @@ -19,6 +19,8 @@ #include #include #include "linphone/core.h" +#include "linphone/logging.h" +#include "logging-private.h" #include "liblinphone_tester.h" #include #include "tester_utils.h" @@ -503,7 +505,7 @@ void linphone_core_manager_uninit(LinphoneCoreManager *mgr) { linphone_core_cbs_unref(mgr->cbs); manager_count--; - linphone_core_set_log_level(old_log_level); + linphone_core_set_log_level_mask(old_log_level); } void linphone_core_manager_wait_for_stun_resolution(LinphoneCoreManager *mgr) { diff --git a/wrappers/cpp/class_impl.mustache b/wrappers/cpp/class_impl.mustache index 3002c3c9c..f780ed6e5 100644 --- a/wrappers/cpp/class_impl.mustache +++ b/wrappers/cpp/class_impl.mustache @@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include #include #include +#include #include "linphone++/linphone.hh" #include "tools.hh"