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
051dacaf
Commit
051dacaf
authored
Mar 24, 2017
by
Ronan Abhamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(src/app/Logger): use a relative context path and thread safe
parent
a4dd00e1
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
124 additions
and
43 deletions
+124
-43
CMakeLists.txt
linphone-desktop/CMakeLists.txt
+1
-0
App.cpp
linphone-desktop/src/app/App.cpp
+4
-3
Logger.cpp
linphone-desktop/src/app/Logger.cpp
+59
-36
Logger.hpp
linphone-desktop/src/app/Logger.hpp
+17
-4
utils.cpp
linphone-desktop/src/utils.cpp
+41
-0
utils.hpp
linphone-desktop/src/utils.hpp
+2
-0
No files found.
linphone-desktop/CMakeLists.txt
View file @
051dacaf
...
...
@@ -106,6 +106,7 @@ set(SOURCES
src/components/timeline/TimelineModel.cpp
src/externals/single-application/SingleApplication.cpp
src/main.cpp
src/utils.cpp
)
set
(
HEADERS
...
...
linphone-desktop/src/app/App.cpp
View file @
051dacaf
...
...
@@ -176,11 +176,12 @@ void App::parseArgs () {
m_parser
.
process
(
*
this
);
// Initialise logger (do not do this before this point because the application has to be created
// for the logs to be put in the correct directory
// Initialize logger. (Do not do this before this point because the
// application has to be created for the logs to be put in the correct
// directory.)
Logger
::
init
();
if
(
m_parser
.
isSet
(
"verbose"
))
{
Logger
::
i
nstance
()
->
setVerbose
(
true
);
Logger
::
getI
nstance
()
->
setVerbose
(
true
);
}
}
...
...
linphone-desktop/src/app/Logger.cpp
View file @
051dacaf
...
...
@@ -24,6 +24,7 @@
#include <linphone/linphonecore.h>
#include <QDateTime>
#include "../utils.hpp"
#include "Paths.hpp"
#include "Logger.hpp"
...
...
@@ -48,13 +49,50 @@
#define MAX_LOGS_COLLECTION_SIZE 104857600
/* 100MB. */
#define SRC_PATTERN "/linphone-desktop/src/"
using
namespace
std
;
// =============================================================================
QMutex
Logger
::
m_mutex
;
Logger
*
Logger
::
m_instance
=
nullptr
;
// -----------------------------------------------------------------------------
static
void
qtLogger
(
QtMsgType
type
,
const
QMessageLogContext
&
context
,
const
QString
&
msg
)
{
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][Critical]"
YELLOW
"Core:%s: "
RESET
"%s
\n
"
;
else
if
(
type
==
ORTP_FATAL
)
format
=
RED
"[%s][Fatal]"
YELLOW
"Core:%s: "
RESET
"%s
\n
"
;
else
return
;
QByteArray
date_time
=
QDateTime
::
currentDateTime
().
toString
(
"HH:mm:ss"
).
toLocal8Bit
();
char
*
msg
=
bctbx_strdup_vprintf
(
fmt
,
args
);
fprintf
(
stderr
,
format
,
date_time
.
constData
(),
domain
,
msg
);
bctbx_free
(
msg
);
if
(
type
==
ORTP_FATAL
)
abort
();
}
// -----------------------------------------------------------------------------
void
Logger
::
log
(
QtMsgType
type
,
const
QMessageLogContext
&
context
,
const
QString
&
msg
)
{
const
char
*
format
;
BctbxLogLevel
level
;
...
...
@@ -79,48 +117,33 @@ static void qtLogger (QtMsgType type, const QMessageLogContext &context, const Q
const
char
*
context_str
=
""
;
#ifdef QT_MESSAGELOGCONTEXT
QByteArray
context_arr
=
QStringLiteral
(
"%1:%2: "
).
arg
(
context
.
file
).
arg
(
context
.
line
).
toLocal8Bit
();
context_str
=
context_arr
.
constData
();
#endif // ifdef QT_MESSAGELOGCONTEXT
QByteArray
local_msg
=
msg
.
toLocal8Bit
();
QByteArray
date_time
=
QDateTime
::
currentDateTime
().
toString
(
"HH:mm:ss"
).
toLocal8Bit
();
fprintf
(
stderr
,
format
,
date_time
.
constData
(),
context_str
,
local_msg
.
constData
());
bctbx_log
(
QT_DOMAIN
,
level
,
"QT: %s%s"
,
context_str
,
local_msg
.
constData
());
QByteArray
context_arr
;
if
(
type
==
QtFatalMsg
)
abort
();
}
// -----------------------------------------------------------------------------
{
const
char
*
file
=
context
.
file
;
const
char
*
pos
=
file
?
::
Utils
::
rstrstr
(
file
,
SRC_PATTERN
)
:
file
;
static
void
linphoneLogger
(
const
char
*
domain
,
OrtpLogLevel
type
,
const
char
*
fmt
,
va_list
args
)
{
const
char
*
format
;
context_arr
=
QStringLiteral
(
"%1:%2: "
)
.
arg
(
pos
?
pos
+
sizeof
(
SRC_PATTERN
)
-
1
:
file
)
.
arg
(
context
.
line
)
.
toLocal8Bit
();
context_str
=
context_arr
.
constData
();
}
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][Critical]"
YELLOW
"Core:%s: "
RESET
"%s
\n
"
;
else
if
(
type
==
ORTP_FATAL
)
format
=
RED
"[%s][Fatal]"
YELLOW
"Core:%s: "
RESET
"%s
\n
"
;
else
return
;
#endif // ifdef QT_MESSAGELOGCONTEXT
QByteArray
local_msg
=
msg
.
toLocal8Bit
();
QByteArray
date_time
=
QDateTime
::
currentDateTime
().
toString
(
"HH:mm:ss"
).
toLocal8Bit
();
char
*
msg
=
bctbx_strdup_vprintf
(
fmt
,
args
);
fprintf
(
stderr
,
format
,
date_time
.
constData
(),
domain
,
msg
);
m_mutex
.
lock
(
);
bctbx_free
(
msg
);
fprintf
(
stderr
,
format
,
date_time
.
constData
(),
context_str
,
local_msg
.
constData
());
bctbx_log
(
QT_DOMAIN
,
level
,
"QT: %s%s"
,
context_str
,
local_msg
.
constData
());
if
(
type
==
ORTP_FATAL
)
m_mutex
.
unlock
();
if
(
type
==
QtFatalMsg
)
abort
();
}
...
...
@@ -131,13 +154,13 @@ void Logger::init () {
return
;
m_instance
=
new
Logger
();
qInstallMessageHandler
(
qtLogger
);
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
(
m_instance
->
isVerbose
())
linphoneLog
ger
(
domain
,
type
,
fmt
,
args
);
linphoneLog
(
domain
,
type
,
fmt
,
args
);
}
);
...
...
linphone-desktop/src/app/Logger.hpp
View file @
051dacaf
...
...
@@ -23,23 +23,36 @@
#ifndef LOGGER_H_
#define LOGGER_H_
#include <Q
tGlobal
>
#include <Q
Mutex
>
// =============================================================================
class
Logger
{
public:
~
Logger
()
=
default
;
bool
isVerbose
()
const
{
return
m_verbose
;
}
void
setVerbose
(
bool
verbose
)
{
m_verbose
=
verbose
;
}
static
void
init
();
static
Logger
*
instance
()
{
return
m_instance
;
};
bool
isVerbose
()
const
{
return
m_verbose
;
};
void
setVerbose
(
bool
verbose
)
{
m_verbose
=
verbose
;
};
static
Logger
*
getInstance
()
{
return
m_instance
;
}
private:
Logger
()
=
default
;
static
void
log
(
QtMsgType
type
,
const
QMessageLogContext
&
context
,
const
QString
&
msg
);
bool
m_verbose
=
false
;
static
QMutex
m_mutex
;
static
Logger
*
m_instance
;
};
...
...
linphone-desktop/src/utils.cpp
0 → 100644
View file @
051dacaf
/*
* utils.cpp
* Copyright (C) 2017 Belledonne Communications, Grenoble, France
*
* 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.
*
* Created on: March 24, 2017
* Author: Ronan Abhamon
*/
#include "utils.hpp"
// =============================================================================
char
*
Utils
::
rstrstr
(
const
char
*
a
,
const
char
*
b
)
{
size_t
a_len
=
strlen
(
a
);
size_t
b_len
=
strlen
(
b
);
const
char
*
s
;
if
(
b_len
>
a_len
)
return
NULL
;
for
(
s
=
a
+
a_len
-
b_len
;
s
>=
a
;
--
s
)
{
if
(
!
strncmp
(
s
,
b
,
b_len
))
return
const_cast
<
char
*>
(
s
);
}
return
NULL
;
}
linphone-desktop/src/utils.hpp
View file @
051dacaf
...
...
@@ -49,6 +49,8 @@ namespace Utils {
return
findParentType
<
T
>
(
parent
);
}
char
*
rstrstr
(
const
char
*
a
,
const
char
*
b
);
}
#endif // UTILS_H_
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