49 #include <pcl/pcl_exports.h>
50 #include <pcl/pcl_config.h>
56 #define PCL_LOG_STREAM(LEVEL, ARGS) \
57 if (pcl::console::isVerbosityLevelEnabled(pcl::console::LEVEL)) \
59 std::stringstream strstream; \
61 pcl::console::LogRecord entry{pcl::console::LEVEL, strstream.str()}; \
62 pcl::console::Logger::getInstance().print(entry); \
65 #define PCL_ALWAYS_STREAM(ARGS) PCL_LOG_STREAM(L_ALWAYS, ARGS)
66 #define PCL_ERROR_STREAM(ARGS) PCL_LOG_STREAM(L_ERROR, ARGS)
67 #define PCL_WARN_STREAM(ARGS) PCL_LOG_STREAM(L_WARN, ARGS)
68 #define PCL_INFO_STREAM(ARGS) PCL_LOG_STREAM(L_INFO, ARGS)
69 #define PCL_DEBUG_STREAM(ARGS) PCL_LOG_STREAM(L_DEBUG, ARGS)
70 #define PCL_VERBOSE_STREAM(ARGS) PCL_LOG_STREAM(L_VERBOSE, ARGS)
73 #define PCL_ALWAYS(...) pcl::console::print (pcl::console::L_ALWAYS, __VA_ARGS__)
74 #define PCL_ERROR(...) pcl::console::print (pcl::console::L_ERROR, __VA_ARGS__)
75 #define PCL_WARN(...) pcl::console::print (pcl::console::L_WARN, __VA_ARGS__)
76 #define PCL_INFO(...) pcl::console::print (pcl::console::L_INFO, __VA_ARGS__)
77 #define PCL_DEBUG(...) pcl::console::print (pcl::console::L_DEBUG, __VA_ARGS__)
78 #define PCL_VERBOSE(...) pcl::console::print (pcl::console::L_VERBOSE, __VA_ARGS__)
79 #define PCL_HIGH(...) pcl::console::print_highlight (__VA_ARGS__)
81 #define PCL_ASSERT_ERROR_PRINT_CHECK(pred, msg) \
87 PCL_ERROR("In File %s, in line %d\n" __FILE__, __LINE__); \
91 #define PCL_ASSERT_ERROR_PRINT_RETURN(pred, msg, err) \
94 PCL_ASSERT_ERROR_PRINT_CHECK(pred, msg); \
95 if (!(pred)) return err; \
215 template <
typename Functor>
219 logcallback = std::move(callback);
244 std::function<void(
const LogRecord&)> logcallback;
253 template <
typename Functor>
266 template <
typename... Args>
270 int final_n, n = (
static_cast<int>(fmt_str.size())) * 2;
271 std::unique_ptr<char[]> formatted;
274 formatted.reset(
new char[n]);
275 va_start(ap, fmt_str);
276 final_n = vsnprintf(formatted.get(), n, fmt_str.c_str(), ap);
278 if (final_n < 0 || final_n >= n)
279 n += abs(final_n - n + 1);
283 return {formatted.get()};
290 template <
typename... Args>
300 template <
typename... Args>
311 template <
typename... Args>
321 template <
typename... Args>
332 template <
typename... Args>
342 template <
typename... Args>
353 template <
typename... Args>
363 template <
typename... Args>
376 template <
typename... Args>
389 template <
typename... Args>
401 template <
typename... Args>
413 template <
typename... Args>
431 template <
typename... Args>
447 template <
typename... Args>
460 template <
typename... Args>
Logger used to log messages with different verbosity levels Can be used to redirect log messages to c...
void print(const LogRecord &logEntry)
void setCallback(Functor &&callback)
static Logger & getInstance()
void print(FILE *stream, const LogRecord &logEntry)
void print_value(FILE *stream, const LogRecord &logEntry)
void print_value(const LogRecord &logEntry)
void print_highlight(FILE *stream, const LogRecord &logEntry)
void print_color(FILE *stream, int attr, int fg, const LogRecord &logEntry)
void print_highlight(const LogRecord &logEntry)
PCL_EXPORTS void enableColoredOutput(FILE *stream, bool enable)
Enable or disable colored text output, overriding the default behavior.
void setCallback(Functor &&callback)
Sets a callable in the Logger instance, which is called whenever a printout has occured.
PCL_EXPORTS void setVerbosityLevel(VERBOSITY_LEVEL level)
set the verbosity level
PCL_EXPORTS void print_color(FILE *stream, int attr, int fg, const std::string format, Args &&... args)
Print a message on stream with colors.
PCL_EXPORTS void print_value(FILE *stream, const std::string format, Args &&... args)
Print a value message on stream with colors.
PCL_EXPORTS void print_warn(FILE *stream, const std::string format, Args &&... args)
Print a warning message on stream with colors.
PCL_EXPORTS bool isVerbosityLevelEnabled(VERBOSITY_LEVEL severity)
is verbosity level enabled?
PCL_EXPORTS void reset_text_color(FILE *stream)
Reset the text color (on either stdout or stderr) to its original state.
PCL_EXPORTS void print_debug(FILE *stream, const std::string format, Args &&... args)
Print a debug message on stream with colors.
PCL_EXPORTS void change_text_color(FILE *stream, int attribute, int fg, int bg)
Change the text color (on either stdout or stderr) with an attr:fg:bg.
PCL_EXPORTS void print(VERBOSITY_LEVEL level, FILE *stream, const std::string format, Args &&...args)
Print a message on stream.
std::string to_string(const std::string fmt_str,...)
insert values into a formatted string
PCL_EXPORTS void print_error(FILE *stream, const std::string format, Args &&... args)
Print an error message on stream with colors.
PCL_EXPORTS VERBOSITY_LEVEL getVerbosityLevel()
get the verbosity level.
PCL_EXPORTS void print_highlight(FILE *stream, const std::string format, Args... args)
Print a highlighted info message on stream with colors.
PCL_EXPORTS bool initVerbosityLevel()
initialize verbosity level.
PCL_EXPORTS void print_info(FILE *stream, const std::string format, Args &&... args)
Print an info message on stream with colors.
Base functor all the models that need non linear optimization must define their own one and implement...
Structure to hold a log record Used by the Logger class.
LogRecord(VERBOSITY_LEVEL lvl, const std::string &str)
LogRecord(const LogRecord &other)=default
LogRecord(VERBOSITY_LEVEL lvl, std::string &&str)