38 #include <boost/thread/mutex.hpp>
45 struct DefaultOutputHandler
47 DefaultOutputHandler(
void)
50 previous_output_handler_ = output_handler_;
51 logLevel_ = ompl::msg::LOG_DEBUG;
65 static DefaultOutputHandler* getDOH(
void)
67 static DefaultOutputHandler DOH;
72 DefaultOutputHandler *doh = getDOH(); \
73 boost::mutex::scoped_lock slock(doh->lock_)
75 #define MAX_BUFFER_SIZE 1024
82 doh->previous_output_handler_ = doh->output_handler_;
83 doh->output_handler_ = NULL;
89 std::swap(doh->previous_output_handler_, doh->output_handler_);
95 doh->previous_output_handler_ = doh->output_handler_;
96 doh->output_handler_ = oh;
101 return getDOH()->output_handler_;
107 if (doh->output_handler_ && level >= doh->logLevel_)
111 char buf[MAX_BUFFER_SIZE];
112 vsnprintf(buf,
sizeof(buf), m, __ap);
114 buf[MAX_BUFFER_SIZE - 1] =
'\0';
116 doh->output_handler_->log(buf, level, file, line);
123 doh->logLevel_ = level;
129 return doh->logLevel_;
132 static const char* LogLevelString[4] = {
"Debug: ",
"Info: ",
"Warning: ",
"Error: "};
136 if (level >= LOG_WARN)
138 std::cerr << LogLevelString[level] << text << std::endl;
139 std::cerr <<
" at line " << line <<
" in " << filename << std::endl;
144 std::cout << LogLevelString[level] << text << std::endl;
151 file_ = fopen(filename,
"a");
153 std::cerr <<
"Unable to open log file: '" << filename <<
"'" << std::endl;
156 ompl::msg::OutputHandlerFile::~OutputHandlerFile(
void)
159 if (fclose(file_) != 0)
160 std::cerr <<
"Error closing logfile" << std::endl;
167 fprintf(file_,
"%s%s\n", LogLevelString[level], text.c_str());
168 if(level >= LOG_WARN)
169 fprintf(file_,
" at line %d in %s\n", line, filename);
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...
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...
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...
LogLevel getLogLevel(void)
Retrieve the current level of logging data. Messages with lower logging levels will not be recorded...
void setLogLevel(LogLevel level)
Set the minimum level of logging data to output. Messages with lower logging levels will not be recor...
Generic class to handle output from a piece of code.
Default implementation of OutputHandler. This sends the information to the console.
void useOutputHandler(OutputHandler *oh)
Specify the instance of the OutputHandler to use. By default, this is OutputHandlerSTD.
OutputHandlerFile(const char *filename)
The name of the file in which to save the message data.
OutputHandler * getOutputHandler(void)
Get the instance of the OutputHandler currently used. This is NULL in case there is no output handler...
void noOutputHandler(void)
This function instructs ompl that no messages should be outputted. Equivalent to useOutputHandler(NUL...
void restorePreviousOutputHandler(void)
Restore the output handler that was previously in use (if any)
LogLevel
The set of priorities for message logging.