Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 27, 2007, 4:58:52 PM (16 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.