#ifndef _utl_MessageLoggerConfig_h_ #define _utl_MessageLoggerConfig_h_ // Just need forward-declarations, tough being nested // utl::MessageLogger::Message we have to included the file. #include // #include #include /** * \file * \author Rodolfo Federico Gamarra * \date 19 Sep 2009 */ namespace utl { class Branch; /** * \class MessageLoggerConfig MessageLoggerConfig.h Configuration/MessageLoggerConfig.h * * \brief Wraps a message to logger (received as parameter or created here), its access * and configuration. * * \author Rodolfo Federico Gamarra * \date 21 Sep 2009 * \ingroup * \sa MessageLogger */ class MessageLoggerConfig { public: /** * \brief Create configurator with the logger to configure * and the branch from where to load the configuration. */ MessageLoggerConfig(MessageLogger& l, const Branch& config); /** * \brief Create configurator with the logger to configure. */ MessageLoggerConfig(MessageLogger& l); /** * \brief Create configurator given the branch from where to load * the configuration. */ MessageLoggerConfig(const Branch& config); /** * \brief Create a configurator without any configuration yet. */ MessageLoggerConfig(); /** * \brief Configure. * * Load and apply configuration. */ void Configure(const Branch& config); /** * \brief Apply already loaded configuration. */ void ApplyConfiguration(); /** * \brief Retrieve (read-only) the current level of verbosity. */ const unsigned int& GetLevel() const { // We could, of course, be returnin by copy. return fLevel; } /** * \brief Retrieve by reference the current level of verbosity. */ unsigned int& GetLevel() { return fLevel; } /** * \brief Change the level of verbosity. */ void SetLevel(unsigned int vl) { fLevel = vl; } /** * \brief Create a message for the given level. * * \sa utl::MessageLogger */ template MessageLogger::Message operator()(const T& message, unsigned int level = 0, bool trailEOL = true) { return fTheLogger(message, level, trailEOL); } /** * \brief Apply configuration to the given stream via manipulators. */ template void ApplyConfigurationOn(S& stream) const { // Forward the call: // (maybe, at last, MessageLoggerConfig and MessageLogger should // be the same class; on the other hand this class handles the // eventual file, and loading from branch). fTheLogger.ApplyConfigurationOn(stream); } private: /** * \brief Configure data loading. */ void LoadConfiguration(const Branch& config); /** * \brief Control how much output is generated. * * \sa utl::MessageLogger */ unsigned int fLevel; /** * \brief Precission digits. */ unsigned int fNPrecDigits; /** * \brief The period. */ unsigned int fFlushPeriod; /** * \brief Output message sink. */ std::ofstream fOutput; /** * \brief Output log filename (if empty, then cout). */ std::string fOutputFilename; /** * \brief Pointer to self created logger. */ std::auto_ptr fOwnLogger; /** * \brief The logger to configure. */ MessageLogger& fTheLogger; }; /** * \brief Applies the configuration to the given * stream. * * Allow usage of the config as a manipulator. * This basically because utl::TabularStream applies * a manipulator only to the current column, and so * when the column changes then any setting is lost. * * So, if desired, then before each call to operator<< * a call to this is needed. */ template inline Stream& operator<<(Stream& s, MessageLoggerConfig& mlc) { mlc.ApplyConfigurationOn(s); return s; } } #endif // _utl_MessageLoggerConfig_h_