Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
spdlog
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
spdlog
Commits
fde3d2db
Commit
fde3d2db
authored
Feb 10, 2015
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
astyle+comments
parent
9f993da4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
17 deletions
+21
-17
bench/spdlog-async.cpp
bench/spdlog-async.cpp
+2
-2
example/example.cpp
example/example.cpp
+6
-3
include/spdlog/details/async_log_helper.h
include/spdlog/details/async_log_helper.h
+10
-9
include/spdlog/details/pattern_formatter_impl.h
include/spdlog/details/pattern_formatter_impl.h
+1
-1
include/spdlog/spdlog.h
include/spdlog/spdlog.h
+2
-2
No files found.
bench/spdlog-async.cpp
View file @
fde3d2db
...
...
@@ -19,9 +19,9 @@ int main(int argc, char* argv[])
int
thread_count
=
10
;
if
(
argc
>
1
)
thread_count
=
atoi
(
argv
[
1
]);
int
howmany
=
1000000
;
int
howmany
=
1000000
1
;
spd
::
set_async_mode
(
1048576
);
spd
::
set_async_mode
(
1048576
*
16
,
spd
::
async_overflow_policy
::
discard_log_msg
);
auto
logger
=
spdlog
::
create
<
spd
::
sinks
::
simple_file_sink_mt
>
(
"file_logger"
,
"logs/spd-bench-async.txt"
,
false
);
logger
->
set_pattern
(
"[%Y-%b-%d %T.%e]: %v"
);
...
...
example/example.cpp
View file @
fde3d2db
...
...
@@ -37,7 +37,7 @@ int main(int, char* [])
spd
::
set_level
(
spd
::
level
::
debug
);
// Create console, multithreaded logger
auto
console
=
spd
::
stdout_logger_mt
(
"console"
);
auto
console
=
spd
::
stdout_logger_mt
(
"console"
);
console
->
info
(
"Hello {}"
,
1
);
console
->
info
(
"An info message example {}.."
,
1
);
console
->
info
()
<<
"Streams are supported too "
<<
1
;
...
...
@@ -65,7 +65,7 @@ int main(int, char* [])
SPDLOG_TRACE
(
console
,
"Enabled only #ifdef SPDLOG_TRACE_ON..{} ,{}"
,
1
,
3.23
);
SPDLOG_DEBUG
(
console
,
"Enabled only #ifdef SPDLOG_DEBUG_ON.. {} ,{}"
,
1
,
3.23
);
// Asynchronous logging is very fast..
// Just call spdlog::set_async_mode(q_size) and all created loggers from now on will be asynchronous..
size_t
q_size
=
1048576
;
//queue size must be power of 2
...
...
@@ -94,7 +94,10 @@ int main(int, char* [])
// Example of user defined class with operator<<
//
class
some_class
{};
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
some_class
&
)
{
return
os
<<
"some_class"
;
}
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
some_class
&
)
{
return
os
<<
"some_class"
;
}
void
custom_class_example
()
{
...
...
include/spdlog/details/async_log_helper.h
View file @
fde3d2db
...
...
@@ -107,8 +107,9 @@ public:
void
log
(
const
details
::
log_msg
&
msg
);
//
S
top logging and join the back thread
//
s
top logging and join the back thread
~
async_log_helper
();
void
set_formatter
(
formatter_ptr
);
...
...
@@ -137,11 +138,11 @@ private:
// worker thread main loop
void
worker_loop
();
//pop next message from the queue and process it
//return true if a message was available (queue was not empty), will set the last_pop to the pop time
//
pop next message from the queue and process it
//
return true if a message was available (queue was not empty), will set the last_pop to the pop time
bool
process_next_msg
(
clock
::
time_point
&
last_pop
);
//
guess how much to sleep if queue is empty/full using last successful op time as
hint
//
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
);
};
...
...
@@ -210,8 +211,8 @@ inline void spdlog::details::async_log_helper::worker_loop()
}
}
//
P
rocess next message in the queue
//
R
eturn true if this thread should still be active (no msg with level::off was received)
//
p
rocess next message in the queue
//
r
eturn true if this thread should still be active (no msg with level::off was received)
inline
bool
spdlog
::
details
::
async_log_helper
::
process_next_msg
(
clock
::
time_point
&
last_pop
)
{
...
...
@@ -243,7 +244,7 @@ inline void spdlog::details::async_log_helper::set_formatter(formatter_ptr msg_f
}
//
S
leep,yield or return immediatly using the time passed since last message as a hint
//
s
leep,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
)
{
using
std
::
chrono
::
milliseconds
;
...
...
@@ -251,7 +252,7 @@ inline void spdlog::details::async_log_helper::sleep_or_yield(const clock::time_
auto
time_since_op
=
clock
::
now
()
-
last_op_time
;
//spin upto 1 ms
//
spin upto 1 ms
if
(
time_since_op
<=
milliseconds
(
1
))
return
;
...
...
@@ -267,7 +268,7 @@ inline void spdlog::details::async_log_helper::sleep_or_yield(const clock::time_
return
sleep_for
(
milliseconds
(
100
));
}
//throw if the worker thread threw an exception or not active
//
throw if the worker thread threw an exception or not active
inline
void
spdlog
::
details
::
async_log_helper
::
throw_if_bad_worker
()
{
if
(
_last_workerthread_ex
)
...
...
include/spdlog/details/pattern_formatter_impl.h
View file @
fde3d2db
...
...
@@ -490,7 +490,7 @@ inline void spdlog::pattern_formatter::handle_flag(char flag)
case
'L'
:
_formatters
.
push_back
(
std
::
unique_ptr
<
details
::
flag_formatter
>
(
new
details
::
short_level_formatter
()));
break
;
case
(
't'
)
:
_formatters
.
push_back
(
std
::
unique_ptr
<
details
::
flag_formatter
>
(
new
details
::
t_formatter
()));
break
;
...
...
include/spdlog/spdlog.h
View file @
fde3d2db
...
...
@@ -55,7 +55,7 @@ void set_pattern(const std::string& format_string);
void
set_formatter
(
formatter_ptr
f
);
//
// Set global logging level for
// Set global logging level for
//
void
set_level
(
level
::
level_enum
log_level
);
...
...
@@ -69,7 +69,7 @@ void set_level(level::level_enum log_level);
// async_overflow_policy::block_retry - if queue is full, block until queue has room for the new log entry.
// async_overflow_policy::discard_log_msg - never block and discard any new messages when queue overflows.
//
// worker_warmup_cb (optional):
// worker_warmup_cb (optional):
// callback function that will be called in worker thread upon start (can be used to init stuff like thread affinity)
//
void
set_async_mode
(
size_t
queue_size
,
const
async_overflow_policy
overflow_policy
=
async_overflow_policy
::
block_retry
,
const
std
::
function
<
void
()
>&
worker_warmup_cb
=
nullptr
);
...
...
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