Go to the documentation of this file.
12 #include <boost/date_time.hpp>
56 Logstream(std::ostream &logTarget) : _logTarget(logTarget), _constructionTime(boost::posix_time::microsec_clock::local_time())
58 _carriageReturn =
true;
59 _displayLogLevel = Log::LogLevel::Info;
60 _streamLogLevel = Log::LogLevel::Info;
73 if (ls._displayLogLevel < ls._streamLogLevel)
return ls;
74 if (ls._streamLogLevel == Log::LogLevel::Warning) ls._logTarget <<
"\033[31m";
75 if (ls._carriageReturn)
77 float dt = float((boost::posix_time::microsec_clock::local_time() - ls._constructionTime).total_microseconds());
78 ls._logTarget <<
"[" << std::fixed << std::setprecision(6) << dt / 1000000.0f <<
"][";
79 if (ls._streamLogLevel == LogLevel::Debug) ls._logTarget <<
"D";
80 else if (ls._streamLogLevel == LogLevel::Info) ls._logTarget <<
"I";
81 else if (ls._streamLogLevel == LogLevel::Warning) ls._logTarget <<
"W";
82 else if (ls._streamLogLevel == LogLevel::Error) ls._logTarget <<
"E";
83 ls._logTarget <<
"] ";
84 ls._carriageReturn =
false;
87 if (ls._streamLogLevel == Log::LogLevel::Warning) ls._logTarget <<
"\033[0m";
100 _streamLogLevel = rhs;
127 std::ostream &_logTarget;
128 boost::posix_time::ptime _constructionTime;
130 bool _carriageReturn;
135 #pragma region Manipulators
144 if (ls._displayLogLevel >= ls._streamLogLevel)
146 ls._logTarget << std::endl;
147 ls._carriageReturn =
true;
162 ls._displayLogLevel = logLevel;
178 ls._streamLogLevel = logLevel;
Logstream & operator<<(const Manipulator &rhs)
Apply plain output manipulator to log stream.
Definition: Log.hpp:110
StructManipulator setDisplayLogLevel(const Log::LogLevel logLevel)
Generate output modifier to set the display log level filter.
Definition: Log.hpp:158
Logstream log(std::cout)
Global Logstream instance.
Definition: Log.hpp:185
Log stream object for simple output filtering.
Definition: Log.hpp:47
@ None
No spin component specified.
Logstream & operator<<(const StructManipulator &rhs)
Apply structured output manipulator to log stream.
Definition: Log.hpp:121
Logstream & endl(Logstream &ls)
Output modifier to print new line.
Definition: Log.hpp:142
Logstream(std::ostream &logTarget)
Construct a new Logstream object with log filtering to Log::LogLevel::Info.
Definition: Log.hpp:56
StructManipulator setLogLevel(const Log::LogLevel logLevel)
Generate output modifier to change the log level.
Definition: Log.hpp:174
Logstream & operator<<(const Log::LogLevel &rhs)
Output operator for LogLevel objects to set filter level.
Definition: Log.hpp:98
friend StructManipulator setLogLevel(const Log::LogLevel logLevel)
Generate output modifier to change the log level.
Definition: Log.hpp:174
friend Logstream & operator<<(Logstream &ls, const T &rhs)
Output operator for messages of arbitrary type. Will accept any log object that implements the output...
Definition: Log.hpp:71
std::function< Logstream &(Logstream &)> StructManipulator
Logstream manipulator type with internal structure.
Definition: Log.hpp:29
LogLevel
Specify log level for output filtering. Any Log level includes also output from lower output levels.
Definition: Log.hpp:20
friend Logstream & endl(Logstream &ls)
Output modifier to print new line.
Definition: Log.hpp:142
friend StructManipulator setDisplayLogLevel(const Log::LogLevel logLevel)
Generate output modifier to set the display log level filter.
Definition: Log.hpp:158