Make unbuffered log verbosity aware

This commit is contained in:
Michael Krasnyk
2017-09-15 10:45:07 +02:00
parent 966139cde9
commit e32b8bae00
4 changed files with 66 additions and 4 deletions
+32 -2
View File
@@ -53,10 +53,40 @@ class Log
virtual ~Log();
std::mutex &get_mutex();
template <typename T> inline std::ostream &operator<<(const T &data) { return stream << data; }
template <typename T> inline Log &operator<<(const T &data)
{
const auto &policy = LogPolicy::GetInstance();
if (!policy.IsMute() && level <= policy.GetLevel())
{
stream << data;
}
return *this;
}
template <typename T> inline Log &operator<<(const std::atomic<T> &data)
{
const auto &policy = LogPolicy::GetInstance();
if (!policy.IsMute() && level <= policy.GetLevel())
{
stream << T(data);
}
return *this;
}
typedef std::ostream &(manip)(std::ostream &);
inline Log &operator<<(manip &m)
{
const auto &policy = LogPolicy::GetInstance();
if (!policy.IsMute() && level <= policy.GetLevel())
{
stream << m;
}
return *this;
}
protected:
LogLevel level;
const LogLevel level;
std::ostringstream buffer;
std::ostream &stream;
};
+1 -1
View File
@@ -83,7 +83,7 @@ class Percent
// When not on a TTY, print newlines after each progress indicator so
// so that progress is visible to line-buffered logging systems
if (!IsStdoutATTY())
log << "" << std::endl;
log << std::endl;
}
}
};