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
b67076fc
Commit
b67076fc
authored
Sep 12, 2016
by
davide
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added level_t to sink. Improves the flexibility of loggers with multiple sinks
parent
c69df8ae
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
8 deletions
+41
-8
example/CMakeLists.txt
example/CMakeLists.txt
+3
-0
include/spdlog/details/async_log_helper.h
include/spdlog/details/async_log_helper.h
+5
-3
include/spdlog/details/logger_impl.h
include/spdlog/details/logger_impl.h
+5
-2
include/spdlog/sinks/dist_sink.h
include/spdlog/sinks/dist_sink.h
+5
-3
include/spdlog/sinks/sink.h
include/spdlog/sinks/sink.h
+23
-0
No files found.
example/CMakeLists.txt
View file @
b67076fc
...
@@ -40,6 +40,9 @@ target_link_libraries(example spdlog::spdlog ${CMAKE_THREAD_LIBS_INIT})
...
@@ -40,6 +40,9 @@ target_link_libraries(example spdlog::spdlog ${CMAKE_THREAD_LIBS_INIT})
add_executable
(
benchmark bench.cpp
)
add_executable
(
benchmark bench.cpp
)
target_link_libraries
(
benchmark spdlog::spdlog
${
CMAKE_THREAD_LIBS_INIT
}
)
target_link_libraries
(
benchmark spdlog::spdlog
${
CMAKE_THREAD_LIBS_INIT
}
)
add_executable
(
multisink multisink.cpp
)
target_link_libraries
(
multisink spdlog::spdlog
${
CMAKE_THREAD_LIBS_INIT
}
)
enable_testing
()
enable_testing
()
file
(
MAKE_DIRECTORY
"
${
CMAKE_CURRENT_BINARY_DIR
}
/logs"
)
file
(
MAKE_DIRECTORY
"
${
CMAKE_CURRENT_BINARY_DIR
}
/logs"
)
add_test
(
NAME RunExample COMMAND example
)
add_test
(
NAME RunExample COMMAND example
)
...
...
include/spdlog/details/async_log_helper.h
View file @
b67076fc
...
@@ -303,8 +303,11 @@ inline bool spdlog::details::async_log_helper::process_next_msg(log_clock::time_
...
@@ -303,8 +303,11 @@ inline bool spdlog::details::async_log_helper::process_next_msg(log_clock::time_
log_msg
incoming_log_msg
;
log_msg
incoming_log_msg
;
incoming_async_msg
.
fill_log_msg
(
incoming_log_msg
);
incoming_async_msg
.
fill_log_msg
(
incoming_log_msg
);
_formatter
->
format
(
incoming_log_msg
);
_formatter
->
format
(
incoming_log_msg
);
for
(
auto
&
s
:
_sinks
)
for
(
auto
&
s
:
_sinks
){
s
->
log
(
incoming_log_msg
);
if
(
s
->
should_log
(
incoming_log_msg
.
level
)){
s
->
log
(
incoming_log_msg
);
}
}
}
}
return
true
;
return
true
;
}
}
...
@@ -317,7 +320,6 @@ inline bool spdlog::details::async_log_helper::process_next_msg(log_clock::time_
...
@@ -317,7 +320,6 @@ inline bool spdlog::details::async_log_helper::process_next_msg(log_clock::time_
handle_flush_interval
(
now
,
last_flush
);
handle_flush_interval
(
now
,
last_flush
);
sleep_or_yield
(
now
,
last_pop
);
sleep_or_yield
(
now
,
last_pop
);
return
!
_terminate_requested
;
return
!
_terminate_requested
;
}
}
}
}
...
...
include/spdlog/details/logger_impl.h
View file @
b67076fc
...
@@ -245,8 +245,11 @@ inline bool spdlog::logger::should_log(spdlog::level::level_enum msg_level) cons
...
@@ -245,8 +245,11 @@ inline bool spdlog::logger::should_log(spdlog::level::level_enum msg_level) cons
inline
void
spdlog
::
logger
::
_sink_it
(
details
::
log_msg
&
msg
)
inline
void
spdlog
::
logger
::
_sink_it
(
details
::
log_msg
&
msg
)
{
{
_formatter
->
format
(
msg
);
_formatter
->
format
(
msg
);
for
(
auto
&
sink
:
_sinks
)
for
(
auto
&
sink
:
_sinks
){
sink
->
log
(
msg
);
if
(
sink
->
should_log
(
msg
.
level
)){
sink
->
log
(
msg
);
}
}
if
(
_should_flush_on
(
msg
))
if
(
_should_flush_on
(
msg
))
flush
();
flush
();
...
...
include/spdlog/sinks/dist_sink.h
View file @
b67076fc
...
@@ -35,11 +35,13 @@ protected:
...
@@ -35,11 +35,13 @@ protected:
void
_sink_it
(
const
details
::
log_msg
&
msg
)
override
void
_sink_it
(
const
details
::
log_msg
&
msg
)
override
{
{
for
(
auto
&
sink
:
_sinks
)
for
(
auto
&
sink
:
_sinks
){
sink
->
log
(
msg
);
if
(
sink
->
should_log
(
msg
.
level
)){
sink
->
log
(
msg
);
}
}
}
}
public:
public:
void
flush
()
override
void
flush
()
override
{
{
...
...
include/spdlog/sinks/sink.h
View file @
b67076fc
...
@@ -15,10 +15,33 @@ namespace sinks
...
@@ -15,10 +15,33 @@ namespace sinks
class
sink
class
sink
{
{
public:
public:
sink
()
:
_level
(
level
::
trace
)
{}
virtual
~
sink
()
{}
virtual
~
sink
()
{}
virtual
void
log
(
const
details
::
log_msg
&
msg
)
=
0
;
virtual
void
log
(
const
details
::
log_msg
&
msg
)
=
0
;
virtual
void
flush
()
=
0
;
virtual
void
flush
()
=
0
;
bool
should_log
(
level
::
level_enum
msg_level
)
const
;
void
set_level
(
level
::
level_enum
log_level
);
level
::
level_enum
level
()
const
;
private:
level_t
_level
;
};
};
inline
bool
sink
::
should_log
(
level
::
level_enum
msg_level
)
const
{
return
msg_level
>=
_level
.
load
(
std
::
memory_order_relaxed
);
}
inline
void
sink
::
set_level
(
level
::
level_enum
log_level
)
{
_level
.
store
(
log_level
);
}
inline
level
::
level_enum
sink
::
level
()
const
{
return
static_cast
<
spdlog
::
level
::
level_enum
>
(
_level
.
load
(
std
::
memory_order_relaxed
));
}
}
}
}
}
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