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:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/Core.cc

    r8729 r8858  
    5252
    5353#include "util/Clock.h"
    54 #include "util/Debug.h"
     54#include "util/Output.h"
    5555#include "util/Exception.h"
     56#include "util/output/LogWriter.h"
    5657#include "util/Scope.h"
    5758#include "util/ScopedSingletonManager.h"
     
    111112        , destructionHelper_(this)
    112113    {
     114        orxout(internal_status) << "initializing Core object..." << endl;
     115
    113116        // Set the hard coded fixed paths
    114117        this->pathConfig_ = new PathConfig();
     
    118121
    119122        // Load modules
     123        orxout(internal_info) << "Loading modules:" << endl;
    120124        const std::vector<std::string>& modulePaths = this->pathConfig_->getModulePaths();
    121125        for (std::vector<std::string>::const_iterator it = modulePaths.begin(); it != modulePaths.end(); ++it)
     
    127131            catch (...)
    128132            {
    129                 COUT(1) << "Couldn't load module \"" << *it << "\": " << Exception::handleMessage() << std::endl;
     133                orxout(user_error) << "Couldn't load module \"" << *it << "\": " << Exception::handleMessage() << endl;
    130134            }
    131135        }
     
    136140        // Set configurable paths like log, config and media
    137141        this->pathConfig_->setConfigurablePaths();
     142
     143        orxout(internal_info) << "Root path:       " << PathConfig::getRootPathString() << endl;
     144        orxout(internal_info) << "Executable path: " << PathConfig::getExecutablePathString() << endl;
     145        orxout(internal_info) << "Data path:       " << PathConfig::getDataPathString() << endl;
     146        orxout(internal_info) << "Ext. data path:  " << PathConfig::getExternalDataPathString() << endl;
     147        orxout(internal_info) << "Config path:     " << PathConfig::getConfigPathString() << endl;
     148        orxout(internal_info) << "Log path:        " << PathConfig::getLogPathString() << endl;
     149        orxout(internal_info) << "Modules path:    " << PathConfig::getModulePathString() << endl;
    138150
    139151        // create a signal handler (only active for Linux)
     
    141153        this->signalHandler_ = new SignalHandler();
    142154        this->signalHandler_->doCatch(PathConfig::getExecutablePathString(), PathConfig::getLogPathString() + "orxonox_crash.log");
    143 
    144         // Set the correct log path. Before this call, /tmp (Unix) or %TEMP% (Windows) was used
    145         OutputHandler::getInstance().setLogPath(PathConfig::getLogPathString());
    146155
    147156#ifdef ORXONOX_PLATFORM_WINDOWS
     
    155164
    156165        // Manage ini files and set the default settings file (usually orxonox.ini)
     166        orxout(internal_info) << "Loading config:" << endl;
    157167        this->configFileManager_ = new ConfigFileManager();
    158168        this->configFileManager_->setFilename(ConfigFileType::Settings,
     
    160170
    161171        // Required as well for the config values
     172        orxout(internal_info) << "Loading language:" << endl;
    162173        this->languageInstance_ = new Language();
    163174
     
    165176        // possibility to configure everything below here
    166177        RegisterRootObject(Core);
     178        orxout(internal_info) << "configuring Core" << endl;
    167179        this->setConfigValues();
    168         // Rewrite the log file with the correct log levels
    169         OutputHandler::getInstance().rewriteLogFile();
     180
     181        // Set the correct log path and rewrite the log file with the correct log levels
     182        LogWriter::getInstance().setLogPath(PathConfig::getLogPathString());
    170183
    171184#if !defined(ORXONOX_PLATFORM_APPLE) && !defined(ORXONOX_USE_WINMAIN)
     
    176189        }
    177190        if (this->bStartIOConsole_)
     191        {
     192            orxout(internal_info) << "creating IO console" << endl;
    178193            this->ioConsole_ = new IOConsole();
     194        }
    179195#endif
    180196
    181197        // creates the class hierarchy for all classes with factories
     198        orxout(internal_info) << "creating class hierarchy" << endl;
    182199        Identifier::createClassHierarchy();
    183200
    184201        // Load OGRE excluding the renderer and the render window
     202        orxout(internal_info) << "creating GraphicsManager:" << endl;
    185203        this->graphicsManager_ = new GraphicsManager(false);
    186204
     
    190208
    191209        // Create singletons that always exist (in other libraries)
     210        orxout(internal_info) << "creating root scope:" << endl;
    192211        this->rootScope_ = new Scope<ScopeID::Root>();
    193212
     
    204223            }
    205224            else
    206                 COUT(0) << "Error: Could not open file for documentation writing" << endl;
    207         }
     225                orxout(internal_error) << "Could not open file for documentation writing" << endl;
     226        }
     227
     228        orxout(internal_status) << "finished initializing Core object" << endl;
    208229    }
    209230
    210231    void Core::destroy()
    211232    {
     233        orxout(internal_status) << "destroying Core object..." << endl;
     234
    212235        // Remove us from the object lists again to avoid problems when destroying them
    213236        this->unregisterObject();
     
    228251        safeObjectDelete(&dynLibManager_);
    229252        safeObjectDelete(&pathConfig_);
    230     }
    231 
    232     namespace DefaultLevelLogFile
    233     {
    234         const OutputLevel::Value Dev  = OutputLevel::Debug;
    235         const OutputLevel::Value User = OutputLevel::Info;
     253
     254        orxout(internal_status) << "finished destroying Core object" << endl;
    236255    }
    237256
     
    239258    void Core::setConfigValues()
    240259    {
    241         // Choose the default level according to the path Orxonox was started (build directory or not)
    242         OutputLevel::Value defaultLogLevel = (PathConfig::buildDirectoryRun() ? DefaultLevelLogFile::Dev : DefaultLevelLogFile::User);
    243 
    244         SetConfigValueExternal(debugLevelLogFile_, "OutputHandler", "debugLevelLogFile", defaultLogLevel)
    245             .description("The maximum level of debug output written to the log file");
    246         OutputHandler::getInstance().setSoftDebugLevel("LogFile", debugLevelLogFile_);
     260        SetConfigValueExternal(LogWriter::getInstance().configurableMaxLevel_,
     261                               LogWriter::getInstance().getConfigurableSectionName(),
     262                               LogWriter::getInstance().getConfigurableMaxLevelName(),
     263                               LogWriter::getInstance().configurableMaxLevel_)
     264            .description("The maximum level of output shown in the log file")
     265            .callback(static_cast<BaseWriter*>(&LogWriter::getInstance()), &BaseWriter::changedConfigurableLevel);
     266        SetConfigValueExternal(LogWriter::getInstance().configurableAdditionalContextsMaxLevel_,
     267                               LogWriter::getInstance().getConfigurableSectionName(),
     268                               LogWriter::getInstance().getConfigurableAdditionalContextsMaxLevelName(),
     269                               LogWriter::getInstance().configurableAdditionalContextsMaxLevel_)
     270            .description("The maximum level of output shown in the log file for additional contexts")
     271            .callback(static_cast<BaseWriter*>(&LogWriter::getInstance()), &BaseWriter::changedConfigurableAdditionalContextsLevel);
     272        SetConfigValueExternal(LogWriter::getInstance().configurableAdditionalContexts_,
     273                               LogWriter::getInstance().getConfigurableSectionName(),
     274                               LogWriter::getInstance().getConfigurableAdditionalContextsName(),
     275                               LogWriter::getInstance().configurableAdditionalContexts_)
     276            .description("Additional output contexts shown in the log file")
     277            .callback(static_cast<BaseWriter*>(&LogWriter::getInstance()), &BaseWriter::changedConfigurableAdditionalContexts);
    247278
    248279        SetConfigValue(bDevMode_, PathConfig::buildDirectoryRun())
     
    279310    void Core::devModeChanged()
    280311    {
    281         bool isNormal = (bDevMode_ == PathConfig::buildDirectoryRun());
    282         if (isNormal)
    283         {
    284             ModifyConfigValueExternal(debugLevelLogFile_, "debugLevelLogFile", update);
    285         }
    286         else
    287         {
    288             OutputLevel::Value level = (bDevMode_ ? DefaultLevelLogFile::Dev : DefaultLevelLogFile::User);
    289             ModifyConfigValueExternal(debugLevelLogFile_, "debugLevelLogFile", tset, level);
    290         }
    291 
    292312        // Inform listeners
    293313        ObjectList<DevModeListener>::iterator it = ObjectList<DevModeListener>::begin();
     
    316336    void Core::loadGraphics()
    317337    {
     338        orxout(internal_info) << "loading graphics in Core" << endl;
     339       
    318340        // Any exception should trigger this, even in upgradeToGraphics (see its remarks)
    319341        Loki::ScopeGuard unloader = Loki::MakeObjGuard(*this, &Core::unloadGraphics);
     
    327349        {
    328350            // Exit the application if the Ogre config dialog was canceled
    329             COUT(1) << Exception::handleMessage() << std::endl;
     351            orxout(user_error) << Exception::handleMessage() << endl;
    330352            exit(EXIT_FAILURE);
    331353        }
     
    338360            // and reloaded between throw and catch (access violation in MSVC).
    339361            // That's why we abort completely and only display the exception.
    340             COUT(1) << "An exception occurred during upgrade to graphics. "
    341                     << "That is unrecoverable. The message was:" << endl
    342                     << Exception::handleMessage() << endl;
     362            orxout(user_error) << "An exception occurred during upgrade to graphics. "
     363                               << "That is unrecoverable. The message was:" << endl
     364                               << Exception::handleMessage() << endl;
    343365            abort();
    344366        }
     
    357379
    358380        // Create singletons associated with graphics (in other libraries)
     381        orxout(internal_info) << "creating graphics scope:" << endl;
    359382        graphicsScope_ = new Scope<ScopeID::Graphics>();
    360383
    361384        unloader.Dismiss();
     385
     386        orxout(internal_info) << "finished loading graphics in Core" << endl;
    362387    }
    363388
    364389    void Core::unloadGraphics()
    365390    {
     391        orxout(internal_info) << "unloading graphics in Core" << endl;
     392
    366393        safeObjectDelete(&graphicsScope_);
    367394        safeObjectDelete(&guiManager_);
     
    374401        catch (...)
    375402        {
    376             COUT(0) << "An exception occurred during 'unloadGraphics':" << Exception::handleMessage() << std::endl
    377                     << "Another exception might be being handled which may lead to undefined behaviour!" << std::endl
    378                     << "Terminating the program." << std::endl;
     403            orxout(user_error) << "An exception occurred during 'unloadGraphics':" << Exception::handleMessage() << endl
     404                               << "Another exception might be being handled which may lead to undefined behaviour!" << endl
     405                               << "Terminating the program." << endl;
    379406            abort();
    380407        }
Note: See TracChangeset for help on using the changeset viewer.