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
f363fff1
Commit
f363fff1
authored
May 09, 2015
by
Denis Ivaykin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
async auto flush
parent
9cad840a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
19 deletions
+42
-19
async_logger.h
include/spdlog/async_logger.h
+6
-3
async_log_helper.h
include/spdlog/details/async_log_helper.h
+27
-10
async_logger_impl.h
include/spdlog/details/async_logger_impl.h
+9
-6
No files found.
include/spdlog/async_logger.h
View file @
f363fff1
...
...
@@ -58,19 +58,22 @@ public:
const
It
&
end
,
size_t
queue_size
,
const
async_overflow_policy
overflow_policy
=
async_overflow_policy
::
block_retry
,
const
std
::
function
<
void
()
>&
worker_warmup_cb
=
nullptr
);
const
std
::
function
<
void
()
>&
worker_warmup_cb
=
nullptr
,
const
std
::
chrono
::
milliseconds
auto_flush_millis
=
std
::
chrono
::
milliseconds
::
zero
());
async_logger
(
const
std
::
string
&
logger_name
,
sinks_init_list
sinks
,
size_t
queue_size
,
const
async_overflow_policy
overflow_policy
=
async_overflow_policy
::
block_retry
,
const
std
::
function
<
void
()
>&
worker_warmup_cb
=
nullptr
);
const
std
::
function
<
void
()
>&
worker_warmup_cb
=
nullptr
,
const
std
::
chrono
::
milliseconds
auto_flush_millis
=
std
::
chrono
::
milliseconds
::
zero
());
async_logger
(
const
std
::
string
&
logger_name
,
sink_ptr
single_sink
,
size_t
queue_size
,
const
async_overflow_policy
overflow_policy
=
async_overflow_policy
::
block_retry
,
const
std
::
function
<
void
()
>&
worker_warmup_cb
=
nullptr
);
const
std
::
function
<
void
()
>&
worker_warmup_cb
=
nullptr
,
const
std
::
chrono
::
milliseconds
auto_flush_millis
=
std
::
chrono
::
milliseconds
::
zero
());
protected
:
...
...
include/spdlog/details/async_log_helper.h
View file @
f363fff1
...
...
@@ -65,7 +65,7 @@ class async_log_helper
async_msg
()
=
default
;
~
async_msg
()
=
default
;
async_msg
(
async_msg
&&
other
)
SPDLOG_NOEXCEPT
:
async_msg
(
async_msg
&&
other
)
SPDLOG_NOEXCEPT
:
logger_name
(
std
::
move
(
other
.
logger_name
)),
level
(
std
::
move
(
other
.
level
)),
time
(
std
::
move
(
other
.
time
)),
...
...
@@ -119,7 +119,8 @@ public:
const
std
::
vector
<
sink_ptr
>&
sinks
,
size_t
queue_size
,
const
async_overflow_policy
overflow_policy
=
async_overflow_policy
::
block_retry
,
const
std
::
function
<
void
()
>&
worker_warmup_cb
=
nullptr
);
const
std
::
function
<
void
()
>&
worker_warmup_cb
=
nullptr
,
const
std
::
chrono
::
milliseconds
auto_flush_millis
=
std
::
chrono
::
milliseconds
::
zero
());
void
log
(
const
details
::
log_msg
&
msg
);
...
...
@@ -145,6 +146,9 @@ private:
// worker thread warmup callback - one can set thread priority, affinity, etc
const
std
::
function
<
void
()
>
_worker_warmup_cb
;
// auto periodic sink flush parameter
const
std
::
chrono
::
milliseconds
_auto_flush_millis
;
// worker thread
std
::
thread
_worker_thread
;
...
...
@@ -159,7 +163,7 @@ private:
bool
process_next_msg
(
clock
::
time_point
&
last_pop
);
// sleep,yield or return immediatly using the time passed since last message as a hint
static
void
sleep_or_yield
(
const
clock
::
time_point
&
last_op_time
);
static
std
::
chrono
::
nanoseconds
sleep_or_yield
(
const
clock
::
time_point
&
last_op_time
);
};
}
...
...
@@ -168,12 +172,13 @@ private:
///////////////////////////////////////////////////////////////////////////////
// async_sink class implementation
///////////////////////////////////////////////////////////////////////////////
inline
spdlog
::
details
::
async_log_helper
::
async_log_helper
(
formatter_ptr
formatter
,
const
std
::
vector
<
sink_ptr
>&
sinks
,
size_t
queue_size
,
const
async_overflow_policy
overflow_policy
,
const
std
::
function
<
void
()
>&
worker_warmup_cb
)
:
inline
spdlog
::
details
::
async_log_helper
::
async_log_helper
(
formatter_ptr
formatter
,
const
std
::
vector
<
sink_ptr
>&
sinks
,
size_t
queue_size
,
const
async_overflow_policy
overflow_policy
,
const
std
::
function
<
void
()
>&
worker_warmup_cb
,
const
std
::
chrono
::
milliseconds
auto_flush_millis
)
:
_formatter
(
formatter
),
_sinks
(
sinks
),
_q
(
queue_size
),
_overflow_policy
(
overflow_policy
),
_worker_warmup_cb
(
worker_warmup_cb
),
_auto_flush_millis
(
auto_flush_millis
),
_worker_thread
(
&
async_log_helper
::
worker_loop
,
this
)
{}
...
...
@@ -249,7 +254,12 @@ inline bool spdlog::details::async_log_helper::process_next_msg(clock::time_poin
}
else
//empty queue
{
sleep_or_yield
(
last_pop
);
auto
time_since_op
=
sleep_or_yield
(
last_pop
);
if
(
_auto_flush_millis
>
std
::
chrono
::
milliseconds
::
zero
()
&&
time_since_op
>
_auto_flush_millis
)
{
for
(
auto
&
s
:
_sinks
)
s
->
flush
();
}
}
return
true
;
}
...
...
@@ -261,7 +271,7 @@ inline void spdlog::details::async_log_helper::set_formatter(formatter_ptr msg_f
// sleep,yield or return immediatly using the time passed since last message as a hint
inline
void
spdlog
::
details
::
async_log_helper
::
sleep_or_yield
(
const
clock
::
time_point
&
last_op_time
)
inline
std
::
chrono
::
nanoseconds
spdlog
::
details
::
async_log_helper
::
sleep_or_yield
(
const
clock
::
time_point
&
last_op_time
)
{
using
std
::
chrono
::
milliseconds
;
using
namespace
std
::
this_thread
;
...
...
@@ -270,18 +280,25 @@ inline void spdlog::details::async_log_helper::sleep_or_yield(const clock::time_
// spin upto 1 ms
if
(
time_since_op
<=
milliseconds
(
1
))
return
;
return
time_since_op
;
// yield upto 10ms
if
(
time_since_op
<=
milliseconds
(
10
))
return
yield
();
{
yield
();
return
time_since_op
;
}
// sleep for half of duration since last op
if
(
time_since_op
<=
milliseconds
(
100
))
return
sleep_for
(
time_since_op
/
2
);
{
sleep_for
(
time_since_op
/
2
);
return
time_since_op
;
}
return
sleep_for
(
milliseconds
(
100
));
sleep_for
(
milliseconds
(
100
));
return
time_since_op
;
}
// throw if the worker thread threw an exception or not active
...
...
include/spdlog/details/async_logger_impl.h
View file @
f363fff1
...
...
@@ -39,9 +39,10 @@ inline spdlog::async_logger::async_logger(const std::string& logger_name,
const
It
&
end
,
size_t
queue_size
,
const
async_overflow_policy
overflow_policy
,
const
std
::
function
<
void
()
>&
worker_warmup_cb
)
:
const
std
::
function
<
void
()
>&
worker_warmup_cb
,
const
std
::
chrono
::
milliseconds
auto_flush_millis
)
:
logger
(
logger_name
,
begin
,
end
),
_async_log_helper
(
new
details
::
async_log_helper
(
_formatter
,
_sinks
,
queue_size
,
overflow_policy
,
worker_warmup_cb
))
_async_log_helper
(
new
details
::
async_log_helper
(
_formatter
,
_sinks
,
queue_size
,
overflow_policy
,
worker_warmup_cb
,
auto_flush_millis
))
{
}
...
...
@@ -49,15 +50,17 @@ inline spdlog::async_logger::async_logger(const std::string& logger_name,
sinks_init_list
sinks
,
size_t
queue_size
,
const
async_overflow_policy
overflow_policy
,
const
std
::
function
<
void
()
>&
worker_warmup_cb
)
:
async_logger
(
logger_name
,
sinks
.
begin
(),
sinks
.
end
(),
queue_size
,
overflow_policy
,
worker_warmup_cb
)
{}
const
std
::
function
<
void
()
>&
worker_warmup_cb
,
const
std
::
chrono
::
milliseconds
auto_flush_millis
)
:
async_logger
(
logger_name
,
sinks
.
begin
(),
sinks
.
end
(),
queue_size
,
overflow_policy
,
worker_warmup_cb
,
auto_flush_millis
)
{}
inline
spdlog
::
async_logger
::
async_logger
(
const
std
::
string
&
logger_name
,
sink_ptr
single_sink
,
size_t
queue_size
,
const
async_overflow_policy
overflow_policy
,
const
std
::
function
<
void
()
>&
worker_warmup_cb
)
:
async_logger
(
logger_name
,
{
single_sink
},
queue_size
,
overflow_policy
,
worker_warmup_cb
)
{}
const
std
::
function
<
void
()
>&
worker_warmup_cb
,
const
std
::
chrono
::
milliseconds
auto_flush_millis
)
:
async_logger
(
logger_name
,
{
single_sink
},
queue_size
,
overflow_policy
,
worker_warmup_cb
,
auto_flush_millis
)
{}
inline
void
spdlog
::
async_logger
::
_set_formatter
(
spdlog
::
formatter_ptr
msg_formatter
)
...
...
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