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
4efbd950
Commit
4efbd950
authored
Aug 20, 2016
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
atyle
parent
efc8de6d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
31 deletions
+38
-31
example/example.cpp
example/example.cpp
+7
-4
include/spdlog/details/registry.h
include/spdlog/details/registry.h
+6
-6
include/spdlog/details/spdlog_impl.h
include/spdlog/details/spdlog_impl.h
+1
-1
include/spdlog/spdlog.h
include/spdlog/spdlog.h
+2
-2
tests/registry.cpp
tests/registry.cpp
+22
-18
No files found.
example/example.cpp
View file @
4efbd950
...
@@ -78,11 +78,14 @@ int main(int, char*[])
...
@@ -78,11 +78,14 @@ int main(int, char*[])
// Change default log error handler
// Change default log error handler
err_handler_example
();
err_handler_example
();
// Apply a function on all registered loggers
spd
::
apply_all
([
&
](
std
::
shared_ptr
<
spdlog
::
logger
>
l
)
{
l
->
info
(
"End of example."
);
});
// Release and close all loggers
// Apply a function on all registered loggers
spd
::
apply_all
([
&
](
std
::
shared_ptr
<
spdlog
::
logger
>
l
)
{
l
->
info
(
"End of example."
);
});
// Release and close all loggers
spdlog
::
drop_all
();
spdlog
::
drop_all
();
}
}
// Exceptions will only be thrown upon failed logger or sink construction (not during logging)
// Exceptions will only be thrown upon failed logger or sink construction (not during logging)
...
...
include/spdlog/details/registry.h
View file @
4efbd950
...
@@ -71,12 +71,12 @@ public:
...
@@ -71,12 +71,12 @@ public:
return
new_logger
;
return
new_logger
;
}
}
void
apply_all
(
std
::
function
<
void
(
std
::
shared_ptr
<
logger
>
)
>
fun
)
void
apply_all
(
std
::
function
<
void
(
std
::
shared_ptr
<
logger
>
)
>
fun
)
{
{
std
::
lock_guard
<
Mutex
>
lock
(
_mutex
);
std
::
lock_guard
<
Mutex
>
lock
(
_mutex
);
for
(
auto
&
l
:
_loggers
)
for
(
auto
&
l
:
_loggers
)
fun
(
l
.
second
);
fun
(
l
.
second
);
}
}
void
drop
(
const
std
::
string
&
logger_name
)
void
drop
(
const
std
::
string
&
logger_name
)
{
{
...
...
include/spdlog/details/spdlog_impl.h
View file @
4efbd950
...
@@ -165,7 +165,7 @@ inline void spdlog::set_sync_mode()
...
@@ -165,7 +165,7 @@ inline void spdlog::set_sync_mode()
inline
void
spdlog
::
apply_all
(
std
::
function
<
void
(
std
::
shared_ptr
<
logger
>
)
>
fun
)
inline
void
spdlog
::
apply_all
(
std
::
function
<
void
(
std
::
shared_ptr
<
logger
>
)
>
fun
)
{
{
details
::
registry
::
instance
().
apply_all
(
fun
);
details
::
registry
::
instance
().
apply_all
(
fun
);
}
}
inline
void
spdlog
::
drop_all
()
inline
void
spdlog
::
drop_all
()
...
...
include/spdlog/spdlog.h
View file @
4efbd950
...
@@ -113,7 +113,7 @@ std::shared_ptr<logger> create(const std::string& logger_name, const It& sinks_b
...
@@ -113,7 +113,7 @@ std::shared_ptr<logger> create(const std::string& logger_name, const It& sinks_b
// Create and register a logger with templated sink type
// Create and register a logger with templated sink type
// Example:
// Example:
// spdlog::create<daily_file_sink_st>("mylog", "dailylog_filename", "txt");
// spdlog::create<daily_file_sink_st>("mylog", "dailylog_filename", "txt");
template
<
typename
Sink
,
typename
...
Args
>
template
<
typename
Sink
,
typename
...
Args
>
std
::
shared_ptr
<
spdlog
::
logger
>
create
(
const
std
::
string
&
logger_name
,
Args
...);
std
::
shared_ptr
<
spdlog
::
logger
>
create
(
const
std
::
string
&
logger_name
,
Args
...);
...
@@ -123,7 +123,7 @@ std::shared_ptr<spdlog::logger> create(const std::string& logger_name, Args...);
...
@@ -123,7 +123,7 @@ std::shared_ptr<spdlog::logger> create(const std::string& logger_name, Args...);
void
register_logger
(
std
::
shared_ptr
<
logger
>
logger
);
void
register_logger
(
std
::
shared_ptr
<
logger
>
logger
);
// Apply a user defined function on all registered loggers
// Apply a user defined function on all registered loggers
// Example:
// Example:
// spdlog::apply_all([&](std::shared_ptr<spdlog::logger> l) {l->flush();});
// spdlog::apply_all([&](std::shared_ptr<spdlog::logger> l) {l->flush();});
void
apply_all
(
std
::
function
<
void
(
std
::
shared_ptr
<
logger
>
)
>
fun
);
void
apply_all
(
std
::
function
<
void
(
std
::
shared_ptr
<
logger
>
)
>
fun
);
...
...
tests/registry.cpp
View file @
4efbd950
...
@@ -25,24 +25,28 @@ TEST_CASE("explicit register" "[registry]")
...
@@ -25,24 +25,28 @@ TEST_CASE("explicit register" "[registry]")
TEST_CASE
(
"apply_all"
"[registry]"
)
TEST_CASE
(
"apply_all"
"[registry]"
)
{
{
spdlog
::
drop_all
();
spdlog
::
drop_all
();
auto
logger
=
std
::
make_shared
<
spdlog
::
logger
>
(
tested_logger_name
,
std
::
make_shared
<
spdlog
::
sinks
::
null_sink_st
>
());
auto
logger
=
std
::
make_shared
<
spdlog
::
logger
>
(
tested_logger_name
,
std
::
make_shared
<
spdlog
::
sinks
::
null_sink_st
>
());
spdlog
::
register_logger
(
logger
);
spdlog
::
register_logger
(
logger
);
auto
logger2
=
std
::
make_shared
<
spdlog
::
logger
>
(
tested_logger_name2
,
std
::
make_shared
<
spdlog
::
sinks
::
null_sink_st
>
());
auto
logger2
=
std
::
make_shared
<
spdlog
::
logger
>
(
tested_logger_name2
,
std
::
make_shared
<
spdlog
::
sinks
::
null_sink_st
>
());
spdlog
::
register_logger
(
logger2
);
spdlog
::
register_logger
(
logger2
);
int
counter
=
0
;
int
counter
=
0
;
spdlog
::
apply_all
([
&
counter
](
std
::
shared_ptr
<
spdlog
::
logger
>
l
){
counter
++
;});
spdlog
::
apply_all
([
&
counter
](
std
::
shared_ptr
<
spdlog
::
logger
>
l
)
REQUIRE
(
counter
==
2
);
{
counter
++
;
counter
=
0
;
});
spdlog
::
drop
(
tested_logger_name2
);
REQUIRE
(
counter
==
2
);
spdlog
::
apply_all
([
&
counter
](
std
::
shared_ptr
<
spdlog
::
logger
>
l
)
{
counter
=
0
;
REQUIRE
(
l
->
name
()
==
tested_logger_name
);
spdlog
::
drop
(
tested_logger_name2
);
counter
++
;
}
spdlog
::
apply_all
([
&
counter
](
std
::
shared_ptr
<
spdlog
::
logger
>
l
)
);
{
REQUIRE
(
counter
==
1
);
REQUIRE
(
l
->
name
()
==
tested_logger_name
);
counter
++
;
}
);
REQUIRE
(
counter
==
1
);
}
}
...
...
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