aboutsummaryrefslogtreecommitdiffstats
path: root/yage/core
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
parent443ae47fc210bcfe10f6f6c5ac8aa3453e1d29d2 (diff)
downloadYAGE-82a3db85138c91df397fd820a3b5d1a0b5c21ef9.tar.gz
YAGE-82a3db85138c91df397fd820a3b5d1a0b5c21ef9.zip
Asynchronous logging added
Diffstat (limited to 'yage/core')
l---------yage/core/.#logmessage.h1
-rw-r--r--yage/core/logger.cpp15
-rw-r--r--yage/core/logger.h4
-rw-r--r--yage/core/logsink.cpp2
-rw-r--r--yage/core/logsink.h8
5 files changed, 20 insertions, 10 deletions
diff --git a/yage/core/.#logmessage.h b/yage/core/.#logmessage.h
new file mode 120000
index 00000000..c4ccefcf
--- /dev/null
+++ b/yage/core/.#logmessage.h
@@ -0,0 +1 @@
+yannherklotz@yann-arch.2036:1510699559 \ No newline at end of file
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);
}
}
diff --git a/yage/core/logger.h b/yage/core/logger.h
index 2c70fd04..30b06b98 100644
--- a/yage/core/logger.h
+++ b/yage/core/logger.h
@@ -9,6 +9,9 @@
#ifndef YAGE_CORE_LOGGER_H
#define YAGE_CORE_LOGGER_H
+#include <yage/util/active.h>
+
+#include <memory>
#include <string>
#include <vector>
@@ -34,6 +37,7 @@ public:
private:
std::vector<LogSink> sinks_;
+ std::unique_ptr<Active> active_;
};
} // namespace yage
diff --git a/yage/core/logsink.cpp b/yage/core/logsink.cpp
index 987a260d..a8f4d7b4 100644
--- a/yage/core/logsink.cpp
+++ b/yage/core/logsink.cpp
@@ -34,7 +34,7 @@ bool LogSink::operator==(const LogSink &sink)
return (wrapper_.get() == sink.wrapper_.get());
}
-void LogSink::write(const LogMessage::Meta &meta, const std::string &msg)
+void LogSink::write(const LogMessage::Meta &meta, const std::string &msg) const
{
wrapper_->write(meta, msg);
}
diff --git a/yage/core/logsink.h b/yage/core/logsink.h
index f18a6d37..526c862e 100644
--- a/yage/core/logsink.h
+++ b/yage/core/logsink.h
@@ -30,7 +30,7 @@ public:
LogSink &operator=(LogSink &&sink);
bool operator==(const LogSink &sink);
- void write(const LogMessage::Meta &meta, const std::string &msg);
+ void write(const LogMessage::Meta &meta, const std::string &msg) const;
private:
struct Concept {
@@ -38,7 +38,7 @@ private:
virtual Concept *clone() const = 0;
virtual void write(const LogMessage::Meta &meta,
- const std::string &msg) = 0;
+ const std::string &msg) const = 0;
};
template <typename T>
@@ -46,7 +46,7 @@ private:
Model(T impl_i);
virtual Concept *clone() const override;
virtual void write(const LogMessage::Meta &meta,
- const std::string &msg) override;
+ const std::string &msg) const override;
T impl;
};
@@ -79,7 +79,7 @@ LogSink::Concept *LogSink::Model<T>::clone() const
template <typename T>
void LogSink::Model<T>::write(const LogMessage::Meta &meta,
- const std::string &msg)
+ const std::string &msg) const
{
impl(meta, msg);
}