Console.h
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2008, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 /* Author: Ioan Sucan */
36 
37 #ifndef OMPL_UTIL_CONSOLE_
38 #define OMPL_UTIL_CONSOLE_
39 
40 #include <string>
41 
64 #define OMPL_ERROR(fmt, ...) ompl::msg::log(__FILE__, __LINE__, ompl::msg::LOG_ERROR, fmt, ##__VA_ARGS__)
65 
66 #define OMPL_WARN(fmt, ...) ompl::msg::log(__FILE__, __LINE__, ompl::msg::LOG_WARN, fmt, ##__VA_ARGS__)
67 
68 #define OMPL_INFORM(fmt, ...) ompl::msg::log(__FILE__, __LINE__, ompl::msg::LOG_INFO, fmt, ##__VA_ARGS__)
69 
70 #define OMPL_DEBUG(fmt, ...) ompl::msg::log(__FILE__, __LINE__, ompl::msg::LOG_DEBUG, fmt, ##__VA_ARGS__)
71 
72 #define OMPL_DEVMSG1(fmt, ...) ompl::msg::log(__FILE__, __LINE__, ompl::msg::LOG_DEV1, fmt, ##__VA_ARGS__)
73 
74 #define OMPL_DEVMSG2(fmt, ...) ompl::msg::log(__FILE__, __LINE__, ompl::msg::LOG_DEV2, fmt, ##__VA_ARGS__)
75 
76 namespace ompl
77 {
81  namespace msg
82  {
84  enum LogLevel
85  {
86  LOG_DEV2 = -2, // message type for developers
87  LOG_DEV1 = -1, // message type for developers
88  LOG_DEBUG = 0,
89  LOG_INFO,
90  LOG_WARN,
91  LOG_ERROR,
92  LOG_NONE
93  };
94 
103  {
104  public:
105  OutputHandler() = default;
106 
107  virtual ~OutputHandler() = default;
108 
111  virtual void log(const std::string &text, LogLevel level, const char *filename, int line) = 0;
112  };
113 
117  {
118  public:
119  OutputHandlerSTD() = default;
120 
121  void log(const std::string &text, LogLevel level, const char *filename, int line) override;
122  };
123 
126  {
127  public:
129  OutputHandlerFile(const char *filename);
130 
131  ~OutputHandlerFile() override;
132 
133  void log(const std::string &text, LogLevel level, const char *filename, int line) override;
134 
135  private:
137  FILE *file_;
138  };
139 
142  void noOutputHandler();
143 
146 
149 
153 
156  void setLogLevel(LogLevel level);
157 
161 
165  void log(const char *file, int line, LogLevel level, const char *m, ...);
166  }
167 }
168 
169 #endif
void noOutputHandler()
This function instructs ompl that no messages should be outputted. Equivalent to useOutputHandler(nul...
Definition: Console.cpp:95
Main namespace. Contains everything in this library.
Definition: AppBase.h:21
LogLevel getLogLevel()
Retrieve the current level of logging data. Messages with lower logging levels will not be recorded...
Definition: Console.cpp:142
void setLogLevel(LogLevel level)
Set the minimum level of logging data to output. Messages with lower logging levels will not be recor...
Definition: Console.cpp:136
Generic class to handle output from a piece of code.
Definition: Console.h:102
virtual void log(const std::string &text, LogLevel level, const char *filename, int line)=0
log a message to the output handler with the given text and logging level from a specific file and li...
void restorePreviousOutputHandler()
Restore the output handler that was previously in use (if any)
Definition: Console.cpp:102
OutputHandler * getOutputHandler()
Get the instance of the OutputHandler currently used. This is nullptr in case there is no output hand...
Definition: Console.cpp:115
Implementation of OutputHandler that saves messages in a file.
Definition: Console.h:125
Default implementation of OutputHandler. This sends the information to the console.
Definition: Console.h:116
void useOutputHandler(OutputHandler *oh)
Specify the instance of the OutputHandler to use. By default, this is OutputHandlerSTD.
Definition: Console.cpp:108
LogLevel
The set of priorities for message logging.
Definition: Console.h:84