aboutsummaryrefslogtreecommitdiffstats
path: root/yage/core/logger.cpp
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-11-16 16:27:47 +0000
committerYann Herklotz <ymherklotz@gmail.com>2017-11-16 16:27:47 +0000
commit82a3db85138c91df397fd820a3b5d1a0b5c21ef9 (patch)
tree6c6435962594df18eb2b6ed1d07740aecd0778ff /yage/core/logger.cpp
parent443ae47fc210bcfe10f6f6c5ac8aa3453e1d29d2 (diff)
downloadYAGE-82a3db85138c91df397fd820a3b5d1a0b5c21ef9.tar.gz
YAGE-82a3db85138c91df397fd820a3b5d1a0b5c21ef9.zip
Asynchronous logging added
Diffstat (limited to 'yage/core/logger.cpp')
-rw-r--r--yage/core/logger.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/yage/core/logger.cpp b/yage/core/logger.cpp
index 9fba2239..12a23dfc 100644
--- a/yage/core/logger.cpp
+++ b/yage/core/logger.cpp
@@ -17,7 +17,7 @@
namespace yage
{
-Logger::Logger()
+Logger::Logger() : active_(Active::create())
{
add(makeConsoleSink());
}
@@ -31,9 +31,14 @@ void Logger::flush(const LogMessage *msg)
{
std::string asString(msg->buffer_.str());
- for (auto &&sink : sinks_) {
- sink.write(msg->meta_, asString);
- }
+ auto &&sinks = sinks_;
+ auto &&meta = msg->meta_;
+
+ active_->send([=] {
+ for (auto &&sink : sinks) {
+ sink.write(meta, asString);
+ }
+ });
}
void Logger::add(const LogSink &sink)
@@ -45,7 +50,7 @@ void Logger::remove(const LogSink &sink)
{
auto it = std::find(std::begin(sinks_), std::end(sinks_), sink);
- if(it != std::end(sinks_)) {
+ if (it != std::end(sinks_)) {
sinks_.erase(it);
}
}