Make unbuffered log verbosity aware
This commit is contained in:
+32
-2
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user