Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
20a32dcd
Commit
20a32dcd
authored
Jul 28, 2022
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
logger: cleanup FileLog
* move pending queue to the stack Change-Id: Ib44578aab4b8e27fd19ff564abab8d67e9b1ad00
parent
0a7809a5
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/logger.cpp
+28
-56
28 additions, 56 deletions
src/logger.cpp
with
28 additions
and
56 deletions
src/logger.cpp
+
28
−
56
View file @
20a32dcd
...
...
@@ -277,18 +277,14 @@ private:
std
::
atomic
<
bool
>
enabled_
;
};
class
ConsoleLog
:
public
jami
::
Logger
::
Handler
class
ConsoleLog
:
public
Logger
::
Handler
{
public:
static
ConsoleLog
&
instance
()
{
// This is an intentional memory leak!!!
//
// Some thread can still be logging after DRing::fini and even
// during the static destructors called by libstdc++. Thus, we
// allocate the logger on the heap and never free it.
// Intentional memory leak:
// Some thread can still be logging even during static destructors.
static
ConsoleLog
*
self
=
new
ConsoleLog
();
return
*
self
;
}
...
...
@@ -407,18 +403,14 @@ Logger::setConsoleLog(bool en)
#endif
}
class
SysLog
:
public
jami
::
Logger
::
Handler
class
SysLog
:
public
Logger
::
Handler
{
public:
static
SysLog
&
instance
()
{
// This is an intentional memory leak!!!
//
// Some thread can still be logging after DRing::fini and even
// during the static destructors called by libstdc++. Thus, we
// allocate the logger on the heap and never free it.
// Intentional memory leak:
// Some thread can still be logging even during static destructors.
static
SysLog
*
self
=
new
SysLog
();
return
*
self
;
}
...
...
@@ -453,18 +445,14 @@ Logger::setSysLog(bool en)
SysLog
::
instance
().
enable
(
en
);
}
class
MonitorLog
:
public
jami
::
Logger
::
Handler
class
MonitorLog
:
public
Logger
::
Handler
{
public:
static
MonitorLog
&
instance
()
{
// This is an intentional memory leak!!!
//
// Some thread can still be logging after DRing::fini and even
// during the static destructors called by libstdc++. Thus, we
// allocate the logger on the heap and never free it.
// Intentional memory leak
// Some thread can still be logging even during static destructors.
static
MonitorLog
*
self
=
new
MonitorLog
();
return
*
self
;
}
...
...
@@ -486,18 +474,14 @@ Logger::setMonitorLog(bool en)
MonitorLog
::
instance
().
enable
(
en
);
}
class
FileLog
:
public
jami
::
Logger
::
Handler
class
FileLog
:
public
Logger
::
Handler
{
public:
static
FileLog
&
instance
()
{
// This is an intentional memory leak!!!
//
// Some thread can still be logging after DRing::fini and even
// during the static destructors called by libstdc++. Thus, we
// allocate the logger on the heap and never free it.
// Intentional memory leak:
// Some thread can still be logging even during static destructors.
static
FileLog
*
self
=
new
FileLog
();
return
*
self
;
}
...
...
@@ -508,33 +492,28 @@ public:
thread_
.
join
();
}
if
(
file_
.
is_open
())
{
file_
.
close
();
}
std
::
ofstream
file
;
if
(
not
path
.
empty
())
{
file
_
.
open
(
path
,
std
::
ofstream
::
out
|
std
::
ofstream
::
app
);
file
.
open
(
path
,
std
::
ofstream
::
out
|
std
::
ofstream
::
app
);
enable
(
true
);
}
else
{
enable
(
false
);
return
;
}
thread_
=
std
::
thread
([
this
]
{
thread_
=
std
::
thread
([
this
,
file
=
std
::
move
(
file
)]()
mutable
{
std
::
vector
<
Logger
::
Msg
>
pendingQ_
;
while
(
isEnable
())
{
{
std
::
unique_lock
lk
(
mtx_
);
cv_
.
wait
(
lk
,
[
&
]
{
return
not
isEnable
()
or
not
currentQ_
.
empty
();
});
if
(
not
isEnable
())
{
if
(
not
isEnable
())
break
;
}
std
::
swap
(
currentQ_
,
pendingQ_
);
}
do_consume
(
pendingQ_
);
do_consume
(
file
,
pendingQ_
);
pendingQ_
.
clear
();
}
});
...
...
@@ -543,45 +522,38 @@ public:
~
FileLog
()
{
notify
([
=
]
{
enable
(
false
);
});
if
(
thread_
.
joinable
())
{
if
(
thread_
.
joinable
())
thread_
.
join
();
}
}
virtual
void
consume
(
jami
::
Logger
::
Msg
&
msg
)
override
virtual
void
consume
(
Logger
::
Msg
&
msg
)
override
{
notify
([
&
,
this
]
{
currentQ_
.
push
_back
(
std
::
move
(
msg
));
});
notify
([
&
,
this
]
{
currentQ_
.
emplace
_back
(
std
::
move
(
msg
));
});
}
private
:
template
<
typename
T
>
void
notify
(
T
func
)
{
std
::
unique_lock
lk
(
mtx_
);
std
::
lock_guard
lk
(
mtx_
);
func
();
cv_
.
notify_one
();
}
void
do_consume
(
const
std
::
vector
<
jami
::
Logger
::
Msg
>&
messages
)
void
do_consume
(
std
::
ofstream
&
file
,
const
std
::
vector
<
Logger
::
Msg
>&
messages
)
{
for
(
const
auto
&
msg
:
messages
)
{
file
_
<<
msg
.
header_
<<
msg
.
payload_
.
get
();
file
<<
msg
.
header_
<<
msg
.
payload_
.
get
();
if
(
msg
.
linefeed_
)
{
file_
<<
ENDL
;
}
if
(
msg
.
linefeed_
)
file
<<
ENDL
;
}
file_
.
flush
();
file
.
flush
();
}
std
::
vector
<
jami
::
Logger
::
Msg
>
currentQ_
;
std
::
vector
<
jami
::
Logger
::
Msg
>
pendingQ_
;
std
::
vector
<
Logger
::
Msg
>
currentQ_
;
std
::
mutex
mtx_
;
std
::
condition_variable
cv_
;
std
::
ofstream
file_
;
std
::
thread
thread_
;
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment