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