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
d3e013a5
Commit
d3e013a5
authored
Jun 15, 2017
by
Gabi Melman
Committed by
GitHub
Jun 15, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #459 from cneumann/create_async
Add create_async factory functions for async loggers
parents
e6cbc22d
8ee90d33
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
1 deletion
+55
-1
include/spdlog/details/registry.h
include/spdlog/details/registry.h
+29
-0
include/spdlog/details/spdlog_impl.h
include/spdlog/details/spdlog_impl.h
+18
-0
include/spdlog/spdlog.h
include/spdlog/spdlog.h
+8
-1
No files found.
include/spdlog/details/registry.h
View file @
d3e013a5
...
...
@@ -71,6 +71,26 @@ public:
return
new_logger
;
}
template
<
class
It
>
std
::
shared_ptr
<
async_logger
>
create_async
(
const
std
::
string
&
logger_name
,
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
,
const
It
&
sinks_begin
,
const
It
&
sinks_end
)
{
std
::
lock_guard
<
Mutex
>
lock
(
_mutex
);
throw_if_exists
(
logger_name
);
auto
new_logger
=
std
::
make_shared
<
async_logger
>
(
logger_name
,
sinks_begin
,
sinks_end
,
queue_size
,
overflow_policy
,
worker_warmup_cb
,
flush_interval_ms
,
worker_teardown_cb
);
if
(
_formatter
)
new_logger
->
set_formatter
(
_formatter
);
if
(
_err_handler
)
new_logger
->
set_error_handler
(
_err_handler
);
new_logger
->
set_level
(
_level
);
//Add to registry
_loggers
[
logger_name
]
=
new_logger
;
return
new_logger
;
}
void
apply_all
(
std
::
function
<
void
(
std
::
shared_ptr
<
logger
>
)
>
fun
)
{
std
::
lock_guard
<
Mutex
>
lock
(
_mutex
);
...
...
@@ -99,6 +119,15 @@ public:
return
create
(
logger_name
,
{
sink
});
}
std
::
shared_ptr
<
async_logger
>
create_async
(
const
std
::
string
&
logger_name
,
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
,
sinks_init_list
sinks
)
{
return
create_async
(
logger_name
,
queue_size
,
overflow_policy
,
worker_warmup_cb
,
flush_interval_ms
,
worker_teardown_cb
,
sinks
.
begin
(),
sinks
.
end
());
}
std
::
shared_ptr
<
async_logger
>
create_async
(
const
std
::
string
&
logger_name
,
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
,
sink_ptr
sink
)
{
return
create_async
(
logger_name
,
queue_size
,
overflow_policy
,
worker_warmup_cb
,
flush_interval_ms
,
worker_teardown_cb
,
{
sink
});
}
void
formatter
(
formatter_ptr
f
)
{
...
...
include/spdlog/details/spdlog_impl.h
View file @
d3e013a5
...
...
@@ -203,6 +203,24 @@ inline std::shared_ptr<spdlog::logger> spdlog::create(const std::string& logger_
return
details
::
registry
::
instance
().
create
(
logger_name
,
sinks_begin
,
sinks_end
);
}
// Create and register an async logger with a single sink
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
create_async
(
const
std
::
string
&
logger_name
,
const
sink_ptr
&
sink
,
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
)
{
return
details
::
registry
::
instance
().
create_async
(
logger_name
,
queue_size
,
overflow_policy
,
worker_warmup_cb
,
flush_interval_ms
,
worker_teardown_cb
,
sink
);
}
// Create and register an async logger with multiple sinks
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
create_async
(
const
std
::
string
&
logger_name
,
sinks_init_list
sinks
,
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
)
{
return
details
::
registry
::
instance
().
create_async
(
logger_name
,
queue_size
,
overflow_policy
,
worker_warmup_cb
,
flush_interval_ms
,
worker_teardown_cb
,
sinks
);
}
template
<
class
It
>
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
create_async
(
const
std
::
string
&
logger_name
,
const
It
&
sinks_begin
,
const
It
&
sinks_end
,
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
)
{
return
details
::
registry
::
instance
().
create_async
(
logger_name
,
queue_size
,
overflow_policy
,
worker_warmup_cb
,
flush_interval_ms
,
worker_teardown_cb
,
sinks_begin
,
sinks_end
);
}
inline
void
spdlog
::
set_formatter
(
spdlog
::
formatter_ptr
f
)
{
details
::
registry
::
instance
().
formatter
(
f
);
...
...
include/spdlog/spdlog.h
View file @
d3e013a5
...
...
@@ -113,7 +113,7 @@ std::shared_ptr<logger> syslog_logger(const std::string& logger_name, const std:
std
::
shared_ptr
<
logger
>
android_logger
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
tag
=
"spdlog"
);
#endif
// Create and register a logger a single sink
// Create and register a logger
with
a single sink
std
::
shared_ptr
<
logger
>
create
(
const
std
::
string
&
logger_name
,
const
sink_ptr
&
sink
);
// Create and register a logger with multiple sinks
...
...
@@ -128,6 +128,13 @@ std::shared_ptr<logger> create(const std::string& logger_name, const It& sinks_b
template
<
typename
Sink
,
typename
...
Args
>
std
::
shared_ptr
<
spdlog
::
logger
>
create
(
const
std
::
string
&
logger_name
,
Args
...);
// Create and register an async logger with a single sink
std
::
shared_ptr
<
logger
>
create_async
(
const
std
::
string
&
logger_name
,
const
sink_ptr
&
sink
,
size_t
queue_size
,
const
async_overflow_policy
overflow_policy
=
async_overflow_policy
::
block_retry
,
const
std
::
function
<
void
()
>&
worker_warmup_cb
=
nullptr
,
const
std
::
chrono
::
milliseconds
&
flush_interval_ms
=
std
::
chrono
::
milliseconds
::
zero
(),
const
std
::
function
<
void
()
>&
worker_teardown_cb
=
nullptr
);
// Create and register an async logger with multiple sinks
std
::
shared_ptr
<
logger
>
create_async
(
const
std
::
string
&
logger_name
,
sinks_init_list
sinks
,
size_t
queue_size
,
const
async_overflow_policy
overflow_policy
=
async_overflow_policy
::
block_retry
,
const
std
::
function
<
void
()
>&
worker_warmup_cb
=
nullptr
,
const
std
::
chrono
::
milliseconds
&
flush_interval_ms
=
std
::
chrono
::
milliseconds
::
zero
(),
const
std
::
function
<
void
()
>&
worker_teardown_cb
=
nullptr
);
template
<
class
It
>
std
::
shared_ptr
<
logger
>
create_async
(
const
std
::
string
&
logger_name
,
const
It
&
sinks_begin
,
const
It
&
sinks_end
,
size_t
queue_size
,
const
async_overflow_policy
overflow_policy
=
async_overflow_policy
::
block_retry
,
const
std
::
function
<
void
()
>&
worker_warmup_cb
=
nullptr
,
const
std
::
chrono
::
milliseconds
&
flush_interval_ms
=
std
::
chrono
::
milliseconds
::
zero
(),
const
std
::
function
<
void
()
>&
worker_teardown_cb
=
nullptr
);
// Register the given logger with the given name
void
register_logger
(
std
::
shared_ptr
<
logger
>
logger
);
...
...
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