Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
spdlog
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
spdlog
Commits
57dc8773
Commit
57dc8773
authored
May 15, 2017
by
Gabi Melman
Committed by
GitHub
May 15, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #443 from alzix/revert-411
Revert "Merge pull request #441 from alzix/count_discarded"
parents
13199034
6547675e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
87 deletions
+9
-87
async_log_helper.h
include/spdlog/details/async_log_helper.h
+9
-42
tweakme.h
include/spdlog/tweakme.h
+0
-7
async_logger.cpp
tests/async_logger.cpp
+0
-38
No files found.
include/spdlog/details/async_log_helper.h
View file @
57dc8773
...
...
@@ -27,7 +27,6 @@
#include <thread>
#include <utility>
#include <vector>
#include <atomic>
namespace
spdlog
{
...
...
@@ -186,12 +185,6 @@ private:
// wait until the queue is empty
void
wait_empty_q
();
// counter for messages discarded due to queue overflow
std
::
atomic
<
unsigned
int
>
_discarded_msg_count
;
// handle discarded messages
void
handle_discarded_msg
(
const
std
::
string
&
logger_name
);
};
}
}
...
...
@@ -218,8 +211,7 @@ inline spdlog::details::async_log_helper::async_log_helper(
_worker_warmup_cb
(
worker_warmup_cb
),
_flush_interval_ms
(
flush_interval_ms
),
_worker_teardown_cb
(
worker_teardown_cb
),
_worker_thread
(
&
async_log_helper
::
worker_loop
,
this
),
_discarded_msg_count
(
0
)
_worker_thread
(
&
async_log_helper
::
worker_loop
,
this
)
{}
// Send to the worker thread termination message(level=off)
...
...
@@ -245,24 +237,16 @@ inline void spdlog::details::async_log_helper::log(const details::log_msg& msg)
inline
void
spdlog
::
details
::
async_log_helper
::
push_msg
(
details
::
async_log_helper
::
async_msg
&&
new_msg
)
{
if
(
!
_q
.
enqueue
(
std
::
move
(
new_msg
)))
if
(
!
_q
.
enqueue
(
std
::
move
(
new_msg
))
&&
_overflow_policy
!=
async_overflow_policy
::
discard_log_msg
)
{
if
(
_overflow_policy
!=
async_overflow_policy
::
discard_log_msg
)
{
auto
last_op_time
=
details
::
os
::
now
();
auto
now
=
last_op_time
;
do
{
now
=
details
::
os
::
now
();
sleep_or_yield
(
now
,
last_op_time
);
}
while
(
!
_q
.
enqueue
(
std
::
move
(
new_msg
)));
}
else
auto
last_op_time
=
details
::
os
::
now
();
auto
now
=
last_op_time
;
do
{
#if defined(SPDLOG_ASYNC_COUNT_DISCARDED_MSG)
_discarded_msg_count
++
;
#endif
now
=
details
::
os
::
now
();
sleep_or_yield
(
now
,
last_op_time
);
}
while
(
!
_q
.
enqueue
(
std
::
move
(
new_msg
)));
}
}
...
...
@@ -321,10 +305,6 @@ inline bool spdlog::details::async_log_helper::process_next_msg(log_clock::time_
break
;
default
:
#if defined(SPDLOG_ASYNC_COUNT_DISCARDED_MSG)
handle_discarded_msg
(
incoming_async_msg
.
logger_name
);
#endif
log_msg
incoming_log_msg
;
incoming_async_msg
.
fill_log_msg
(
incoming_log_msg
);
_formatter
->
format
(
incoming_log_msg
);
...
...
@@ -409,18 +389,5 @@ inline void spdlog::details::async_log_helper::set_error_handler(spdlog::log_err
_err_handler
=
err_handler
;
}
inline
void
spdlog
::
details
::
async_log_helper
::
handle_discarded_msg
(
const
std
::
string
&
logger_name
)
{
unsigned
int
num_of_discarded_messages
=
_discarded_msg_count
.
exchange
(
0
);
if
(
num_of_discarded_messages
)
{
log_msg
discarded_warning_msg
(
&
logger_name
,
level
::
warn
);
discarded_warning_msg
.
raw
<<
"Discarded "
<<
num_of_discarded_messages
<<
" messages - logger queue overflow"
;
_formatter
->
format
(
discarded_warning_msg
);
for
(
auto
&
s
:
_sinks
)
{
s
->
log
(
discarded_warning_msg
);
}
}
}
include/spdlog/tweakme.h
View file @
57dc8773
...
...
@@ -120,10 +120,3 @@
//
// #define SPDLOG_FINAL final
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Uncomment to count and print warning message about number of dropped messages.
// Only relevant for async_logger with async_overflow_policy::discard_log_msg
//
// #define SPDLOG_ASYNC_COUNT_DISCARDED_MSG
///////////////////////////////////////////////////////////////////////////////
tests/async_logger.cpp
deleted
100644 → 0
View file @
13199034
#include <iostream>
#include "includes.h"
#include "../include/spdlog/common.h"
#include "../include/spdlog/tweakme.h"
TEST_CASE
(
"async_logging_overflow "
,
"[async_logging]"
)
{
std
::
string
filename
=
"logs/async_log_overflow.txt"
;
auto
sink
=
std
::
make_shared
<
spdlog
::
sinks
::
simple_file_sink_st
>
(
filename
,
true
);
auto
logger
=
std
::
make_shared
<
spdlog
::
async_logger
>
(
"overflow_logger"
,
sink
,
2
,
// queue size
spdlog
::
async_overflow_policy
::
discard_log_msg
);
for
(
int
i
=
0
;
i
<
8
;
i
++
)
{
logger
->
info
(
"Message #{}"
,
i
);
}
logger
->
flush
();
logger
.
reset
();
std
::
string
the_log
=
file_contents
(
filename
);
#if defined(SPDLOG_ASYNC_COUNT_DISCARDED_MSG)
std
::
cout
<<
the_log
<<
std
::
endl
;
REQUIRE
(
the_log
.
find
(
"Dropped 6 messages"
)
!=
std
::
string
::
npos
);
#endif
}
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