Commit d24be527 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(Logger): use C++ API now, remove link to lib linphone C

parent 52ac3d09
......@@ -91,12 +91,10 @@ endif ()
set(QT5_PACKAGES_OPTIONAL TextToSpeech)
if (LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
include("${EP_linphone_CONFIG_DIR}/LinphoneConfig.cmake")
include("${EP_linphone_CONFIG_DIR}/wrappers/cpp/LinphoneCxxConfig.cmake")
include("${EP_bctoolbox_CONFIG_DIR}/BcToolboxConfig.cmake")
include("${EP_belcard_CONFIG_DIR}/BelcardConfig.cmake")
else ()
find_package(Linphone REQUIRED)
find_package(LinphoneCxx REQUIRED)
find_package(BcToolbox REQUIRED)
find_package(Belcard REQUIRED)
......@@ -359,8 +357,8 @@ endif ()
set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME "${EXECUTABLE_NAME}")
set_target_properties(${TESTER_TARGET_NAME} PROPERTIES OUTPUT_NAME "${TESTER_EXECUTABLE_NAME}")
set(INCLUDED_DIRECTORIES "${LINPHONECXX_INCLUDE_DIRS}" "${LINPHONE_INCLUDE_DIRS}" "${BELCARD_INCLUDE_DIRS}" "${BCTOOLBOX_INCLUDE_DIRS}")
set(LIBRARIES ${BCTOOLBOX_CORE_LIBRARIES} ${BELCARD_LIBRARIES} ${LINPHONE_LIBRARIES} ${LINPHONECXX_LIBRARIES})
set(INCLUDED_DIRECTORIES "${LINPHONECXX_INCLUDE_DIRS}" "${BELCARD_INCLUDE_DIRS}" "${BCTOOLBOX_INCLUDE_DIRS}")
set(LIBRARIES ${BCTOOLBOX_CORE_LIBRARIES} ${BELCARD_LIBRARIES} ${LINPHONECXX_LIBRARIES})
foreach (package ${QT5_PACKAGES})
list(APPEND INCLUDED_DIRECTORIES "${Qt5${package}_INCLUDE_DIRS}")
......
......@@ -21,7 +21,6 @@
*/
#include <bctoolbox/logging.h>
#include <linphone/linphonecore.h>
#include <QDateTime>
#include <QThread>
......@@ -68,34 +67,56 @@ static inline QByteArray getFormattedCurrentTime () {
// -----------------------------------------------------------------------------
static void linphoneLog (const char *domain, OrtpLogLevel type, const char *fmt, va_list args) {
const char *format;
if (type == ORTP_DEBUG)
format = GREEN "[%s][Debug]" YELLOW "Core:%s: " RESET "%s\n";
else if (type == ORTP_TRACE)
format = BLUE "[%s][Trace]" YELLOW "Core:%s: " RESET "%s\n";
else if (type == ORTP_MESSAGE)
format = BLUE "[%s][Info]" YELLOW "Core:%s: " RESET "%s\n";
else if (type == ORTP_WARNING)
format = RED "[%s][Warning]" YELLOW "Core:%s: " RESET "%s\n";
else if (type == ORTP_ERROR)
format = RED "[%s][Error]" YELLOW "Core:%s: " RESET "%s\n";
else if (type == ORTP_FATAL)
format = RED "[%s][Fatal]" YELLOW "Core:%s: " RESET "%s\n";
else
return;
QByteArray dateTime = ::getFormattedCurrentTime();
char *msg = bctbx_strdup_vprintf(fmt, args);
class LinphoneLogger : public linphone::LoggingServiceListener {
public:
LinphoneLogger (const Logger *logger) : mLogger(logger) {}
private:
void onLogMessageWritten (
const shared_ptr<linphone::LoggingService> &,
const string &domain,
linphone::LogLevel level,
const string &message
) override {
if (!mLogger->isVerbose())
return;
const char *format;
switch (level) {
case linphone::LogLevel::LogLevelDebug:
format = GREEN "[%s][Debug]" YELLOW "Core:%s: " RESET "%s\n";
break;
case linphone::LogLevel::LogLevelTrace:
format = BLUE "[%s][Trace]" YELLOW "Core:%s: " RESET "%s\n";
break;
case linphone::LogLevel::LogLevelMessage:
format = BLUE "[%s][Info]" YELLOW "Core:%s: " RESET "%s\n";
break;
case linphone::LogLevel::LogLevelWarning:
format = RED "[%s][Warning]" YELLOW "Core:%s: " RESET "%s\n";
break;
case linphone::LogLevel::LogLevelError:
format = RED "[%s][Error]" YELLOW "Core:%s: " RESET "%s\n";
break;
case linphone::LogLevel::LogLevelFatal:
format = RED "[%s][Fatal]" YELLOW "Core:%s: " RESET "%s\n";
break;
}
fprintf(stderr, format, dateTime.constData(), domain ? domain : "linphone", msg);
fprintf(
stderr,
format,
::getFormattedCurrentTime().constData(),
domain.empty() ? domain.c_str() : "linphone",
message.c_str()
);
bctbx_free(msg);
if (level == linphone::LogLevel::LogLevelFatal)
terminate();
};
if (type == ORTP_FATAL)
abort();
}
const Logger *mLogger;
};
// -----------------------------------------------------------------------------
......@@ -150,13 +171,17 @@ void Logger::log (QtMsgType type, const QMessageLogContext &context, const QStri
mMutex.unlock();
if (type == QtFatalMsg)
abort();
terminate();
}
// -----------------------------------------------------------------------------
void Logger::enable (bool status) {
linphone_core_enable_log_collection(status ? LinphoneLogCollectionEnabled : LinphoneLogCollectionDisabled);
linphone::Core::enableLogCollection(
status
? linphone::LogCollectionStateEnabled
: linphone::LogCollectionStateDisabled
);
}
void Logger::init (const shared_ptr<linphone::Config> &config) {
......@@ -170,14 +195,14 @@ void Logger::init (const shared_ptr<linphone::Config> &config) {
qInstallMessageHandler(Logger::log);
linphone_core_set_log_level(ORTP_MESSAGE);
linphone_core_set_log_handler([](const char *domain, OrtpLogLevel type, const char *fmt, va_list args) {
if (mInstance->isVerbose())
::linphoneLog(domain, type, fmt, args);
});
{
shared_ptr<linphone::LoggingService> loggingService = linphone::LoggingService::get();
loggingService->setLogLevel(linphone::LogLevel::LogLevelMessage);
loggingService->setListener(make_shared<LinphoneLogger>(mInstance));
}
linphone_core_set_log_collection_path(::Utils::appStringToCoreString(folder).c_str());
linphone::Core::setLogCollectionPath(::Utils::appStringToCoreString(folder));
linphone::Core::setLogCollectionMaxFileSize(MAX_LOGS_COLLECTION_SIZE);
linphone_core_set_log_collection_max_file_size(MAX_LOGS_COLLECTION_SIZE);
mInstance->enable(SettingsModel::getLogsEnabled(config));
}
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