aboutsummaryrefslogtreecommitdiffstats
path: root/yage/core/logger.cpp
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2018-01-05 15:56:35 +0000
committerYann Herklotz <ymherklotz@gmail.com>2018-01-05 15:56:35 +0000
commitdb6480dccd9a3dbf4100a824930a36251f4e743c (patch)
treea36c5be39c86f9888e64076ef44c386e5160c088 /yage/core/logger.cpp
parent7b95e3a9eacf296f215c73e5d8ad9090a24adb20 (diff)
downloadYAGE-db6480dccd9a3dbf4100a824930a36251f4e743c.tar.gz
YAGE-db6480dccd9a3dbf4100a824930a36251f4e743c.zip
[Engine] Log levels added to engine.
Diffstat (limited to 'yage/core/logger.cpp')
-rw-r--r--yage/core/logger.cpp55
1 files changed, 41 insertions, 14 deletions
diff --git a/yage/core/logger.cpp b/yage/core/logger.cpp
index 3c80cf1b..1ae04d0b 100644
--- a/yage/core/logger.cpp
+++ b/yage/core/logger.cpp
@@ -19,29 +19,51 @@
namespace yage
{
-Logger::Logger() : active_(Active::create())
+Logger::Logger() : active_(Active::create()), min_level_(LogLevel::INFO)
{
add(makeConsoleSink());
- add(makeFileSink("yage.log"));
}
-LogMessage Logger::operator()(const std::string &fileName, int lineNum)
+Logger::Logger(const std::string &file_path)
+ : active_(Active::create()), min_level_(LogLevel::INFO)
{
- return LogMessage(this, fileName, lineNum);
+ add(makeConsoleSink());
+ add(makeFileSink(file_path));
+}
+
+Logger::Logger(LogLevel min_level)
+ : active_(Active::create()), min_level_(min_level)
+{
+ add(makeConsoleSink());
+}
+
+Logger::Logger(LogLevel min_level, const std::string &file_path)
+ : active_(Active::create()), min_level_(min_level)
+{
+ add(makeConsoleSink());
+ add(makeFileSink(file_path));
+}
+
+LogMessage Logger::operator()(LogLevel level, const std::string &fileName,
+ int lineNum)
+{
+ return LogMessage(this, level, fileName, lineNum);
}
void Logger::flush(const LogMessage *msg)
{
- std::string asString(msg->buffer_.str());
+ if (static_cast<int>(msg->meta_.level) >= static_cast<int>(min_level_)) {
+ std::string asString(msg->buffer_.str());
- auto &&sinks = sinks_;
- auto &&meta = msg->meta_;
+ auto &&sinks = sinks_;
+ auto &&meta = msg->meta_;
- active_->send([=] {
- for (auto &&sink : sinks) {
- sink.write(meta, asString);
- }
- });
+ active_->send([=] {
+ for (auto &&sink : sinks) {
+ sink.write(meta, asString);
+ }
+ });
+ }
}
void Logger::add(const LogSink &sink)
@@ -65,9 +87,14 @@ void Logger::clear()
Logger &Logger::instance()
{
- static Logger yLogger;
+ static Logger y_logger(LogLevel::INFO, "yage.log");
+
+ return y_logger;
+}
- return yLogger;
+void Logger::setLevel(LogLevel min_level)
+{
+ min_level_ = min_level;
}
} // namespace yage