Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
linphone-desktop
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
linphone-desktop
Commits
d24be527
Commit
d24be527
authored
Jan 23, 2018
by
Ronan Abhamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(Logger): use C++ API now, remove link to lib linphone C
parent
52ac3d09
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
39 deletions
+62
-39
CMakeLists.txt
CMakeLists.txt
+2
-4
Logger.cpp
src/app/logger/Logger.cpp
+60
-35
No files found.
CMakeLists.txt
View file @
d24be527
...
...
@@ -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
}
${
LINPHONE
CXX_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
}
"
)
...
...
src/app/logger/Logger.cpp
View file @
d24be527
...
...
@@ -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
));
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment