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
9cbdd5ff
Commit
9cbdd5ff
authored
Jul 20, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added async_nonblocking factory
parent
ddb3002b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
10 deletions
+24
-10
include/spdlog/async.h
include/spdlog/async.h
+15
-2
include/spdlog/async_logger.h
include/spdlog/async_logger.h
+8
-0
include/spdlog/common.h
include/spdlog/common.h
+1
-8
No files found.
include/spdlog/async.h
View file @
9cbdd5ff
...
...
@@ -21,9 +21,11 @@
#include <memory>
namespace
spdlog
{
// async logger factory - creates async loggers backed with thread pool.
// if a global thread pool doesn't already exist, create it with default queue size of 8192 items and single thread.
struct
async_factory
template
<
async_overflow_policy
OverflowPolicy
=
async_overflow_policy
::
block
>
struct
async_factory_impl
{
template
<
typename
Sink
,
typename
...
SinkArgs
>
static
std
::
shared_ptr
<
async_logger
>
create
(
const
std
::
string
&
logger_name
,
SinkArgs
&&
...
args
)
...
...
@@ -39,18 +41,29 @@ struct async_factory
}
auto
sink
=
std
::
make_shared
<
Sink
>
(
std
::
forward
<
SinkArgs
>
(
args
)...);
auto
new_logger
=
std
::
make_shared
<
async_logger
>
(
logger_name
,
std
::
move
(
sink
),
std
::
move
(
tp
),
async_overflow_policy
::
block
);
auto
new_logger
=
std
::
make_shared
<
async_logger
>
(
logger_name
,
std
::
move
(
sink
),
std
::
move
(
tp
),
OverflowPolicy
);
registry
::
instance
().
register_and_init
(
new_logger
);
return
new_logger
;
}
};
using
async_factory
=
async_factory_impl
<
async_overflow_policy
::
block
>
;
using
async_factory_nonblock
=
async_factory_impl
<
async_overflow_policy
::
overrun_oldest
>
;
template
<
typename
Sink
,
typename
...
SinkArgs
>
inline
std
::
shared_ptr
<
spdlog
::
logger
>
create_async
(
const
std
::
string
&
logger_name
,
SinkArgs
&&
...
sink_args
)
{
return
async_factory
::
create
<
Sink
>
(
logger_name
,
std
::
forward
<
SinkArgs
>
(
sink_args
)...);
}
template
<
typename
Sink
,
typename
...
SinkArgs
>
inline
std
::
shared_ptr
<
spdlog
::
logger
>
create_async_nb
(
const
std
::
string
&
logger_name
,
SinkArgs
&&
...
sink_args
)
{
return
async_factory
<
spdlog
::
async_overflow_policy
::
overrun_oldest
>::
create
<
Sink
>
(
logger_name
,
std
::
forward
<
SinkArgs
>
(
sink_args
)...);
}
// set global thread pool.
inline
void
init_thread_pool
(
size_t
q_size
,
size_t
thread_count
)
{
...
...
include/spdlog/async_logger.h
View file @
9cbdd5ff
...
...
@@ -23,6 +23,14 @@
#include <string>
namespace
spdlog
{
// Async overflow policy - block by default.
enum
class
async_overflow_policy
{
block
,
// Block until message can be enqueued
overrun_oldest
// Discard oldest message in the queue if full when trying to add new item.
};
namespace
details
{
class
thread_pool
;
}
...
...
include/spdlog/common.h
View file @
9cbdd5ff
...
...
@@ -121,14 +121,7 @@ inline spdlog::level::level_enum from_str(const std::string &name)
using
level_hasher
=
std
::
hash
<
int
>
;
}
// namespace level
//
// Async overflow policy - block by default.
//
enum
class
async_overflow_policy
{
block
,
// Block until message can be enqueued
overrun_oldest
// Discard oldest message in the queue if full when trying to add new item.
};
//
// Pattern time - specific time getting to use for pattern_formatter.
...
...
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