47 struct DefaultOutputHandler
49 DefaultOutputHandler(
void)
52 previous_output_handler_ = output_handler_;
67 static DefaultOutputHandler* getDOH(
void)
69 static DefaultOutputHandler DOH;
74 DefaultOutputHandler *doh = getDOH(); \ 75 std::lock_guard<std::mutex> lock_guard(doh->lock_) 77 #define MAX_BUFFER_SIZE 1024 84 doh->previous_output_handler_ = doh->output_handler_;
85 doh->output_handler_ =
NULL;
91 std::swap(doh->previous_output_handler_, doh->output_handler_);
97 doh->previous_output_handler_ = doh->output_handler_;
98 doh->output_handler_ = oh;
103 return getDOH()->output_handler_;
115 if (doh->output_handler_ && level >= doh->logLevel_)
119 char buf[MAX_BUFFER_SIZE];
121 vsnprintf_s(buf,
sizeof(buf), _TRUNCATE, m, __ap);
123 vsnprintf(buf,
sizeof(buf), m, __ap);
126 buf[MAX_BUFFER_SIZE - 1] =
'\0';
128 doh->output_handler_->log(buf, level, file, line);
135 if (doh->output_handler_ && level >= doh->logLevel_)
139 char buf[MAX_BUFFER_SIZE];
141 vsnprintf_s(buf,
sizeof(buf), _TRUNCATE, m, __ap);
143 vsnprintf(buf,
sizeof(buf), m, __ap);
146 buf[MAX_BUFFER_SIZE - 1] =
'\0';
148 doh->output_handler_->log(buf, level, file, line);
155 doh->logLevel_ =
level;
161 return doh->logLevel_;
164 static const char*
LogLevelString[4] = {
"Debug: ",
"Info: ",
"Warning: ",
"Error: "};
171 std::cerr <<
" at line " << line <<
" in " << filename << std::endl;
184 errno_t err = fopen_s(&
file_, filename,
"a");
185 if (err != 0 || !
file_)
187 file_ = fopen(filename,
"a");
190 std::cerr <<
"Unable to open log file: '" << filename <<
"'" << std::endl;
196 if (fclose(
file_) != 0)
197 std::cerr <<
"Error closing logfile" << std::endl;
206 fprintf(
file_,
" at line %d in %s\n", line, filename);
Default implementation of OutputHandler. This sends the information to the console.
void noOutputHandler(void)
This function instructs ompl that no messages should be outputted. Equivalent to useOutputHandler(NUL...
Generic class to handle output from a piece of code.
LogLevel getLogLevel(void)
Retrieve the current level of logging data. Messages with lower logging levels will not be recorded...
GLenum GLuint GLenum GLsizei const GLchar * buf
virtual void log(const std::string &text, LogLevel level, const char *filename, int line)
log a message to the output handler with the given text and logging level from a specific file and li...
FILE * file_
The file to save to.
void setLogLevel(LogLevel level)
Set the minimum level of logging data to output. Messages with lower logging levels will not be recor...
OutputHandler * getOutputHandler(void)
Get the instance of the OutputHandler currently used. This is NULL in case there is no output handler...
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
void restorePreviousOutputHandler(void)
Restore the output handler that was previously in use (if any)
OutputHandlerFile(const char *filename)
The name of the file in which to save the message data.
LogLevel
The set of priorities for message logging.
virtual ~OutputHandlerFile(void)
CONSOLE_BRIDGE_DEPRECATED void log_deprecated(const char *file, int line, LogLevel level, const char *m,...)
Root level logging function. This should not be invoked directly, but rather used via a logging macro...
static const char * LogLevelString[4]
void log(const char *file, int line, LogLevel level, const char *m,...)
Root level logging function. This should not be invoked directly, but rather used via a logging macro...
void useOutputHandler(OutputHandler *oh)
Specify the instance of the OutputHandler to use. By default, this is OutputHandlerSTD.
virtual void log(const std::string &text, LogLevel level, const char *filename, int line)
log a message to the output handler with the given text and logging level from a specific file and li...