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
3af247fb
Commit
3af247fb
authored
Aug 20, 2016
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a way to iterate all registered loggers (issues #238 and #259).
parent
1c4da3ee
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
9 deletions
+26
-9
example/example.cpp
example/example.cpp
+6
-5
include/spdlog/details/registry.h
include/spdlog/details/registry.h
+7
-0
include/spdlog/details/spdlog_impl.h
include/spdlog/details/spdlog_impl.h
+5
-2
include/spdlog/spdlog.h
include/spdlog/spdlog.h
+8
-2
No files found.
example/example.cpp
View file @
3af247fb
...
...
@@ -70,16 +70,17 @@ int main(int, char*[])
// Just call spdlog::set_async_mode(q_size) and all created loggers from now on will be asynchronous..
async_example
();
// syslog example. linux/osx only
..
// syslog example. linux/osx only
syslog_example
();
//
log user-defined types example..
//
Log user-defined types example
user_defined_example
();
// Change default log error handler
err_handler_example
();
console
->
info
(
"End of example. bye.."
);
// 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
();
...
...
include/spdlog/details/registry.h
View file @
3af247fb
...
...
@@ -71,6 +71,13 @@ 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
drop
(
const
std
::
string
&
logger_name
)
{
std
::
lock_guard
<
Mutex
>
lock
(
_mutex
);
...
...
include/spdlog/details/spdlog_impl.h
View file @
3af247fb
...
...
@@ -153,8 +153,6 @@ inline void spdlog::set_error_handler(log_err_handler handler)
}
inline
void
spdlog
::
set_async_mode
(
size_t
queue_size
,
const
async_overflow_policy
overflow_policy
,
const
std
::
function
<
void
()
>&
worker_warmup_cb
,
const
std
::
chrono
::
milliseconds
&
flush_interval_ms
,
const
std
::
function
<
void
()
>&
worker_teardown_cb
)
{
details
::
registry
::
instance
().
set_async_mode
(
queue_size
,
overflow_policy
,
worker_warmup_cb
,
flush_interval_ms
,
worker_teardown_cb
);
...
...
@@ -165,6 +163,11 @@ inline void spdlog::set_sync_mode()
details
::
registry
::
instance
().
set_sync_mode
();
}
inline
void
spdlog
::
apply_all
(
std
::
function
<
void
(
std
::
shared_ptr
<
logger
>
)
>
fun
)
{
details
::
registry
::
instance
().
apply_all
(
fun
);
}
inline
void
spdlog
::
drop_all
()
{
details
::
registry
::
instance
().
drop_all
();
...
...
include/spdlog/spdlog.h
View file @
3af247fb
...
...
@@ -113,7 +113,8 @@ std::shared_ptr<logger> create(const std::string& logger_name, const It& sinks_b
// Create and register a logger with templated sink type
// Example: spdlog::create<daily_file_sink_st>("mylog", "dailylog_filename", "txt");
// 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
...);
...
...
@@ -121,10 +122,15 @@ std::shared_ptr<spdlog::logger> create(const std::string& logger_name, Args...);
// Register the given logger with the given name
void
register_logger
(
std
::
shared_ptr
<
logger
>
logger
);
// Apply a user defined function on all registered loggers
// Example:
// spdlog::apply_all([&](std::shared_ptr<spdlog::logger> l) {l->flush();});
void
apply_all
(
std
::
function
<
void
(
std
::
shared_ptr
<
logger
>
)
>
fun
);
// Drop the reference to the given logger
void
drop
(
const
std
::
string
&
name
);
// Drop all references
// Drop all references
from the registry
void
drop_all
();
...
...
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