Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 699 for code/branches/FICN


Ignore:
Timestamp:
Dec 27, 2007, 4:58:52 PM (17 years ago)
Author:
landauf
Message:

introduced 3 different soft debug levels: one for each output device (console, logfile, ingame-shell (to come))
all are configurable in the config file

Location:
code/branches/FICN/src/orxonox/core
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/FICN/src/orxonox/core/Debug.h

    r684 r699  
    6868
    6969#define PRINT_EXEC  printf
    70 //#define COUT_EXEC   std::cout
    71 #define COUT_EXEC   orxonox::OutputHandler::getOutStream()
     70#define COUT_EXEC(x) \
     71  orxonox::OutputHandler::getOutStream().setOutputLevel(x)
    7272
    7373#ifndef PRINTF
     
    207207   #define COUT1  \
    208208    if (getSoftDebugLevel() >= ORX_ERROR)  \
    209      COUT_EXEC
     209     COUT_EXEC(1)
    210210  #else
    211211   #define COUT1 if (ORX_NONE)\
    212     COUT_EXEC
     212    COUT_EXEC(1)
    213213  #endif
    214214
     
    216216   #define COUT2 \
    217217    if (getSoftDebugLevel() >= ORX_WARNING) \
    218      COUT_EXEC
     218     COUT_EXEC(2)
    219219  #else
    220220   #define COUT2 if (ORX_NONE) \
    221     COUT_EXEC
     221    COUT_EXEC(2)
    222222  #endif
    223223
     
    225225   #define COUT3 \
    226226    if (getSoftDebugLevel() >= ORX_INFO) \
    227      COUT_EXEC
     227     COUT_EXEC(3)
    228228  #else
    229229   #define COUT3 if (ORX_NONE) \
    230     COUT_EXEC
     230    COUT_EXEC(3)
    231231  #endif
    232232
     
    234234   #define COUT4 \
    235235    if (getSoftDebugLevel() >= ORX_DEBUG) \
    236      COUT_EXEC
     236     COUT_EXEC(4)
    237237  #else
    238238   #define COUT4 if (ORX_NONE) \
    239     COUT_EXEC
     239    COUT_EXEC(4)
    240240  #endif
    241241
     
    243243   #define COUT5 \
    244244    if (getSoftDebugLevel() >= ORX_vDEBUG) \
    245      COUT_EXEC
     245     COUT_EXEC(5)
    246246  #else
    247247   #define COUT5 if (ORX_NONE) \
    248     COUT_EXEC
     248    COUT_EXEC(5)
    249249  #endif
    250250
    251251 #else /* if ORX_PRINT_DEBUG_OUTPUT */
    252252  #define COUT(x) if (ORX_NONE) \
    253    COUT_EXEC
     253   COUT_EXEC(5)
    254254 #endif /* if ORX_PRINT_DEBUG_OUTPUT */
    255255
    256256 #define COUT0 \
    257   COUT_EXEC
     257  COUT_EXEC(0)
    258258#endif /* ifndef COUT */
    259259
  • code/branches/FICN/src/orxonox/core/DebugLevel.cc

    r696 r699  
    3232
    3333#include "CoreIncludes.h"
    34 #include "Debug.h"
    3534#include "DebugLevel.h"
    3635
     
    5352    void DebugLevel::setConfigValues()
    5453    {
    55         SetConfigValue(softDebugLevel_, 2);
     54        SetConfigValue(softDebugLevelConsole_, 3);
     55        SetConfigValue(softDebugLevelLogfile_, 3);
     56        SetConfigValue(softDebugLevelShell_, 1);
     57
     58        // softDebugLevel_ is the maximum of the 3 variables
     59        this->softDebugLevel_ = this->softDebugLevelConsole_;
     60        if (this->softDebugLevelLogfile_ > this->softDebugLevel_)
     61            this->softDebugLevel_ = this->softDebugLevelLogfile_;
     62        if (this->softDebugLevelShell_ > this->softDebugLevel_)
     63            this->softDebugLevel_ = this->softDebugLevelShell_;
    5664    }
    5765
     
    5967        @brief Static function that holds the singleton.
    6068    */
    61     int DebugLevel::getSoftDebugLevel()
     69    int DebugLevel::getSoftDebugLevel(OutputHandler::OutputDevice device)
    6270    {
    6371        static bool bCreatingSoftDebugLevelObject = true;   // Static variable - used to enhance the performance
     
    6775        // If bReturnSoftDebugLevel is true, the instance of DebugLevel was created (it's set to true at the end of the constructor, call by reference)
    6876        if (bReturnSoftDebugLevel)
    69             return theOnlyDebugLevelObject->softDebugLevel_;
     77        {
     78            if (device == OutputHandler::LD_All)
     79                return theOnlyDebugLevelObject->softDebugLevel_;
     80            else if (device == OutputHandler::LD_Console)
     81                return theOnlyDebugLevelObject->softDebugLevelConsole_;
     82            else if (device == OutputHandler::LD_Logfile)
     83                return theOnlyDebugLevelObject->softDebugLevelLogfile_;
     84            else if (device == OutputHandler::LD_Shell)
     85                return theOnlyDebugLevelObject->softDebugLevelShell_;
     86        }
    7087
    7188        // If bCreatingSoftDebugLevelObject is true, we're just about to create an instance of the DebugLevel class
     
    7491            bCreatingSoftDebugLevelObject = false;
    7592            theOnlyDebugLevelObject = new DebugLevel(bReturnSoftDebugLevel);
    76             return theOnlyDebugLevelObject->softDebugLevel_;
     93            return getSoftDebugLevel(device);
    7794        }
    7895
  • code/branches/FICN/src/orxonox/core/DebugLevel.h

    r695 r699  
    3131
    3232    The DebugLevel class is a singleton, only used to configure the amount of debug
    33     output (see Debug.h) into the console and the log-file (see OutputHandler.h).
     33    output (see Debug.h) into the console and the logfile (see OutputHandler.h).
    3434*/
    3535
     
    3939#include "CorePrereqs.h"
    4040#include "OrxonoxClass.h"
     41#include "OutputHandler.h"
    4142
    4243namespace orxonox
     
    4647    {
    4748        public:
    48             static int getSoftDebugLevel();
     49            static int getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All);
    4950            void setConfigValues();
    5051
     
    5556
    5657            int softDebugLevel_;                            //!< The debug level
     58            int softDebugLevelConsole_;                     //!< The debug level for the console
     59            int softDebugLevelLogfile_;                     //!< The debug level for the logfile
     60            int softDebugLevelShell_;                       //!< The debug level for the ingame shell
    5761            ConfigValueContainer* softDebugLevelContainer_; //!< The config value container for the debug level
    5862    };
  • code/branches/FICN/src/orxonox/core/OutputHandler.cc

    r685 r699  
    2727
    2828#include "OutputHandler.h"
     29#include "DebugLevel.h"
    2930
    3031namespace orxonox
     
    6162
    6263    /**
     64        @brief Returns the soft debug level for a given output device.
     65        @param device The output device
     66        @return The debug level
     67    */
     68    int OutputHandler::getSoftDebugLevel(OutputHandler::OutputDevice device)
     69    {
     70        return DebugLevel::getSoftDebugLevel(device);
     71    }
     72
     73    /**
    6374        @brief Overloaded << operator, redirects the output to the console and the logfile.
    6475        @param sb The streambuffer that should be shown in the console
     
    6778    OutputHandler& OutputHandler::operator<<(std::streambuf* sb)
    6879    {
    69         std::cout << sb;
    70         this->logfile_ << sb;
    71         this->logfile_.flush();
     80        if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
     81            std::cout << sb;
     82
     83        if (getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_)
     84        {
     85            this->logfile_ << sb;
     86            this->logfile_.flush();
     87        }
     88
    7289        return *this;
    7390    }
     
    8097    OutputHandler& OutputHandler::operator<<(std::ostream& (*manipulator)(std::ostream&))
    8198    {
    82         manipulator(std::cout);
    83         manipulator(this->logfile_);
    84         this->logfile_.flush();
     99        if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
     100            manipulator(std::cout);
     101
     102        if (getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_)
     103        {
     104            manipulator(this->logfile_);
     105            this->logfile_.flush();
     106        }
     107
    85108        return *this;
    86109    }
     
    93116    OutputHandler& OutputHandler::operator<<(std::ios& (*manipulator)(std::ios&))
    94117    {
    95         manipulator(std::cout);
    96         manipulator(this->logfile_);
    97         this->logfile_.flush();
     118        if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
     119            manipulator(std::cout);
     120
     121        if (getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_)
     122        {
     123            manipulator(this->logfile_);
     124            this->logfile_.flush();
     125        }
     126
    98127        return *this;
    99128    }
     
    106135    OutputHandler& OutputHandler::operator<<(std::ios_base& (*manipulator)(std::ios_base&))
    107136    {
    108         manipulator(std::cout);
    109         manipulator(this->logfile_);
    110         this->logfile_.flush();
     137        if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
     138            manipulator(std::cout);
     139
     140        if (getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_)
     141        {
     142            manipulator(this->logfile_);
     143            this->logfile_.flush();
     144        }
     145
    111146        return *this;
    112147    }
    113 
    114     /**
    115         @brief Overloaded non-member << operator, redirects the output to the console and the logfile.
    116         @param output The value that should be shown in the console
    117         @return A reference to the OutputHandler itself
    118     *//*
    119     OutputHandler& operator<<(OutputHandler& out, char c)
    120     {
    121         std::cout << c;
    122         out.getLogfile() << c;
    123         out.getLogfile().flush();
    124         return out;
    125     }*/
    126 
    127     /**
    128         @brief Overloaded non-member << operator, redirects the output to the console and the logfile.
    129         @param output The value that should be shown in the console
    130         @return A reference to the OutputHandler itself
    131     *//*
    132     OutputHandler& operator<<(OutputHandler& out, signed char c)
    133     {
    134         std::cout << c;
    135         out.getLogfile() << c;
    136         out.getLogfile().flush();
    137         return out;
    138     }*/
    139 
    140     /**
    141         @brief Overloaded non-member << operator, redirects the output to the console and the logfile.
    142         @param output The value that should be shown in the console
    143         @return A reference to the OutputHandler itself
    144     *//*
    145     OutputHandler& operator<<(OutputHandler& out, unsigned char c)
    146     {
    147         std::cout << c;
    148         out.getLogfile() << c;
    149         out.getLogfile().flush();
    150         return out;
    151     }*/
    152 
    153     /**
    154         @brief Overloaded non-member << operator, redirects the output to the console and the logfile.
    155         @param output The value that should be shown in the console
    156         @return A reference to the OutputHandler itself
    157     *//*
    158     OutputHandler& operator<<(OutputHandler& out, const char* s)
    159     {
    160         std::cout << s;
    161         out.getLogfile() << s;
    162         out.getLogfile().flush();
    163         return out;
    164     }*/
    165 
    166     /**
    167         @brief Overloaded non-member << operator, redirects the output to the console and the logfile.
    168         @param output The value that should be shown in the console
    169         @return A reference to the OutputHandler itself
    170     *//*
    171     OutputHandler& operator<<(OutputHandler& out, const signed char* s)
    172     {
    173         std::cout << s;
    174         out.getLogfile() << s;
    175         out.getLogfile().flush();
    176         return out;
    177     }*/
    178 
    179     /**
    180         @brief Overloaded non-member << operator, redirects the output to the console and the logfile.
    181         @param output The value that should be shown in the console
    182         @return A reference to the OutputHandler itself
    183     *//*
    184     OutputHandler& operator<<(OutputHandler& out, const unsigned char* s)
    185     {
    186         std::cout << s;
    187         out.getLogfile() << s;
    188         out.getLogfile().flush();
    189         return out;
    190     }*/
    191  }
     148}
  • code/branches/FICN/src/orxonox/core/OutputHandler.h

    r685 r699  
    4949    {
    5050        public:
     51            enum OutputDevice
     52            {
     53                LD_All,
     54                LD_Console,
     55                LD_Logfile,
     56                LD_Shell
     57            };
     58
    5159            static OutputHandler& getOutStream();
    5260
    5361            /** @returns a reference to the logfile. */
    54             inline std::ofstream& getLogfile() { return this->logfile_; }
     62            inline std::ofstream& getLogfile()
     63                { return this->logfile_; }
     64
     65            /** @brief Sets the level of the incoming output. @param level The level of the incoming output @return The OutputHandler itself */
     66            inline OutputHandler& setOutputLevel(int level)
     67                { this->outputLevel_ = level; return *this; }
     68
     69            /** @returns the level of the incoming output. */
     70            inline int getOutputLevel() const
     71                { return this->outputLevel_; }
     72
     73            static int getSoftDebugLevel(OutputHandler::OutputDevice device);
    5574
    5675            template <class T>
     
    94113            std::ofstream logfile_;     //!< The logfile where the output is logged
    95114            std::string logfilename_;   //!< The name of the logfile
     115            int outputLevel_;           //!< The level of the incoming output
    96116    };
    97117
     
    104124    OutputHandler& OutputHandler::output(const T& output)
    105125    {
    106         std::cout << output;
    107         this->logfile_ << output;
    108         this->logfile_.flush();
     126        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
     127            std::cout << output;
     128
     129        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_)
     130        {
     131            this->logfile_ << output;
     132            this->logfile_.flush();
     133        }
     134
    109135        return *this;
    110136    }
    111 /*
    112     _CoreExport OutputHandler& operator<<(OutputHandler& out, char c);
    113     _CoreExport OutputHandler& operator<<(OutputHandler& out, signed char c);
    114     _CoreExport OutputHandler& operator<<(OutputHandler& out, unsigned char c);
    115137
    116     _CoreExport OutputHandler& operator<<(OutputHandler& out, const char* s);
    117     _CoreExport OutputHandler& operator<<(OutputHandler& out, const signed char* s);
    118     _CoreExport OutputHandler& operator<<(OutputHandler& out, const unsigned char* s);
    119 */
    120138    /**
    121139        @brief Overloading of the non-member << operator to redirect the output of classes with self defined '<< to std::ostream' operators to the console and the logfile.
     
    127145    OutputHandler& operator<<(OutputHandler& out, const T& output)
    128146    {
    129         std::cout << output;
    130         out.getLogfile() << output;
    131         out.getLogfile().flush();
     147        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Console) >= out.getOutputLevel())
     148            std::cout << output;
     149
     150        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Logfile) >= out.getOutputLevel())
     151        {
     152            out.getLogfile() << output;
     153            out.getLogfile().flush();
     154        }
     155
    132156        return out;
    133157    }
Note: See TracChangeset for help on using the changeset viewer.