Go to the documentation of this file.
23 #define WIN32_LEAN_AND_MEAN
64 if (
level < m_min_verbosity_level)
return;
68 if (logging_enable_keep_record) m_history.push_back(msg);
70 if (logging_enable_console_output)
76 for (
const auto&
c : m_listCallbacks)
93 std::string str = this->generateStringFromFormat(fmt, argp);
96 this->logStr(
level, str);
100 const char* fmt, va_list argp)
const
102 int result = -1,
length = 1024;
113 if (result >=
length) result = -1;
124 this->logStr(
level, msg_str);
129 m_logger_name =
name;
136 m_min_verbosity_level =
level;
140 m_min_verbosity_level =
level;
146 for (
const auto& h : m_history) fname += h.getAsString();
151 this->getLogAsString(str);
165 fname = m_logger_name +
".log";
167 std::ofstream f(fname);
170 "[%s:] Could not open external file: %s",
171 m_logger_name.c_str(), fname.c_str()));
174 this->getLogAsString(hist_str);
181 for (
const auto& h : m_history) h.dumpToConsole();
186 TMsg last_msg = m_history.back();
192 msg_str = this->getLoggerLastMsg();
197 m_logger_name =
"log";
200 logging_enable_console_output =
true;
201 logging_enable_keep_record =
false;
218 this->
level = in_level;
237 if (!body.empty() && *body.rbegin() !=
'\n') out << std::endl;
243 *contents = this->getAsString();
250 OutputDebugStringA(str.c_str());
265 (dump_to_cerr ? std::cerr : std::cout) << str;
276 m_listCallbacks.emplace_back(userFunc);
279 template <
typename T,
typename... U>
282 using fnType = T (*)(U...);
283 fnType** fnPointer = f.template target<fnType*>();
284 return (
size_t)*fnPointer;
289 for (
auto it = m_listCallbacks.begin(); it != m_listCallbacks.end(); ++it)
293 m_listCallbacks.erase(it);
TMsg(const mrpt::system::VerbosityLevel level, const std::string &msg, const COutputLogger &logger)
Class constructor that passes a message in std::string form as well as a reference to the COutputLogg...
mrpt::system::TTimeStamp timestamp
Timestamp of the message.
static mrpt::system::TConsoleColor logging_levels_to_colors[NUMBER_OF_VERBOSITY_LEVELS]
Map from VerbosityLevels to their corresponding mrpt::system::TConsoleColor.
void logStr(const VerbosityLevel level, const std::string &msg_str) const
Main method to add the specified message string to the logger.
void dumpToConsole() const
Dump the message contents to the standard output.
void reset()
Reset the contents of the TMsg instance.
void writeToStream(std::ostream &out) const
Write the message contents to the specified stream.
virtual ~COutputLogger()
virtual dtor (so we can derive classes from this one)
void setVerbosityLevel(const VerbosityLevel level)
alias of setMinLoggingLevel()
std::string generateStringFromFormat(const char *fmt, va_list argp) const
Helper method for generating a std::string instance from printf-like arguments.
void writeLogToFile(const std::string *fname_in=NULL) const
Write the contents of the COutputLogger instance to an external file.
#define INVALID_TIMESTAMP
Represents an invalid timestamp, where applicable.
std::string getLoggerLastMsg() const
Return the last Tmsg instance registered in the logger history.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
GLuint GLsizei GLsizei * length
GLuint const GLchar * name
std::string getLoggerName() const
Return the name of the COutputLogger instance.
void void logCond(const VerbosityLevel level, bool cond, const std::string &msg_str) const
Log the given message only if the condition is satisfied.
std::string getLogAsString() const
Get the history of COutputLogger instance in a string representation.
void logFmt(const VerbosityLevel level, const char *fmt,...) const MRPT_printf_format_check(3
Alternative logging method, which mimics the printf behavior.
VerbosityLevel
Enumeration of available verbosity levels.
int vsnprintf(char *buf, size_t bufSize, const char *format, va_list args) noexcept
An OS-independent version of vsnprintf (Notice the bufSize param, which may be ignored in some compil...
size_t getAddress(std::function< T(U...)> f)
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
std::string body
Actual content of the message.
std::string timeLocalToString(const mrpt::system::TTimeStamp t, unsigned int secondFractionDigits=6)
Convert a timestamp into this textual form (in local time): HH:MM:SS.MMMMMM.
VerbosityLevel level
Verbosity level of the message.
std::string getAsString() const
Return a string representation of the underlying message.
void setMinLoggingLevel(const VerbosityLevel level)
Set the minimum logging level for which the incoming logs are going to be taken into account.
~TMsg()
Default Destructor.
void loggerReset()
Reset the contents of the logger instance.
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
bool logDeregisterCallback(output_logger_callback_t userFunc)
Versatile class for consistent logging and management of output messages.
mrpt::system::TTimeStamp getCurrentTime()
Returns the current (UTC) system time.
void dumpLogToConsole() const
Dump the current contents of the COutputLogger instance in the terminal window.
TConsoleColor
For use in setConsoleColor.
Struct responsible of holding information relevant to the message (in std::string form) issued by the...
void logRegisterCallback(output_logger_callback_t userFunc)
GLsizei const GLchar ** string
static std::string logging_levels_to_names[NUMBER_OF_VERBOSITY_LEVELS]
Map from VerbosityLevels to their corresponding names.
void setLoggerName(const std::string &name)
Set the name of the COutputLogger instance.
@ NUMBER_OF_VERBOSITY_LEVELS
void setConsoleColor(TConsoleColor color, bool changeStdErr=false)
Changes the text color in the console for the text written from now on.
COutputLogger()
Default class constructor.
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
std::function< void(const std::string &msg, const mrpt::system::VerbosityLevel level, const std::string &loggerName, const mrpt::system::TTimeStamp timestamp)> output_logger_callback_t
Callback types for use with mrpt::system::COuputLogger.
std::string name
Name of the COutputLogger instance that called registered the message.
Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST | |