ompl/util/Console.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2008, Willow Garage, Inc.
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of the Willow Garage nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 *********************************************************************/
00034 
00035 /* Author: Ioan Sucan */
00036 
00037 #ifndef OMPL_UTIL_CONSOLE_
00038 #define OMPL_UTIL_CONSOLE_
00039 
00040 #include <string>
00041 
00064 #define OMPL_ERROR(fmt, ...)  ompl::msg::log(__FILE__, __LINE__, ompl::msg::LOG_ERROR, fmt, ##__VA_ARGS__)
00065 
00066 #define OMPL_WARN(fmt, ...)   ompl::msg::log(__FILE__, __LINE__, ompl::msg::LOG_WARN,  fmt, ##__VA_ARGS__)
00067 
00068 #define OMPL_INFORM(fmt, ...) ompl::msg::log(__FILE__, __LINE__, ompl::msg::LOG_INFO,  fmt, ##__VA_ARGS__)
00069 
00070 #define OMPL_DEBUG(fmt, ...)  ompl::msg::log(__FILE__, __LINE__, ompl::msg::LOG_DEBUG, fmt, ##__VA_ARGS__)
00071 
00072 namespace ompl
00073 {
00074 
00078     namespace msg
00079     {
00081         enum LogLevel
00082         {
00083             LOG_DEBUG = 0,
00084             LOG_INFO,
00085             LOG_WARN,
00086             LOG_ERROR,
00087             LOG_NONE
00088         };
00089 
00097         class OutputHandler
00098         {
00099         public:
00100 
00101             OutputHandler()
00102             {
00103             }
00104 
00105             virtual ~OutputHandler()
00106             {
00107             }
00108 
00111             virtual void log(const std::string &text, LogLevel level, const char *filename, int line) = 0;
00112         };
00113 
00116         class OutputHandlerSTD : public OutputHandler
00117         {
00118         public:
00119 
00120             OutputHandlerSTD() : OutputHandler()
00121             {
00122             }
00123 
00124             virtual void log(const std::string &text, LogLevel level, const char *filename, int line);
00125 
00126         };
00127 
00129         class OutputHandlerFile : public OutputHandler
00130         {
00131         public:
00132 
00134             OutputHandlerFile(const char *filename);
00135 
00136             virtual ~OutputHandlerFile();
00137 
00138             virtual void log(const std::string &text, LogLevel level, const char *filename, int line);
00139 
00140         private:
00141 
00143             FILE *file_;
00144 
00145         };
00146 
00148         void noOutputHandler();
00149 
00151         void restorePreviousOutputHandler();
00152 
00154         void useOutputHandler(OutputHandler *oh);
00155 
00157         OutputHandler* getOutputHandler();
00158 
00161         void setLogLevel(LogLevel level);
00162 
00165         LogLevel getLogLevel();
00166 
00170         void log(const char *file, int line, LogLevel level, const char *m, ...);
00171     }
00172 
00173 }
00174 
00175 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines