Log.h

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @class  Log
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @author Matthew Jacobs (jacobs.mh@gmail.com)
00005    @date   Fall 2008
00006 
00007    @brief
00008       Unified logging functionality for Milton debugging output
00009    <!-------------------------------------------------------------------->**/
00010 
00011 #ifndef LOG_H_
00012 #define LOG_H_
00013 
00014 #include <common/common.h>
00015 
00016 #define DEBUG_STREAM_WARNING     (std::cerr)
00017 #define DEBUG_STREAM_ERROR       (std::cerr)
00018 #define DEBUG_STREAM_INFO        (std::cerr)
00019 
00020 #ifdef DEBUG
00021 #  define DEFAULT_STREAM_WARNING DEBUG_STREAM_WARNING
00022 #  define DEFAULT_STREAM_ERROR   DEBUG_STREAM_ERROR
00023 #  define DEFAULT_STREAM_INFO    DEBUG_STREAM_INFO
00024 #  define DEFAULT_DEBUG          (true)
00025 #else
00026 #  define DEFAULT_STREAM_WARNING (Log::s_null)
00027 #  define DEFAULT_STREAM_ERROR   (std::cerr)
00028 #  define DEFAULT_STREAM_INFO    (Log::s_null)
00029 #  define DEFAULT_DEBUG          (false)
00030 #endif
00031 
00032 /**
00033  * @brief
00034  *    Unified Logging interface
00035  */
00036 struct Log {
00037    // (default log is standard output when debug logging is enabled)
00038    inline Log(bool debug = false)
00039       : warning(debug ? DEBUG_STREAM_WARNING : DEFAULT_STREAM_WARNING), 
00040         error(debug   ? DEBUG_STREAM_ERROR   : DEFAULT_STREAM_ERROR), 
00041         info(debug    ? DEBUG_STREAM_INFO    : DEFAULT_STREAM_INFO), 
00042         _depth(0), _debug(debug ? true : DEFAULT_DEBUG)
00043    { }
00044    
00045    inline Log &operator=(Log &data) {
00046       _debug   = data._debug;
00047       
00048       return *this;
00049    }
00050    
00051    virtual void init();
00052    
00053    virtual void setDebug(bool debug);
00054    
00055    std::ostream &warning;
00056    std::ostream &error;
00057    std::ostream &info;
00058    
00059    protected:
00060       inline int _getDepth() const;
00061    
00062    protected:
00063       // stores depth in stack frames from last time 'init' was called
00064       int           _depth;
00065       
00066       // whether or not logging is enabled
00067       bool          _debug;
00068       
00069       // prints out to info stream
00070       friend inline std::ostream &operator<<(Log &data, const std::string &s);
00071       friend inline std::ostream &operator<<(Log &data, const char *s);
00072       
00073       static std::ostream s_null;
00074 };
00075 
00076 // include inline logging functions
00077 #include <utils/Log.inl>
00078 
00079 #endif // LOG_H_
00080 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6