Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 23, 2011, 12:45:53 AM (13 years ago)
Author:
landauf
Message:

merged output branch back to trunk.

Changes:

  • you have to include util/Output.h instead of util/Debug.h
  • COUT(x) is now called orxout(level)
  • output levels are now defined by an enum instead of numbers. see util/Output.h for the definition
  • it's possible to use output contexts with orxout(level, context). see util/Output.h for some common contexts. you can define more contexts
  • you must use 'endl' at the end of an output message, '\n' does not flush the message

Output levels:

  • instead of COUT(0) use orxout()
  • instead of COUT(1) use orxout(user_error) or orxout(internal_error)
  • instead of COUT(2) use orxout(user_warning) or orxout(internal_warning)
  • instead of COUT(3) use orxout(user_status/user_info) or orxout(internal_status/internal_info)
  • instead of COUT(4) use orxout(verbose)
  • instead of COUT(5) use orxout(verbose_more)
  • instead of COUT(6) use orxout(verbose_ultra)

Guidelines:

  • user_* levels are for the user, visible in the console and the log-file
  • internal_* levels are for developers, visible in the log-file
  • verbose_* levels are for debugging, only visible if the context of the output is activated

Usage in C++:

  • orxout() << "message" << endl;
  • orxout(level) << "message" << endl;
  • orxout(level, context) << "message" << endl;

Usage in Lua:

  • orxout("message")
  • orxout(orxonox.level.levelname, "message")
  • orxout(orxonox.level.levelname, "context", "message")

Usage in Tcl (and in the in-game-console):

  • orxout levelname message
  • orxout_context levelname context message
  • shortcuts: log message, error message, warning message, status message, info message, debug message
Location:
code/trunk
Files:
3 deleted
19 edited
20 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/util/CMakeLists.txt

    r8729 r8858  
    2626  CRC32.cc
    2727  ExprParser.cc
    28   OutputHandler.cc
    2928  Scope.cc
    3029  ScopedSingletonManager.cc
     
    4241)
    4342
     43ADD_SUBDIRECTORY(output)
     44
    4445ORXONOX_ADD_LIBRARY(util
    4546  FIND_HEADER_FILES
  • code/trunk/src/libraries/util/Clipboard.cc

    r7401 r8858  
    4848#undef min
    4949#undef max
    50 #include "Debug.h"
     50#include "Output.h"
    5151
    5252namespace orxonox
     
    7676        catch (...)
    7777        {
    78             COUT(1) << "Error: Unable to copy the following text to the clipboard:" << std::endl;
    79             COUT(1) << "       \"" << text << '"' << std::endl;
     78            orxout(user_error) << "Unable to copy the following text to the clipboard:" << endl;
     79            orxout(user_error) << '"' << text << '"' << endl;
    8080        }
    8181        return false;
     
    104104        catch (...)
    105105        {
    106             COUT(1) << "Error: Unable to retrieve text from the clipboard." << std::endl;
     106            orxout(user_error) << "Unable to retrieve text from the clipboard." << endl;
    107107        }
    108108        return "";
  • code/trunk/src/libraries/util/Convert.h

    r8729 r8858  
    130130#include <loki/TypeManip.h>
    131131
    132 #include "Debug.h"
     132#include "Output.h"
    133133#include "ImplicitConversion.h"
    134134
     
    151151        ORX_FORCEINLINE static bool convert(ToType* /*output*/, const FromType& /*input*/)
    152152        {
    153             COUT(2) << "Could not convert value of type " << typeid(FromType).name()
    154                     << " to type " << typeid(ToType).name() << std::endl;
     153            orxout(internal_warning) << "Could not convert value of type " << typeid(FromType).name()
     154                                     << " to type " << typeid(ToType).name() << endl;
    155155            return false;
    156156        }
  • code/trunk/src/libraries/util/Exception.cc

    r8410 r8858  
    3737#include <cstddef>
    3838#include <CEGUIExceptions.h>
    39 #include "Debug.h"
     39#include "Output.h"
    4040
    4141namespace orxonox
     
    111111        catch (...)
    112112        {
    113             COUT(0) << "BIG WARNING: Unknown exception type encountered."
    114                     << "Rethrowing" << endl;
     113            orxout(user_error) << "BIG WARNING: Unknown exception type encountered."
     114                               << " Rethrowing" << endl;
    115115            throw;
    116116        }
  • code/trunk/src/libraries/util/Exception.h

    r8706 r8858  
    6363#include <sstream>
    6464#include <string>
    65 #include "Debug.h"
     65#include "Output.h"
    6666
    6767namespace orxonox
     
    176176    inline const T& exceptionThrowerHelper(const T& exception)
    177177    {
    178         // let the catcher decide whether to display the message below level 4
    179         COUT(4) << exception.getFullDescription() << std::endl;
     178        // let the catcher decide whether to display the message also to the user
     179        orxout(internal_error) << exception.getFullDescription() << endl;
    180180        return exception;
    181181    }
  • code/trunk/src/libraries/util/ExprParser.h

    r8351 r8858  
    5555            if (!expr.getRemains().empty())
    5656            {
    57                 COUT(2) << "Warning: Expression could not be parsed to the end! Remains: '" << expr.getRemains() << '\'' << std::endl;
     57                orxout(user_warning) << "Expression could not be parsed to the end! Remains: '" << expr.getRemains() << '\'' << endl;
    5858            }
    5959            float result = expr.getResult();
    6060        }
    6161        else
    62             COUT(1) << "Error: Cannot calculate expression: Parse error." << std::endl;
     62            orxout(user_error) << "Cannot calculate expression: Parse error." << endl;
    6363        @endcode
    6464        getRemains() returns the expression after what could be parsed. For instance
  • code/trunk/src/libraries/util/MultiType.h

    r7401 r8858  
    7878    void myfunction(int value)
    7979    {
    80         COUT(0) << "doubled value is " << (2 * value) << std::endl;
     80        orxout() << "doubled value is " << (2 * value) << endl;
    8181    }
    8282
  • code/trunk/src/libraries/util/OrxAssert.h

    r8372 r8858  
    4040
    4141#include <cassert>
    42 #include "Debug.h"
     42#include "Output.h"
    4343
    4444#ifndef NDEBUG
     
    4646/** Run time assertion like assert(), but with an embedded message.
    4747@details
    48     The message will be printed as error with COUT(1). <br>
     48    The message will be printed as error with orxout(user_error). <br>
    4949    You can use the same magic here as you can with \ref ThrowException
    5050    @code
     
    5757        if (!(condition)) \
    5858        { \
    59             COUT(1) << __FILE__ << "(" << __LINE__ << "): "; \
    60             COUT(1) << "Assertion failed in " << __FUNCTIONNAME__ << std::endl; \
    61             COUT(1) << "Expression: " << #condition << std::endl; \
    62             COUT(1) << "Message   : " << errorMessage << std::endl; \
     59            orxout(user_error) << __FILE__ << "(" << __LINE__ << "): "; \
     60            orxout(user_error) << "Assertion failed in " << __FUNCTIONNAME__ << endl; \
     61            orxout(user_error) << "Expression: " << #condition << endl; \
     62            orxout(user_error) << "Message   : " << errorMessage << endl; \
    6363            /* Don't use the condition again to avoid double evaluation */ \
    6464            /* Instead, stringify the expression and negate it */ \
     
    7070    mode (no abort() triggered then).
    7171@details
    72     The message will be printed as error with COUT(1). <br>
     72    The message will be printed as error with orxout(user_error). <br>
    7373    You can use the same magic here as you can with \ref ThrowException
    7474    @code
     
    8181        if (!(condition)) \
    8282        { \
    83             COUT(1) << __FILE__ << "(" << __LINE__ << "): "; \
    84             COUT(1) << "Verification failed in " << __FUNCTIONNAME__ << std::endl; \
    85             COUT(1) << "Expression: " << #condition << std::endl; \
    86             COUT(1) << "Message   : " << errorMessage << std::endl; \
     83            orxout(user_error) << __FILE__ << "(" << __LINE__ << "): "; \
     84            orxout(user_error) << "Verification failed in " << __FUNCTIONNAME__ << endl; \
     85            orxout(user_error) << "Expression: " << #condition << endl; \
     86            orxout(user_error) << "Message   : " << errorMessage << endl; \
    8787            /* Don't use the condition again to avoid double evaluation */ \
    8888            /* Instead, stringify the expression and negate it */ \
     
    100100        if (!(condition)) \
    101101        { \
    102             COUT(1) << __FILE__ << "(" << __LINE__ << "): "; \
    103             COUT(1) << "Verification failed in " << __FUNCTIONNAME__ << std::endl; \
    104             COUT(1) << "Expression: " << #condition << std::endl; \
    105             COUT(1) << "Message   : " << errorMessage << std::endl; \
     102            orxout(user_error) << __FILE__ << "(" << __LINE__ << "): "; \
     103            orxout(user_error) << "Verification failed in " << __FUNCTIONNAME__ << endl; \
     104            orxout(user_error) << "Expression: " << #condition << endl; \
     105            orxout(user_error) << "Message   : " << errorMessage << endl; \
    106106            /* No assert() in release configuration */ \
    107107        } \
  • code/trunk/src/libraries/util/Scope.h

    r7401 r8858  
    6060#include <loki/ScopeGuard.h>
    6161
    62 #include "Debug.h"
     62#include "Output.h"
    6363
    6464namespace orxonox
     
    128128            Scope()
    129129            {
     130                orxout(internal_status) << "creating scope... (" << scope << ")" << endl;
     131
    130132                try
    131133                {
     
    148150                    throw;
    149151                }
     152
     153                orxout(internal_status) << "created scope (" << scope << ")" << endl;
    150154            }
    151155
     
    153157            ~Scope()
    154158            {
     159                orxout(internal_status) << "destroying scope... (" << scope << ")" << endl;
     160
    155161                ScopeManager::instanceCounts_s[scope]--;
    156162
     
    162168                if (ScopeManager::instanceCounts_s[scope] == 0)
    163169                    this->deactivateListeners();
     170
     171                orxout(internal_status) << "destroyed scope (" << scope << ")" << endl;
    164172            }
    165173
     
    174182                            { (*it)->deactivated(); }
    175183                        catch (...)
    176                             { COUT(0) << "ScopeListener::deactivated() failed! This MUST NOT happen, fix it!" << std::endl; }
     184                            { orxout(internal_warning) << "ScopeListener::deactivated() failed! This MUST NOT happen, fix it!" << endl; }
    177185                        (*(it++))->bActivated_ = false;
    178186                    }
  • code/trunk/src/libraries/util/ScopedSingletonManager.h

    r8706 r8858  
    231231                { singletonPtr_ = new T(); }
    232232            catch (const InitialisationAbortedException& ex)
    233                 { COUT(3) << ex.getDescription() << std::endl; }
     233                { orxout(internal_error) << ex.getDescription() << endl; }
    234234            catch (...)
    235                 { COUT(1) << "Singleton creation failed: " << Exception::handleMessage() << std::endl; }
     235                { orxout(internal_error) << "Singleton creation failed: " << Exception::handleMessage() << endl; }
    236236        }
    237237
  • code/trunk/src/libraries/util/SignalHandler.cc

    r8351 r8858  
    3939#include <cstdio>
    4040
    41 #include "Debug.h"
     41#include "Output.h"
    4242
    4343namespace orxonox
     
    127127      if( SignalHandler::singletonPtr_s == 0 )
    128128      {
    129         COUT(0) << "Received signal " << sigName.c_str() << std::endl << "Can't write backtrace because SignalHandler is already destroyed" << std::endl;
     129        orxout(user_error) << "Received signal " << sigName.c_str() << endl << "Can't write backtrace because SignalHandler is already destroyed" << endl;
    130130        exit(EXIT_FAILURE);
    131131      }
     
    137137
    138138
    139       COUT(0) << "Received signal " << sigName.c_str() << std::endl << "Try to write backtrace to file orxonox_crash.log" << std::endl;
     139      orxout(user_error) << "Received signal " << sigName.c_str() << endl << "Try to write backtrace to file orxonox_crash.log" << endl;
    140140
    141141     
     
    206206#ifdef PR_SET_PTRACER
    207207        if( prctl(PR_SET_PTRACER, gdbPid, 0, 0, 0) == -1 )
    208           COUT(0) << "could not set proper permissions for GDB to attach to process..." << endl;
     208          orxout(user_error) << "could not set proper permissions for GDB to attach to process..." << endl;
    209209#endif
    210210       
     
    213213
    214214        if( read( sigPipe[0], &someData, sizeof(someData) ) != sizeof(someData) )
    215           COUT(0) << "something went wrong :(" << std::endl;
     215          orxout(user_error) << "something went wrong :(" << endl;
    216216
    217217        if ( someData != 0x12345678 )
    218218        {
    219           COUT(0) << "something went wrong :(" << std::endl;
     219          orxout(user_error) << "something went wrong :(" << endl;
    220220        }
    221221
     
    328328      if ( fwrite( bt.c_str(), 1, bt.length(), f ) != bt.length() )
    329329      {
    330         COUT(0) << "could not write " << bt.length() << " byte to " << getInstance().filename << std::endl;
     330        orxout(user_error) << "could not write " << bt.length() << " byte to " << getInstance().filename << endl;
    331331        exit(EXIT_FAILURE);
    332332      }
     
    364364_UtilExport void __cdecl abort()
    365365{
    366     COUT(1) << "This application has requested the Runtime to terminate it in an unusual way." << std::endl;
    367     COUT(1) << "Please contact the application's support team for more information." << std::endl;
     366    using namespace orxonox;
     367    orxout(user_error) << "This application has requested the Runtime to terminate it in an unusual way." << endl;
     368    orxout(user_error) << "Please contact the application's support team for more information." << endl;
    368369    DebugBreak();
    369370    exit(0x3);
     
    373374_UtilExport void __cdecl _assert(const char* expression, const char* file, int line)
    374375{
    375     COUT(1) << "Assertion failed: " << expression << ", file " << file << ", line " << line << std::endl;
    376     COUT(1) << std::endl;
     376    using namespace orxonox;
     377    orxout(user_error) << "Assertion failed: " << expression << ", file " << file << ", line " << line << endl;
     378    orxout(user_error) << endl;
    377379    abort();
    378380}
     
    423425            bExecuting = true;
    424426
    425             COUT(1) << std::endl;
     427            orxout(user_error) << endl;
    426428
    427429            // if the signalhandler has already been destroyed then don't do anything
    428430            if (SignalHandler::singletonPtr_s == 0)
    429431            {
    430                 COUT(1) << "Caught an unhandled exception" << std::endl << "Can't write backtrace because SignalHandler is already destroyed" << std::endl;
     432                orxout(user_error) << "Caught an unhandled exception" << endl << "Can't write backtrace because SignalHandler is already destroyed" << endl;
    431433                exit(EXIT_FAILURE);
    432434            }
    433435
    434             COUT(1) << "Caught an unhandled exception" << std::endl << "Try to write backtrace to orxonox_crash.log..." << std::endl;
     436            orxout(user_error) << "Caught an unhandled exception" << endl << "Try to write backtrace to orxonox_crash.log..." << endl;
    435437
    436438            // write the crash log
     
    439441            time_t now = time(NULL);
    440442
    441             crashlog << "=======================================================" << std::endl;
     443            crashlog << "=======================================================" << endl;
    442444            crashlog << "= Time: " << std::string(ctime(&now));
    443             crashlog << "=======================================================" << std::endl;
    444             crashlog << std::endl;
     445            crashlog << "=======================================================" << endl;
     446            crashlog << endl;
    445447
    446448            const std::string& error = SignalHandler::getExceptionType(pExceptionInfo);
    447449
    448             crashlog << error << std::endl;
    449             crashlog << std::endl;
     450            crashlog << error << endl;
     451            crashlog << endl;
    450452
    451453            const std::string& callstack = SignalHandler::getStackTrace(pExceptionInfo);
    452454
    453             crashlog << "Call stack:" << std::endl;
    454             crashlog << callstack << std::endl;
     455            crashlog << "Call stack:" << endl;
     456            crashlog << callstack << endl;
    455457
    456458            crashlog.close();
    457459
    458460            // print the same information also to the console
    459             COUT(1) << std::endl;
    460             COUT(1) << error << std::endl;
    461             COUT(1) << std::endl;
    462             COUT(1) << "Call stack:" << std::endl;
    463             COUT(1) << callstack << std::endl;
     461            orxout(user_error) << endl;
     462            orxout(user_error) << error << endl;
     463            orxout(user_error) << endl;
     464            orxout(user_error) << "Call stack:" << endl;
     465            orxout(user_error) << callstack << endl;
    464466
    465467            bExecuting = false;
     
    467469        else
    468470        {
    469             COUT(1) << "An error occurred while writing the backtrace" << std::endl;
     471            orxout(user_error) << "An error occurred while writing the backtrace" << endl;
    470472        }
    471473
  • code/trunk/src/libraries/util/Singleton.h

    r7904 r8858  
    100100    void TestSingleton::testFunction()                      // implement testFunction
    101101    {
    102         COUT(0) << "My value is " << this->testValue_ << std::endl;
     102        orxout() << "My value is " << this->testValue_ << endl;
    103103    }
    104104
  • code/trunk/src/libraries/util/Sleep.cc

    r5738 r8858  
    3434
    3535#include "Sleep.h"
    36 #include "Debug.h"
     36#include "Output.h"
    3737
    3838#ifdef ORXONOX_PLATFORM_WINDOWS
     
    4949    {
    5050        //if (microseconds < 1000)
    51         //    COUT(2) << "Warning: Windows cannot sleep less than 1ms, ignoring" << std::endl;
     51        //    orxout(internal_warning) << "Windows cannot sleep less than 1ms, ignoring" << endl;
    5252        Sleep(microseconds / 1000);
    5353    }
  • code/trunk/src/libraries/util/StringUtils.cc

    r8232 r8858  
    7979        for (; pos2 > 0         && (str[pos2] == ' ' || str[pos2] == '\t' || str[pos2] == '\n'); pos2--);
    8080        return str.substr(pos1, pos2 - pos1 + 1);
     81    }
     82
     83    /// Splits a given string by a delimiter and stores it in an output vector
     84    void vectorize(const std::string& str, char delimiter, std::vector<std::string>* output)
     85    {
     86        for (size_t start = 0, end = 0; end != std::string::npos; start = end + 1)
     87        {
     88            end = str.find_first_of(delimiter, start);
     89            output->push_back(str.substr(start, end - start));
     90        }
    8191    }
    8292
     
    517527        return matrix[(rows-1)*cols + cols-1];
    518528    }
    519    
     529
    520530    /**
    521531    @brief
  • code/trunk/src/libraries/util/StringUtils.h

    r8232 r8858  
    4343#include "UtilPrereqs.h"
    4444#include <string>
     45#include <vector>
    4546
    4647namespace orxonox
     
    5455
    5556    _UtilExport std::string  removeTrailingWhitespaces(const std::string& str);
     57
     58    _UtilExport void         vectorize(const std::string& str, char delimiter, std::vector<std::string>* output);
    5659
    5760    _UtilExport size_t       getNextQuote(const std::string& str, size_t start);
     
    8891
    8992    _UtilExport unsigned int getLevenshteinDistance(const std::string& str1, const std::string& str2);
    90    
     93
    9194    _UtilExport std::string  getTimestamp(void);
    9295}
  • code/trunk/src/libraries/util/SubString.cc

    r7401 r8858  
    4545#include "SubString.h"
    4646#include <cstdio>
    47 #include "Debug.h"
     47#include "Output.h"
    4848
    4949namespace orxonox
     
    513513    void SubString::debug() const
    514514    {
    515         COUT(0) << "Substring-information::count=" << this->tokens_.size() << " ::";
     515        orxout(debug_output) << "Substring-information::count=" << this->tokens_.size() << " ::";
    516516        for (unsigned int i = 0; i < this->tokens_.size(); ++i)
    517             COUT(0) << "s" << i << "='" << this->tokens_[i].c_str() << "'::";
    518         COUT(0) << std::endl;
     517            orxout(debug_output) << "s" << i << "='" << this->tokens_[i].c_str() << "'::";
     518        orxout(debug_output) << endl;
    519519    }
    520520}
  • code/trunk/src/libraries/util/SubString.h

    r8706 r8858  
    5959
    6060    for (unsigned int i = 0; i < tokens.size(); ++i)
    61         COUT(0) << i << ": " << tokens[i] << std::endl;
     61        orxout() << i << ": " << tokens[i] << endl;
    6262    @endcode
    6363
  • code/trunk/src/libraries/util/UtilPrereqs.h

    r8729 r8858  
    8888    class ExprParser;
    8989    class MultiType;
    90     class OutputHandler;
    9190    class OutputListener;
     91    class OutputManager;
     92    class OutputStream;
    9293    template <ScopeID::Value>
    9394    class Scope;
Note: See TracChangeset for help on using the changeset viewer.