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
9b984ddb
Commit
9b984ddb
authored
May 11, 2016
by
Gabi Melman
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #208 from SBAM/master
In async mode, teardown callback on worker thread exit
parents
409f24d1
ee815042
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
19 deletions
+35
-19
include/spdlog/async_logger.h
include/spdlog/async_logger.h
+7
-5
include/spdlog/details/async_log_helper.h
include/spdlog/details/async_log_helper.h
+9
-2
include/spdlog/details/async_logger_impl.h
include/spdlog/details/async_logger_impl.h
+9
-6
include/spdlog/details/registry.h
include/spdlog/details/registry.h
+4
-2
include/spdlog/details/spdlog_impl.h
include/spdlog/details/spdlog_impl.h
+2
-3
include/spdlog/spdlog.h
include/spdlog/spdlog.h
+4
-1
No files found.
include/spdlog/async_logger.h
View file @
9b984ddb
...
...
@@ -13,7 +13,7 @@
// 1. Checks if its log level is enough to log the message
// 2. Push a new copy of the message to a queue (or block the caller until space is available in the queue)
// 3. will throw spdlog_ex upon log exceptions
// Upon
g
destruction, logs all remaining messages in the queue before destructing..
// Upon destruction, logs all remaining messages in the queue before destructing..
#include <spdlog/common.h>
#include <spdlog/logger.h>
...
...
@@ -41,21 +41,24 @@ public:
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
::
chrono
::
milliseconds
&
flush_interval_ms
=
std
::
chrono
::
milliseconds
::
zero
(),
const
std
::
function
<
void
()
>&
worker_teardown_cb
=
nullptr
);
async_logger
(
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
::
chrono
::
milliseconds
&
flush_interval_ms
=
std
::
chrono
::
milliseconds
::
zero
(),
const
std
::
function
<
void
()
>&
worker_teardown_cb
=
nullptr
);
async_logger
(
const
std
::
string
&
logger_name
,
sink_ptr
single_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
::
chrono
::
milliseconds
&
flush_interval_ms
=
std
::
chrono
::
milliseconds
::
zero
(),
const
std
::
function
<
void
()
>&
worker_teardown_cb
=
nullptr
);
void
flush
()
override
;
...
...
@@ -71,4 +74,3 @@ private:
#include <spdlog/details/async_logger_impl.h>
include/spdlog/details/async_log_helper.h
View file @
9b984ddb
...
...
@@ -121,7 +121,8 @@ public:
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
::
chrono
::
milliseconds
&
flush_interval_ms
=
std
::
chrono
::
milliseconds
::
zero
(),
const
std
::
function
<
void
()
>&
worker_teardown_cb
=
nullptr
);
void
log
(
const
details
::
log_msg
&
msg
);
...
...
@@ -157,6 +158,9 @@ private:
// auto periodic sink flush parameter
const
std
::
chrono
::
milliseconds
_flush_interval_ms
;
// worker thread teardown callback
const
std
::
function
<
void
()
>
_worker_teardown_cb
;
// worker thread
std
::
thread
_worker_thread
;
...
...
@@ -190,7 +194,8 @@ inline spdlog::details::async_log_helper::async_log_helper(
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
::
chrono
::
milliseconds
&
flush_interval_ms
,
const
std
::
function
<
void
()
>&
worker_teardown_cb
)
:
_formatter
(
formatter
),
_sinks
(
sinks
),
_q
(
queue_size
),
...
...
@@ -199,6 +204,7 @@ inline spdlog::details::async_log_helper::async_log_helper(
_overflow_policy
(
overflow_policy
),
_worker_warmup_cb
(
worker_warmup_cb
),
_flush_interval_ms
(
flush_interval_ms
),
_worker_teardown_cb
(
worker_teardown_cb
),
_worker_thread
(
&
async_log_helper
::
worker_loop
,
this
)
{}
...
...
@@ -254,6 +260,7 @@ inline void spdlog::details::async_log_helper::worker_loop()
auto
last_pop
=
details
::
os
::
now
();
auto
last_flush
=
last_pop
;
while
(
process_next_msg
(
last_pop
,
last_flush
));
if
(
_worker_teardown_cb
)
_worker_teardown_cb
();
}
catch
(
const
std
::
exception
&
ex
)
{
...
...
include/spdlog/details/async_logger_impl.h
View file @
9b984ddb
...
...
@@ -23,9 +23,10 @@ inline spdlog::async_logger::async_logger(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
::
chrono
::
milliseconds
&
flush_interval_ms
,
const
std
::
function
<
void
()
>&
worker_teardown_cb
)
:
logger
(
logger_name
,
begin
,
end
),
_async_log_helper
(
new
details
::
async_log_helper
(
_formatter
,
_sinks
,
queue_size
,
overflow_policy
,
worker_warmup_cb
,
flush_interval_ms
))
_async_log_helper
(
new
details
::
async_log_helper
(
_formatter
,
_sinks
,
queue_size
,
overflow_policy
,
worker_warmup_cb
,
flush_interval_ms
,
worker_teardown_cb
))
{
}
...
...
@@ -34,19 +35,21 @@ inline spdlog::async_logger::async_logger(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
)
:
async_logger
(
logger_name
,
sinks
.
begin
(),
sinks
.
end
(),
queue_size
,
overflow_policy
,
worker_warmup_cb
,
flush_interval_ms
)
{}
const
std
::
chrono
::
milliseconds
&
flush_interval_ms
,
const
std
::
function
<
void
()
>&
worker_teardown_cb
)
:
async_logger
(
logger_name
,
sinks
.
begin
(),
sinks
.
end
(),
queue_size
,
overflow_policy
,
worker_warmup_cb
,
flush_interval_ms
,
worker_teardown_cb
)
{}
inline
spdlog
::
async_logger
::
async_logger
(
const
std
::
string
&
logger_name
,
sink_ptr
single_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
::
chrono
::
milliseconds
&
flush_interval_ms
,
const
std
::
function
<
void
()
>&
worker_teardown_cb
)
:
async_logger
(
logger_name
,
{
single_sink
},
queue_size
,
overflow_policy
,
worker_warmup_cb
,
flush_interval_ms
)
{}
},
queue_size
,
overflow_policy
,
worker_warmup_cb
,
flush_interval_ms
,
worker_teardown_cb
)
{}
inline
void
spdlog
::
async_logger
::
flush
()
...
...
include/spdlog/details/registry.h
View file @
9b984ddb
...
...
@@ -53,7 +53,7 @@ public:
throw_if_exists
(
logger_name
);
std
::
shared_ptr
<
logger
>
new_logger
;
if
(
_async_mode
)
new_logger
=
std
::
make_shared
<
async_logger
>
(
logger_name
,
sinks_begin
,
sinks_end
,
_async_q_size
,
_overflow_policy
,
_worker_warmup_cb
,
_flush_interval_ms
);
new_logger
=
std
::
make_shared
<
async_logger
>
(
logger_name
,
sinks_begin
,
sinks_end
,
_async_q_size
,
_overflow_policy
,
_worker_warmup_cb
,
_flush_interval_ms
,
_worker_teardown_cb
);
else
new_logger
=
std
::
make_shared
<
logger
>
(
logger_name
,
sinks_begin
,
sinks_end
);
...
...
@@ -112,7 +112,7 @@ public:
_level
=
log_level
;
}
void
set_async_mode
(
size_t
q_size
,
const
async_overflow_policy
overflow_policy
,
const
std
::
function
<
void
()
>&
worker_warmup_cb
,
const
std
::
chrono
::
milliseconds
&
flush_interval_ms
)
void
set_async_mode
(
size_t
q_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
)
{
std
::
lock_guard
<
Mutex
>
lock
(
_mutex
);
_async_mode
=
true
;
...
...
@@ -120,6 +120,7 @@ public:
_overflow_policy
=
overflow_policy
;
_worker_warmup_cb
=
worker_warmup_cb
;
_flush_interval_ms
=
flush_interval_ms
;
_worker_teardown_cb
=
worker_teardown_cb
;
}
void
set_sync_mode
()
...
...
@@ -153,6 +154,7 @@ private:
async_overflow_policy
_overflow_policy
=
async_overflow_policy
::
block_retry
;
std
::
function
<
void
()
>
_worker_warmup_cb
=
nullptr
;
std
::
chrono
::
milliseconds
_flush_interval_ms
;
std
::
function
<
void
()
>
_worker_teardown_cb
=
nullptr
;
};
#ifdef SPDLOG_NO_REGISTRY_MUTEX
typedef
registry_t
<
spdlog
::
details
::
null_mutex
>
registry
;
...
...
include/spdlog/details/spdlog_impl.h
View file @
9b984ddb
...
...
@@ -132,9 +132,9 @@ inline void spdlog::set_level(level::level_enum log_level)
}
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
)
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
);
details
::
registry
::
instance
().
set_async_mode
(
queue_size
,
overflow_policy
,
worker_warmup_cb
,
flush_interval_ms
,
worker_teardown_cb
);
}
inline
void
spdlog
::
set_sync_mode
()
...
...
@@ -146,4 +146,3 @@ inline void spdlog::drop_all()
{
details
::
registry
::
instance
().
drop_all
();
}
include/spdlog/spdlog.h
View file @
9b984ddb
...
...
@@ -53,7 +53,10 @@ void set_level(level::level_enum log_level);
// worker_warmup_cb (optional):
// callback function that will be called in worker thread upon start (can be used to init stuff like thread affinity)
//
void
set_async_mode
(
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
());
// worker_teardown_cb (optional):
// callback function that will be called in worker thread upon exit
//
void
set_async_mode
(
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
);
// Turn off async mode
void
set_sync_mode
();
...
...
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